fix: address round-1 review findings

- slow_down now sleeps (and waits longer) instead of re-polling at
  once; the interval cap that could lower a server interval is gone.
  The deadline already bounds the loop.
- Non-JSON error bodies from gateways and the Vercel checkpoint no
  longer surface as SyntaxError; the HTTP status is preserved.
- Drop the dead process.env.NOUS_API_KEY fallback in fetchModels:
  envApiKeyAuth already resolves it into the credential upstream.
- apply() persists the catalog flag before mutating memory, so a
  read-only agent dir cannot leave the two out of step.
- sleep() replaced with node:timers/promises; three unused exports
  removed; stale tags.user comment corrected; hermes filter explained.
- Tests: 8 (was 4). Pin tierOf, the tier header, and withoutTierHeader
  on both stream entry points; t.mock.method replaces hand-rolled fetch
  swaps; stub gains getAgentDir.
- Docs: README covers install lockfile flag, hermes row, browser-UA
  posture, and typecheck path pinning; AGENTS.md allowlist includes
  pi-coding-agent; tests/AGENTS.md contracts updated.
This commit is contained in:
AlexKucera committed 2026-11-25 09:48:55 +01:00
1 parent 8bbece7613
commit 00d50e10de
7 files changed
+102 -50

No files matched your search

+4 -4
View File
@@ -14,10 +14,10 @@ Offline unit tests for `index.ts`. They pin the pure logic that has real branchi
- `index.test.mjs` loads `index.ts` through jiti, the same TS loader pi uses, because the host packages are not installed in `node_modules`.
- Host imports are aliased to `stubs/pi-ai.mjs`. Alias keys are matched longest-prefix first: `@earendil-works/pi-ai/compat` must be listed before `@earendil-works/pi-ai`, or the bare key swallows the subpath and resolution fails.
- `stubs/pi-ai.mjs` exports only what `index.ts` touches at import time: `envApiKeyAuth`, `createProvider`, `openAICompletionsApi`. It is a type-less stub; correctness of those functions is pi's concern and is verified live, not here.
- Exported functions under test: `toModel`, `toCredential`, `fetchModels`. Anything not exported is not unit-tested.
- Network calls are replaced by assigning `globalThis.fetch` and restored in `finally`.
- `fetchModels` falls back to `process.env.NOUS_API_KEY`, so tests that assert "no network" must delete that variable for the duration and restore it afterwards.
- `stubs/pi-ai.mjs` exports only what `index.ts` touches at module load: `envApiKeyAuth`, `createProvider`, `openAICompletionsApi`, `getAgentDir`. It is a type-less stub; correctness of those functions is pi's concern and is verified live, not here.
- Exported functions under test: `toModel`, `toCredential`, `fetchModels`, `tierOf`, `withoutTierHeader`. Anything not exported is not unit-tested.
- Network calls are replaced with `t.mock.method(globalThis, "fetch", …)` from `node:test`, which restores itself when the test ends. Do not hand-roll a `globalThis.fetch` swap.
- `fetchModels` reads a key only from the `credential` argument. Env resolution of `$NOUS_API_KEY` is `envApiKeyAuth`'s job upstream, so tests never need to touch `process.env`.
## Work Guidance