testing · diff

git:20260319.c97e02c to git:20260329.8cf93fd

10 added, 15 removed. Audit A to A.

What this update changes in the checks

No check changed: every fixed check gives the same answer before and after this update.

A tripped check is a label, not a verdict: read the matched text and the lines below. This week's updates that newly trip a check.

---
- description: Vitest testing patterns — LLM mocks, coverage config, test file structure
- globs: src/**/__tests__/*.test.ts,src/test/**
- alwaysApply: false
+ description: Vitest testing patterns for Caliber
+ globs: src/**/__tests__/**
---
- - All LLM calls globally mocked via `src/test/setup.ts` — no real API calls in tests
- - Override per-test: `vi.spyOn(llm, 'llmCall').mockResolvedValue('...')`
- - Coverage excludes: `src/test/`, `src/bin.ts`, `src/cli.ts`, `src/commands/**`, `dist/**`
- - Scoring checks (`src/scoring/checks/`) are pure functions — test with temp dirs or mocked fs
- - LLM utils (`extractJson`, `estimateTokens`) are pure — no mocking needed
- - Fingerprint tests (`src/fingerprint/__tests__/`): mock `fs` and `child_process.execSync`
- - Learner tests (`src/learner/__tests__/`): use temp directories from `os.tmpdir()`
- - Use `memfs` for filesystem mocking when needed
- - Run single file: `npx vitest run src/scoring/__tests__/accuracy.test.ts`
- - Spawn mock return values must include `stderr: { on: vi.fn() }` when stdio is `['pipe', 'pipe', 'pipe']`
- - Tests for `src/llm/__tests__/index.test.ts` must call `vi.unmock('../index.js')` and `resetProvider()` in beforeEach
- - Tests for `src/llm/__tests__/model-recovery.test.ts` must call `vi.unmock('../model-recovery.js')` in beforeEach
+ - Vitest config: `vitest.config.ts` · Setup: `src/test/setup.ts`
+ - Run all: `npm run test` · Single: `npx vitest run src/scoring/__tests__/accuracy.test.ts`
+ - Coverage: `npm run test:coverage` (v8 provider)
+ - LLM calls globally mocked in `src/test/setup.ts` — never call real providers
+ - Use `vi.mock()` for `fs`, `child_process` · `vi.mocked()` for type-safe assertions
+ - Tests colocated: `src/llm/__tests__/config.test.ts` tests `src/llm/config.ts`
+ - Pattern: `describe` → `beforeEach(vi.clearAllMocks)` → `it` with `expect`
+ - Environment vars: save in `beforeEach`, restore in `afterEach`