test: address round-5 review findings
- provider fetchModels: pin that an empty live list keeps the last good list instead of the baseline. - tokenRequest: pin the OAuth error mapping (error -> code, error_description -> message, body excerpt when absent). - overlap test: give the session a Nous model so the setModel half of the supersede guard is asserted (exactly one switch, by the winner). - README: drop the hard-coded live catalog counts (409 / 3 / 42); they are a 2026-11-25 snapshot that drifts silently. /model shows the live list. No production-code change. Tests: 20 (was 18).
This commit is contained in:
1 parent
78e89241a6
commit
04fa08f0b7
2 files changed
+28
-10
No files matched your search
@@ -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.
|
||||
|
||||
|
||||
+22
-4
@@ -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", () => {
|
||||
|
||||
Reference in new issue
Block a user