Record the fresh-context audit of the Nous Portal provider as the first entry in docs/devlog/ (rounds 1-5, the fixes in 00d50e1..04fa08f, decisions, gotchas, open items) with its INDEX.md, and add the Session Logs pointer window to the root AGENTS.md. DOX pass: docs/AGENTS.md now owns docs/devlog/ (one log per unit of work, INDEX.md is the source of truth, logs are append-only) and its verification line covers the filename convention; tests/AGENTS.md documents the drive() harness changes from rounds 4 and 5 (a deferred refresh to simulate overlapping handlers, a Nous model for setModel assertions, provider-level fetchModels via the registered provider).
3.0 KiB
3.0 KiB
tests/AGENTS.md
Purpose
Offline unit tests for index.ts. They pin the pure logic that has real branching: model mapping, credential construction, model fetching, token-endpoint error handling, and the slash commands (driven through a recording pi). 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.tsimports:envApiKeyAuth,createProvider,openAICompletionsApi,getAgentDir(plusagentDirso tests can find the flag file).getAgentDiris called inside the default export, so it is reached only by tests that drive the commands; it returns a privatemkdtempdir per run, shared throughglobalThisbecause jiti loads the stub as a separate instance from a native import. 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,tokenRequest,fetchModels,tierOf,withoutTierHeader, and the default export via thedrive()harness.drive(flag)returnsrun(name, model, available, refresh)— pass a deferred promise asrefreshto simulate overlapping command invocations, and a Nousmodelwhen thesetModelhalf of a contract is under test — plus the registeredprovider, which is how the provider-levelfetchModelslast-good retention is reached. Anything else is not unit-tested (notably the device-code poll loop insidelogin, which would need timer control and extraction). - 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. The one test that touchesprocess.envsets it deliberately, to pin thatfetchModelsignores it; it restores the previous value int.after.
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 |