From 78e89241a6e43241008dee23905edc61392d2fc5 Mon Sep 17 00:00:00 2001 From: Alexander Kucera Date: Wed, 25 Nov 2026 10:43:26 +0100 Subject: [PATCH] fix: address round-4 review findings - apply(): if a newer invocation changed the catalog while this one awaited the model refresh, exit silently. The superseded invocation otherwise reported the second's catalog in its notice and could fire one extra setModel. Pinned with a deferred-refresh test. - CITATION.cff: drop date-released while the CHANGELOG is [Unreleased] and no release tag exists; version stays 0.1.0. - Tests: 18 (was 17). --- CITATION.cff | 1 - index.ts | 2 ++ tests/index.test.mjs | 17 +++++++++++++++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/CITATION.cff b/CITATION.cff index b6d724b..9ca7a77 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -9,7 +9,6 @@ authors: family-names: "Kucera" email: a.kucera@babylondreams.de version: 0.1.0 -date-released: "2026-11-25" abstract: >- Nous Portal provider extension for the pi coding agent: subscription device-code OAuth and API-key auth against the Nous inference API, diff --git a/index.ts b/index.ts index 3736d22..eabd652 100644 --- a/index.ts +++ b/index.ts @@ -277,6 +277,8 @@ export default function nousPortal(pi: ExtensionAPI) { else writeFileSync(flagPath, next); catalog = next; await ctx.modelRegistry.refresh({ providers: [PROVIDER_ID] }); + // A newer invocation may have changed the catalog while we awaited; it reports the final state, so stay silent. + if (catalog !== next) return; const shown = ctx.modelRegistry.getAvailable().filter((m) => m.provider === PROVIDER_ID && inCatalog(m)); // Keep the session usable only when a Nous model just got filtered out; a session on another provider // is left alone, and the notice names the model actually in use, not the first hit. diff --git a/tests/index.test.mjs b/tests/index.test.mjs index f69821f..2aec461 100644 --- a/tests/index.test.mjs +++ b/tests/index.test.mjs @@ -150,10 +150,10 @@ const drive = (flag) => { registerProvider: (input) => Object.assign(provider, input), setModel: async (model) => switched.push(model), }); - const run = (name, model, available) => + const run = (name, model, available, refresh = async () => {}) => commands[name].handler("", { model, - modelRegistry: { refresh: async () => {}, getAvailable: () => available }, + modelRegistry: { refresh, getAvailable: () => available }, ui: { notify: (message) => notes.push(message) }, }); return { run, provider, switched, notes }; @@ -217,6 +217,19 @@ test("/nous-catalog cycles full → free → promo → full", async () => { } }); +test("overlapping catalog switches: the invocation superseded while awaiting a slow refresh stays silent", async () => { + const { run, switched, notes } = drive(); + const all = [nous("free-a", "free"), nous("promo-a", "promo"), nous("paid")]; + let release; + const gate = new Promise((resolve) => (release = resolve)); + const first = run("nous-free", undefined, all, () => gate); // apply("free"), then awaits a slow refresh + await run("nous-catalog", undefined, all); // reads catalog "free" → applies "promo", refresh resolves at once + release(); + await first; + assert.deepEqual(notes.map((n) => n.split(" ")[2]), ["promo"]); + assert.deepEqual(switched, []); +}); + test("a saved catalog survives restart; a corrupted flag falls back to full", () => { const all = [nous("free-a", "free"), nous("promo-a", "promo"), nous("paid")]; try {