Files
nous-portal/tests/AGENTS.md
T
AlexKucera 8bbece7613 docs: install DOX framework and initialize the DOX tree
Appends the canonical DOX framework to the root AGENTS.md and creates
child docs for the two durable boundaries: docs/ (ADR numbering,
format and status rules) and tests/ (jiti aliasing to host-package
stubs, what the tests pin, the NOUS_API_KEY fallback gotcha).

tests/stubs/ gets no child doc on purpose: it is a single file whose
only contract is owned by tests/AGENTS.md.
2026-11-25 09:35:17 +01:00

37 lines
2.0 KiB
Markdown

# 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.ts` is owned by the root; tests import its exports but never edit it.
## Local Contracts
- `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.
## 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.ts` starts importing it at module load.
## Verification
- `npm test` (or `npm run check`) runs `node --test tests/*.test.mjs`. All tests must pass.
## Child DOX Index
| Path | Scope |
|---|---|
| (none) | `stubs/` holds a single file governed by the contracts above |