import { defineConfig } from "vitest/config"; const include = [ "extensions/**/__tests__/**/*.test.ts", "scripts/**/*.test.ts", "skills/**/*.test.ts", "test/**/*.test.ts", ]; const exclude = ["**/__e2e__/**", "**/node_modules/**"]; const nativeTests = [ "extensions/ultra/__tests__/dynamic-extensions.test.ts", // Native Git/GH/UI round-trips need the uncontended subprocess group. "extensions/strata/__serial__/**/*.test.ts", "extensions/strata/__tests__/contract.test.ts", "scripts/prompt-composition.test.ts", "scripts/e2e-requirements.test.ts", "scripts/build/build.test.ts", "scripts/build/pfui-runtime.test.ts", ]; export default defineConfig({ test: { reporters: ["minimal"], testTimeout: 30_000, hookTimeout: 30_000, // Non-gating, author-driven coverage (opt-in via `//:coverage`). Provider // is V8: timed at 37s vs Istanbul 44s over the unit+contract suite, with // far lower transform overhead; vitest's ast-aware remapping reports // line/branch/function. `all: true` surfaces unimported owned files. coverage: { provider: "v8", all: true, include: ["extensions/**/*.ts"], exclude: [ "**/__tests__/**", "**/__e2e__/**", "**/__bench__/**", "**/*.test.ts", "**/*.bench.ts", "**/playwright.config.ts", ], reporter: ["text", "json-summary"], }, projects: [ { extends: true, test: { // Pure unit and component tests with deterministic inputs. // Pure, parallel-safe tests. Tests that mock core modules or spawn // subprocesses belong in `__serial__` (the `isolated-serial` project). name: "unit", include, exclude: [ ...exclude, ...nativeTests, // Owned-fixture contract tests mutate process.env, so they run // isolated in the `contract` project instead. "**/contract.test.ts", "test/**", "scripts/build/packages.test.ts", ], isolate: false, // Default-group projects share a pool sized to half the cores; // Vitest requires equal maxWorkers within a group. // Native subprocess tests run later in their own single-worker group. maxWorkers: "50%", }, }, { extends: true, test: { name: "contract", include: [ "extensions/**/__tests__/contract.test.ts", "test/**/*.test.ts", ], exclude: [...exclude, ...nativeTests], // Each contract test owns a sandboxed process.env; isolate per file. isolate: true, maxWorkers: "50%", }, }, { extends: true, test: { // Any extension's `__serial__/` tests: they mock core modules, stub // globals, or spawn subprocesses, so they need fresh module state per // file and a single worker. Routed by folder, not by extension name. name: "isolated-serial", include: ["extensions/**/__serial__/**/*.test.ts"], exclude: [...exclude, ...nativeTests], isolate: true, // Subprocess/module-mock heavy; isolate per file (fresh module state) // and share the capped pool so total concurrent subprocesses stay // bounded by the 50%-of-cores worker count. maxWorkers: "50%", }, }, { extends: true, test: { // Generated-package tests: immutable dist snapshots loaded relocated // through a child Pi. Opt-in and slow; see packages.test.ts. name: "packages", include: ["scripts/build/packages.test.ts"], exclude, isolate: true, maxWorkers: "50%", }, }, { extends: true, test: { // Native integration: real subprocesses/child validators in their own // process, one worker to avoid watchdog/subprocess contention. name: "native", include: nativeTests, exclude, isolate: true, sequence: { groupOrder: 1 }, maxWorkers: 1, }, }, ], }, });