From ba5e13ba52ece5e754155b211d4647d2dab76e6f Mon Sep 17 00:00:00 2001 From: Rohit Pathak Date: Fri, 13 Nov 2026 23:38:44 -0500 Subject: [PATCH 1/2] fix: make tsc pass and restore the daily update-check limit - Add typescript@5.9.3 and @types/node@24.19.2 as pinned devDependencies (tsc was only present transitively). - version.ts: accept both the sync v1 TuiKV and the async v2 facade KV. With the sync KV, the "checked today" branch was never taken, so every launch hit the GitHub API. Narrow the toast variant to TuiToast's union. - Add test/version.test.ts covering sync/async KV and stale checks. - `just check` now runs `tsc --noEmit` so CI catches type errors. Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 4 ++-- CONTRIBUTING.md | 2 +- justfile | 7 +++++- package.json | 4 +++- src/version.ts | 28 +++++++++++------------ test/version.test.ts | 53 ++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 79 insertions(+), 19 deletions(-) create mode 100644 test/version.test.ts diff --git a/AGENTS.md b/AGENTS.md index 14487e9..7022051 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -175,7 +175,7 @@ Text objects (`iw`/`aw`, the quote/bracket pairs, and the `iq`/`ib` aliases) rou just dev # Launch v1 with the plugin (uses OPENCODE_TUI_CONFIG=dev-tui.json) just dev2 # Launch pinned v2/local source with isolated .dev2/ state bun test # Run characterization tests -just check # Lint + existing fast tests (used in GitHub Actions) +just check # Lint + typecheck + existing fast tests (used in GitHub Actions) just test-int # On-demand SDK/process integration and parser helpers just test-e2e # Both pinned PTY hosts (v1 1.18.34, v2 2.0.15); optional v1/v2 selector just compat-unit # Pure checks for the optional host harness @@ -220,7 +220,7 @@ Branch naming: `type/description` — e.g. `feat/replace-char`, `fix/escape-hand **Shifted key translation** happens in `translateKey()` before the handler sees the key. Handlers work with normalized keys (`$` not `shift+4`, `G` not `shift+g`). Add new shift mappings in `translateKey`, not in handlers. -**TypeScript strictness.** `strict: true` in tsconfig. No `any` in `src/vim/` or `test/`. The `api` parameter in `index.ts` is typed as `any` because the plugin types come from peer deps that may not be installed locally — that's the one acceptable use. +**TypeScript strictness.** `strict: true` in tsconfig. No `any` in `src/vim/` or `test/`. `api` in `index.ts` is typed as `TuiPluginApi` from `@opencode-ai/plugin`; `just check` runs `tsc --noEmit`, so type errors fail CI. **Cross-platform.** All code must work on macOS, Linux, and Windows. No platform-specific assumptions without a runtime `process.platform` check and fallbacks for other platforms. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index de7bdfa..e48d407 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -6,7 +6,7 @@ just install # install deps just dev # launch OpenCode v1 with the plugin loaded just dev2 # launch pinned v2 with local source and separate .dev2/ state -just check # run lint + existing fast tests +just check # run lint + typecheck + existing fast tests just test # existing fast suite just test-int # on-demand harness integration checks (including launcher) just test-e2e # both pinned hosts; inferred private binaries/temp outputs diff --git a/justfile b/justfile index 2627e3f..62cb16f 100644 --- a/justfile +++ b/justfile @@ -8,6 +8,10 @@ install: test: bun test +# Type-check src with tsc +typecheck: + bun run typecheck + # Check formatting and lint (warnings are errors) lint: bunx biome ci --error-on-warnings . @@ -16,9 +20,10 @@ lint: lint-fix: bunx biome check --write . -# Run lint + tests +# Run lint + typecheck + tests check: just lint + just typecheck just test # Optional real-host check: use an empty output dir outside any checkout. diff --git a/package.json b/package.json index ec4386e..590854e 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,8 @@ "@kitlangton/terminal-control": "1.2.1", "@opencode-ai/plugin": "^1.15.4", "@opentui/keymap": "0.5.10", - "tsx": "^4.22.1" + "@types/node": "24.19.2", + "tsx": "^4.22.1", + "typescript": "5.9.3" } } diff --git a/src/version.ts b/src/version.ts index a854e84..77b649a 100644 --- a/src/version.ts +++ b/src/version.ts @@ -5,27 +5,27 @@ export const VERSION = "0.21.1"; // is CDN-cached for up to 5 minutes which delays update detection. const LATEST_VERSION_URL = "https://api.github.com/repos/rohit-pathak/vimcode/contents/package.json?ref=main"; -type Toast = (opts: { message: string; variant: string; duration: number }) => void; -type KV = { get(key: string): Promise; set(key: string, value: string): Promise }; +type Toast = (opts: { message: string; variant: "info" | "success" | "warning" | "error"; duration: number }) => void; +// The v1 TuiKV is synchronous; the v2 facade (src/v2.ts) is async. Accept both: +// results go through Promise.resolve, which passes plain values and promises alike. +type KV = { get(key: string): unknown; set(key: string, value: string): unknown }; const ONE_DAY_MS = 24 * 60 * 60 * 1000; export function checkForUpdate(toast: Toast, kv?: KV) { + let last: unknown; try { - const last = kv?.get("lastUpdateCheck"); - if (last && typeof last.then === "function") { - last - .then((ts: string | undefined) => { - if (ts && Date.now() - Number(ts) < ONE_DAY_MS) return; - fetchLatest(toast, kv); - }) - .catch(() => {}); - } else { - fetchLatest(toast, kv); - } + last = kv?.get("lastUpdateCheck"); } catch { fetchLatest(toast); + return; } + Promise.resolve(last) + .then((ts) => { + if (ts && Date.now() - Number(ts) < ONE_DAY_MS) return; + fetchLatest(toast, kv); + }) + .catch(() => {}); } function fetchLatest(toast: Toast, kv?: KV) { @@ -36,7 +36,7 @@ function fetchLatest(toast: Toast, kv?: KV) { .then((r) => r.json()) // biome-ignore lint/suspicious/noExplicitAny: untyped JSON response .then((pkg: any) => { - kv?.set("lastUpdateCheck", Date.now().toString()); + Promise.resolve(kv?.set("lastUpdateCheck", Date.now().toString())).catch(() => {}); const latest = pkg?.version; if (latest && latest !== VERSION) { toast({ message: `vimcode update available: v${VERSION} → v${latest}`, variant: "info", duration: 5000 }); diff --git a/test/version.test.ts b/test/version.test.ts new file mode 100644 index 0000000..1e3188e --- /dev/null +++ b/test/version.test.ts @@ -0,0 +1,53 @@ +import { afterEach, beforeEach, describe, expect, it, mock } from "bun:test"; +import { checkForUpdate, VERSION } from "../src/version"; + +const realFetch = globalThis.fetch; +let fetchMock: ReturnType; + +const flush = () => new Promise((resolve) => setTimeout(resolve, 0)); +const recent = () => String(Date.now() - 60_000); +const stale = () => String(Date.now() - 2 * 24 * 60 * 60 * 1000); + +beforeEach(() => { + fetchMock = mock(async () => new Response(JSON.stringify({ version: "999.0.0" }))); + globalThis.fetch = fetchMock as unknown as typeof fetch; +}); + +afterEach(() => { + globalThis.fetch = realFetch; +}); + +describe("checkForUpdate", () => { + it("skips the fetch when a sync KV (v1) says it checked today", async () => { + checkForUpdate(() => {}, { get: () => recent(), set: () => {} }); + await flush(); + expect(fetchMock).not.toHaveBeenCalled(); + }); + + it("skips the fetch when an async KV (v2) says it checked today", async () => { + checkForUpdate(() => {}, { get: async () => recent(), set: async () => {} }); + await flush(); + expect(fetchMock).not.toHaveBeenCalled(); + }); + + it("fetches, records the check and toasts when the last check is stale", async () => { + const toast = mock(() => {}); + const set = mock(() => {}); + checkForUpdate(toast, { get: () => stale(), set }); + await flush(); + await flush(); + expect(fetchMock).toHaveBeenCalledTimes(1); + expect(set).toHaveBeenCalledWith("lastUpdateCheck", expect.any(String)); + expect(toast).toHaveBeenCalledWith({ + message: `vimcode update available: v${VERSION} → v999.0.0`, + variant: "info", + duration: 5000, + }); + }); + + it("fetches when there is no KV", async () => { + checkForUpdate(() => {}); + await flush(); + expect(fetchMock).toHaveBeenCalledTimes(1); + }); +}); From ade17b7821c93b34f01c3574b99a83f8bac2e429 Mon Sep 17 00:00:00 2001 From: Rohit Pathak Date: Fri, 13 Nov 2026 23:38:44 -0500 Subject: [PATCH 2/2] chore: pin bun 1.3 with mise Co-Authored-By: Claude Opus 5.5 --- mise.toml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 mise.toml diff --git a/mise.toml b/mise.toml new file mode 100644 index 0000000..c80fc01 --- /dev/null +++ b/mise.toml @@ -0,0 +1,3 @@ +# Pins bun for this project (mise). Node comes from the global default. +[tools] +bun = "1.3"