diff --git a/docs/help/testing.md b/docs/help/testing.md index 7db025fcae0..345814babab 100644 --- a/docs/help/testing.md +++ b/docs/help/testing.md @@ -82,7 +82,8 @@ Think of the suites as “increasing realism” (and increasing flakiness/cost): - Fast-local iteration note: - `pnpm test:changed` runs the wrapper with `--changed origin/main`. - The base Vitest config marks the wrapper manifests/config files as `forceRerunTriggers` so changed-mode reruns stay correct when scheduler inputs change. - - Use `OPENCLAW_VITEST_FS_MODULE_CACHE=1` for repeated local reruns on a stable branch when transform cost dominates. + - Vitest's filesystem module cache is now enabled by default for Node-side test reruns. + - Opt out with `OPENCLAW_VITEST_FS_MODULE_CACHE=0` or `OPENCLAW_VITEST_FS_MODULE_CACHE=false` if you suspect stale transform cache behavior. - Perf-debug note: - `pnpm test:perf:imports` enables Vitest import-duration reporting plus import-breakdown output. - `pnpm test:perf:imports:changed` scopes the same profiling view to files changed since `origin/main`. diff --git a/docs/reference/test.md b/docs/reference/test.md index c0a65ab60c6..cb15e6bd65e 100644 --- a/docs/reference/test.md +++ b/docs/reference/test.md @@ -39,7 +39,7 @@ For local PR land/gate checks, run: If `pnpm test` flakes on a loaded host, rerun once before treating it as a regression, then isolate with `pnpm vitest run `. For memory-constrained hosts, use: - `OPENCLAW_TEST_PROFILE=low OPENCLAW_TEST_SERIAL_GATEWAY=1 pnpm test` -- `OPENCLAW_VITEST_FS_MODULE_CACHE=1 pnpm test:changed` +- `OPENCLAW_VITEST_FS_MODULE_CACHE=0 pnpm test:changed` ## Model latency bench (local keys) diff --git a/test/vitest-performance-config.test.ts b/test/vitest-performance-config.test.ts index 6f6fdd07ad3..213d73bd723 100644 --- a/test/vitest-performance-config.test.ts +++ b/test/vitest-performance-config.test.ts @@ -2,8 +2,12 @@ import { describe, expect, it } from "vitest"; import { loadVitestExperimentalConfig } from "../vitest.performance-config.ts"; describe("loadVitestExperimentalConfig", () => { - it("returns an empty object when no perf flags are enabled", () => { - expect(loadVitestExperimentalConfig({})).toEqual({}); + it("enables the filesystem module cache by default", () => { + expect(loadVitestExperimentalConfig({})).toEqual({ + experimental: { + fsModuleCache: true, + }, + }); }); it("enables the filesystem module cache explicitly", () => { @@ -18,6 +22,14 @@ describe("loadVitestExperimentalConfig", () => { }); }); + it("allows disabling the filesystem module cache explicitly", () => { + expect( + loadVitestExperimentalConfig({ + OPENCLAW_VITEST_FS_MODULE_CACHE: "0", + }), + ).toEqual({}); + }); + it("enables import timing output and import breakdown reporting", () => { expect( loadVitestExperimentalConfig({ @@ -26,6 +38,7 @@ describe("loadVitestExperimentalConfig", () => { }), ).toEqual({ experimental: { + fsModuleCache: true, importDurations: { print: true }, printImportBreakdown: true, }, diff --git a/vitest.performance-config.ts b/vitest.performance-config.ts index 07f35946258..3211efbf6d4 100644 --- a/vitest.performance-config.ts +++ b/vitest.performance-config.ts @@ -5,6 +5,11 @@ const isEnabled = (value: string | undefined): boolean => { return normalized === "1" || normalized === "true"; }; +const isDisabled = (value: string | undefined): boolean => { + const normalized = value?.trim().toLowerCase(); + return normalized === "0" || normalized === "false"; +}; + export function loadVitestExperimentalConfig(env: EnvMap = process.env): { experimental?: { fsModuleCache?: true; @@ -18,7 +23,7 @@ export function loadVitestExperimentalConfig(env: EnvMap = process.env): { printImportBreakdown?: true; } = {}; - if (isEnabled(env.OPENCLAW_VITEST_FS_MODULE_CACHE)) { + if (!isDisabled(env.OPENCLAW_VITEST_FS_MODULE_CACHE)) { experimental.fsModuleCache = true; } if (isEnabled(env.OPENCLAW_VITEST_IMPORT_DURATIONS)) {