diff --git a/test/vitest-performance-config.test.ts b/test/vitest-performance-config.test.ts index 213d73bd723..4766b6cf272 100644 --- a/test/vitest-performance-config.test.ts +++ b/test/vitest-performance-config.test.ts @@ -22,6 +22,43 @@ describe("loadVitestExperimentalConfig", () => { }); }); + it("disables the filesystem module cache by default on Windows", () => { + const originalRunnerOs = process.env.RUNNER_OS; + process.env.RUNNER_OS = "Windows"; + try { + expect(loadVitestExperimentalConfig({ RUNNER_OS: "Windows" })).toEqual({}); + } finally { + if (originalRunnerOs === undefined) { + delete process.env.RUNNER_OS; + } else { + process.env.RUNNER_OS = originalRunnerOs; + } + } + }); + + it("still allows enabling the filesystem module cache explicitly on Windows", () => { + const originalRunnerOs = process.env.RUNNER_OS; + process.env.RUNNER_OS = "Windows"; + try { + expect( + loadVitestExperimentalConfig({ + RUNNER_OS: "Windows", + OPENCLAW_VITEST_FS_MODULE_CACHE: "1", + }), + ).toEqual({ + experimental: { + fsModuleCache: true, + }, + }); + } finally { + if (originalRunnerOs === undefined) { + delete process.env.RUNNER_OS; + } else { + process.env.RUNNER_OS = originalRunnerOs; + } + } + }); + it("allows disabling the filesystem module cache explicitly", () => { expect( loadVitestExperimentalConfig({ diff --git a/vitest.performance-config.ts b/vitest.performance-config.ts index 3211efbf6d4..a94e089b599 100644 --- a/vitest.performance-config.ts +++ b/vitest.performance-config.ts @@ -10,6 +10,14 @@ const isDisabled = (value: string | undefined): boolean => { return normalized === "0" || normalized === "false"; }; +const isWindowsEnv = (env: EnvMap, platform: NodeJS.Platform): boolean => { + if (platform === "win32") { + return true; + } + const runnerOs = env.RUNNER_OS?.trim().toLowerCase(); + return runnerOs === "windows"; +}; + export function loadVitestExperimentalConfig(env: EnvMap = process.env): { experimental?: { fsModuleCache?: true; @@ -22,8 +30,12 @@ export function loadVitestExperimentalConfig(env: EnvMap = process.env): { importDurations?: { print: true }; printImportBreakdown?: true; } = {}; + const windowsEnv = isWindowsEnv(env, process.platform); - if (!isDisabled(env.OPENCLAW_VITEST_FS_MODULE_CACHE)) { + if (!windowsEnv && !isDisabled(env.OPENCLAW_VITEST_FS_MODULE_CACHE)) { + experimental.fsModuleCache = true; + } + if (windowsEnv && isEnabled(env.OPENCLAW_VITEST_FS_MODULE_CACHE)) { experimental.fsModuleCache = true; } if (isEnabled(env.OPENCLAW_VITEST_IMPORT_DURATIONS)) {