diff --git a/README.md b/README.md index cbfb622..c837ceb 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Then in pi: - `/login nous-portal` offers two methods: **Sign in to Nous Portal (subscription)** for the device-code OAuth flow, or **Nous Portal API key** to store an `sk-nous-…` key. - The API-key route also reads `$NOUS_API_KEY`. -- `/model` lists the live catalog (409 models) in interactive sessions. +- `/model` lists the live catalog in interactive sessions. ### Catalog filters @@ -32,11 +32,11 @@ Then in pi: /nous-free jump to free models (again returns to full) ``` -| Catalog | Live signal | Models | -|---|---|---| -| full | every chat model except Hermes-branded ids (none in the catalog as of 2026-11-25) | 409 | -| free | `synthesizedFreeVariant`, also suffixed `:free` | 3 | -| promo | `pricing.original` above the current price | 42 | +| Catalog | Live signal | +|---|---| +| full | every chat model except Hermes-branded ids (none in the catalog as of 2026-11-25) | +| free | `synthesizedFreeVariant`, also suffixed `:free` | +| promo | `pricing.original` above the current price | The choice is saved in `~/.pi/agent/nous-portal-catalog` and survives restarts. diff --git a/tests/index.test.mjs b/tests/index.test.mjs index 2aec461..60950d3 100644 --- a/tests/index.test.mjs +++ b/tests/index.test.mjs @@ -139,6 +139,24 @@ test("fetchModels: an API key is sent as the bearer; a non-OK response throws wi assert.equal(auth, "Bearer k"); }); +test("tokenRequest: a JSON error body maps error → code and error_description → message; a missing description falls back to the body", async (t) => { + let body = JSON.stringify({ error: "slow_down", error_description: "SLOW DOWN" }); + t.mock.method(globalThis, "fetch", async () => ({ ok: false, status: 400, text: async () => body })); + await assert.rejects(tokenRequest({ device_code: "d" }), (error) => error.code === "slow_down" && error.message === "slow_down: 400 SLOW DOWN"); + body = JSON.stringify({ error: "expired_token" }); + await assert.rejects(tokenRequest({ device_code: "d" }), (error) => error.code === "expired_token" && error.message === 'expired_token: 400 {"error":"expired_token"}'); +}); + +test("provider fetchModels: an empty live list keeps the last good list instead of the baseline", async (t) => { + const { provider } = drive(); + const ctx = { credential: { type: "api_key", key: "k" }, signal: new AbortController().signal }; + let data = [{ id: "qwen/qwen3.5-35b-a3b" }]; + t.mock.method(globalThis, "fetch", async () => ({ ok: true, json: async () => ({ data }) })); + assert.deepEqual((await provider.fetchModels(ctx)).map((m) => m.id), ["qwen/qwen3.5-35b-a3b"]); + data = []; + assert.deepEqual((await provider.fetchModels(ctx)).map((m) => m.id), ["qwen/qwen3.5-35b-a3b"]); +}); + // Drives the default export with a recording pi, so the slash commands run without a real host. // `flag` seeds the saved catalog before load to exercise the startup restore; default is a fresh install. const drive = (flag) => { @@ -217,17 +235,17 @@ test("/nous-catalog cycles full → free → promo → full", async () => { } }); -test("overlapping catalog switches: the invocation superseded while awaiting a slow refresh stays silent", async () => { +test("overlapping catalog switches: the invocation superseded while awaiting a slow refresh neither notifies nor switches the model", 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 + const first = run("nous-free", nous("paid"), all, () => gate); // apply("free"), then awaits a slow refresh + await run("nous-catalog", nous("paid"), all); // reads catalog "free" → applies "promo", refresh resolves at once, paid is filtered out → switches release(); await first; assert.deepEqual(notes.map((n) => n.split(" ")[2]), ["promo"]); - assert.deepEqual(switched, []); + assert.deepEqual(switched.map((m) => m.id), ["promo-a"]); // only the winning invocation switched }); test("a saved catalog survives restart; a corrupted flag falls back to full", () => {