import { availableParallelism } from "node:os"; import { defaultExclude, defineConfig } from "vitest/config"; export default defineConfig({ test: { // Spread defaultExclude -- Vitest replaces this array rather than merging // it, so a bare ["**/.claude/**"] would silently re-enable scanning of // node_modules/ and dist/. // // .claude/worktrees// holds full linked worktrees, each with its own // complete test/ directory. Without this, `npm test` from the primary // checkout discovers and runs every test file a second time (once per // live worktree), roughly doubling suite runtime and creating spurious // load-related flakes. // Scoped to worktrees specifically rather than all of `.claude/`: // `src/assets/.claude/` is tracked, distributable content, and a blanket // exclusion would silently skip any test fixture added there later. exclude: [...defaultExclude, "**/.claude/worktrees/**"], // A cap on the worker pool, not a floor: a machine with five or fewer // CPUs keeps vitest's own default (availableParallelism() - 1), so CI's // 4-vCPU runners still use 3. Measured 2026-10-21 on the operator's // Windows machine (8 cores, 16 logical CPUs, 2319 tests): the default 15 // workers timed out 23 tests, 12 workers 13, 10 workers 12, 8 workers 1 // and 3, 6 workers 1, 4 workers 0 and 0, while the suite took 192-243 s // at every count -- the git-heavy tests wait on process creation, not // CPU, so workers past 4 add contention and no speed. The cap is per // run: two sessions running the suite at once still contend. // VITEST_MAX_WORKERS and --maxWorkers override it for an experiment. maxWorkers: Math.min(Math.max(availableParallelism() - 1, 1), 4), passWithNoTests: true, reporters: ["default", "junit"], outputFile: { junit: "coverage/junit.xml", }, coverage: { provider: "v8", reporter: ["text", "lcov", "cobertura"], exclude: [ // Build scripts — not part of the shipped library "scripts/**", // CLI entry point — wires commands; covered by integration tests indirectly "src/index.ts", // Interactive agent setup — requires TTY/inquirer prompts, not unit-testable "src/modules/agents.ts", // spell doctor — side-effectful env checks; not unit-testable without heavy mocking "src/commands/doctor.ts", // Type declarations only "src/types.ts", // Agent profile config — data file, no logic "src/config/agent-profiles.ts", ], thresholds: { lines: 80, branches: 80, functions: 80, statements: 80, "src/modules/run-grants.ts": { lines: 95, branches: 95, functions: 95, statements: 95, }, "src/commands/login.ts": { lines: 95, branches: 95, functions: 95, statements: 95, }, "src/modules/oidc.ts": { lines: 95, branches: 95, functions: 95, statements: 95, }, // The presence bearer check is authentication (testing-standards.md: critical tier). "src/modules/presence/auth.ts": { lines: 95, branches: 95, functions: 95, statements: 95, }, // The presence token store is credential storage (testing-standards.md: critical tier). "src/modules/presence/store.ts": { lines: 95, branches: 95, functions: 95, statements: 95, }, "src/modules/copier.ts": { lines: 95, branches: 95, functions: 95, statements: 95, }, "src/modules/manifest.ts": { lines: 95, branches: 90, // non-ENOENT rethrow branch tested via itOnPosix (chmod); skipped on Windows functions: 95, statements: 95, }, "src/modules/merger.ts": { lines: 95, branches: 95, functions: 95, statements: 95, }, "src/modules/registry.ts": { lines: 95, branches: 95, functions: 95, statements: 95, }, "src/config/profiles.ts": { lines: 95, branches: 95, functions: 95, statements: 95, }, }, }, }, });