diff --git a/tests2/harness/file-boundary-runner.ts b/tests2/harness/file-boundary-runner.ts new file mode 100644 index 000000000..ecc1dc5ef --- /dev/null +++ b/tests2/harness/file-boundary-runner.ts @@ -0,0 +1,17 @@ +import { VitestTestRunner } from "vitest/runners"; +import type { File } from "@vitest/runner"; +import { setProjectRoot } from "../../src/server/bobbit-dir.js"; +import { resetAgentDirStateForTests } from "../../src/server/agent-dir-config.js"; + +const BASELINE_CWD = process.cwd(); + +// isolate:false files share a fork's module graph, so the project-root and +// agent-dir singletons leak between files. onCollectStart is the only hook that +// runs per file before its module loads; env is left to the fork-scoped gateway. +export default class FileBoundaryRunner extends VitestTestRunner { + onCollectStart(file: File): void { + setProjectRoot(BASELINE_CWD); + resetAgentDirStateForTests(); + return super.onCollectStart(file); + } +} diff --git a/vitest.config.ts b/vitest.config.ts index 374cfe7d4..9e1f3e4bb 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -50,6 +50,8 @@ const shared = { }, }; const tier1SetupFiles = ["tests2/harness/tier1-spawn-guard.ts"]; +// Per-file reset of leaking dir singletons for the isolate:false projects. +const fileBoundaryRunner = "tests2/harness/file-boundary-runner.ts"; const coverage = { provider: "v8" as const, @@ -99,6 +101,7 @@ export default defineConfig({ ...shared, name: "v2-core", environment: "node", + runner: fileBoundaryRunner, setupFiles: tier1SetupFiles, include: execution.core, }, @@ -123,6 +126,7 @@ export default defineConfig({ ...shared, name: "v2-integration", environment: "node", + runner: fileBoundaryRunner, setupFiles: tier1SetupFiles, include: execution.integration, testTimeout: 60_000,