- 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.
2.1 KiB
2.1 KiB
tests/AGENTS.md
Purpose
Offline unit tests for index.ts. They pin the pure logic that has real branching: model mapping, credential construction, and model fetching. No network, no real credentials.
Ownership
- This doc owns the test suite, its loader setup, and the host-package stub.
- Root AGENTS.md owns
npm run check(which runs these tests) and repo-wide rules. index.tsis owned by the root; tests import its exports but never edit it.
Local Contracts
index.test.mjsloadsindex.tsthrough jiti, the same TS loader pi uses, because the host packages are not installed innode_modules.- Host imports are aliased to
stubs/pi-ai.mjs. Alias keys are matched longest-prefix first:@earendil-works/pi-ai/compatmust be listed before@earendil-works/pi-ai, or the bare key swallows the subpath and resolution fails. stubs/pi-ai.mjsexports only whatindex.tstouches 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", …)fromnode:test, which restores itself when the test ends. Do not hand-roll aglobalThis.fetchswap. fetchModelsreads a key only from thecredentialargument. Env resolution of$NOUS_API_KEYisenvApiKeyAuth's job upstream, so tests never need to touchprocess.env.
Work Guidance
- Test behaviour, not implementation. Each test pins one contract from the function under test.
- When adding an export with branching logic to
index.ts, add a test here in the same change. - Keep the stub minimal: add an export only when
index.tsstarts importing it at module load.
Verification
npm test(ornpm run check) runsnode --test tests/*.test.mjs. All tests must pass.
Child DOX Index
| Path | Scope |
|---|---|
| (none) | stubs/ holds a single file governed by the contracts above |