# Domain 3: Test Infrastructure

> Last updated: 2026-04-19

**Pillars served:** governance-axis P2 (primary), P5 (supporting); content-quality-axis CQ5 Testability (primary — testing-quality content).

**Scope:** All 133 test files across the test suite. Coverage analysis, test quality assessment, and testing infrastructure evaluation.
**Sub-agents:** 5

> **Test file inventory:** see `governance/inventory.json` (`testFiles` array, regenerated by `npm run inventory`) and the `src/__tests__/` row in `CLAUDE.md` §Architecture. Currently 133 test files across 22 directories.

## Sub-Agent Decomposition

| SA | Focus | Files |
|----|-------|-------|
| 3.1 | Adapter Tests | 26 test files in `src/__tests__/adapters/` (now includes `amazonq.test.ts`) |
| 3.2 | CLI Tests | 27 test files in `src/__tests__/cli/` |
| 3.3 | Content & Manifest Tests | `src/__tests__/content/` (13 files), `src/__tests__/manifest/`, `src/__tests__/manifests/` |
| 3.4 | Integration Tests | `src/__tests__/{hooks,models,detect,env,archive,merge,workspace,worktree,pipeline,audit,cliTools,version,clean,e2e,importers,install}/` (83 files) |
| 3.5 | Coverage Meta-Analysis | All 133 test files, coverage report, test infrastructure |

> Apply the rigor contract per [../templates/rigor-contract.md](../templates/rigor-contract.md) on every finding.

## Audit Checklists

> **Per-finding (Decision 17 / charter directive 18):** every finding declares `impact_horizon: short|medium|long` AND `progress_toward_pillar: <axis>.<pillar_id>+<delta>` (e.g., `governance.P5+0.15` or `content-quality.CQ5+0.20`); orchestrator DROPS at output time if either missing.

### 3.1 Adapter Tests
- [ ] Each adapter test covers: output path correctness, format validation, feature flag behavior, MCP format, hook format, managed blocks
- [ ] Test isolation — no cross-test state leakage
- [ ] Mocking patterns — mocks are minimal and realistic
- [ ] Coverage of error paths — adapter failures are tested

### 3.2 CLI Tests
- [ ] Each CLI command test covers: happy path, error cases, edge cases (existing install, corrupt state, missing dependencies)
- [ ] Mock completeness — filesystem, network, and process mocks are accurate
- [ ] Interactive prompt testing — inquirer prompts are correctly simulated
- [ ] Exit code verification — correct exit codes for success and failure

### 3.3 Content & Manifest Tests
- [ ] Content index tests cover tag filtering, preset application, selective init scenarios
- [ ] Tag tests verify classification accuracy for all content types
- [ ] Manifest tests cover schema validation, parsing edge cases, malformed input

### 3.4 Integration Tests
- [ ] Hook integration tests — hook lifecycle, adapter-specific format transformation
- [ ] Model resolution/customization tests — override application, precedence
- [ ] Repo analyzer tests — detection accuracy across project types
- [ ] MCP env tests — environment variable generation correctness
- [ ] Drift detection tests — regenerate-and-diff accuracy
- [ ] Archive tests — backup creation, restoration, cleanup
- [ ] Safe write/managed block tests — merge integrity, concurrent access
- [ ] Workspace integration tests — manifest lifecycle, multi-repo sync, detection accuracy
- [ ] Worktree integration tests — setup flow, pattern resolution, cross-worktree isolation

### 3.5 Coverage Meta-Analysis
- [ ] Run `npm test` and analyze overall coverage percentage
- [ ] Identify untested modules — source files with zero coverage
- [ ] Identify untested branches — conditional paths not exercised
- [ ] Test quality assessment — assertions per test, meaningful vs trivial tests
- [ ] Test determinism — no flaky tests, no order dependencies
- [ ] Fixture management — test data is organized and maintainable
- [ ] Missing test scenarios — identify gaps based on source code analysis
- [ ] Regression quality assessment: zero-regression rate across framework updates, content freshness verification, maintenance burden analysis (effort to keep framework current)
