From 3ccf1bee2cd6ac253cdf4e71b508401bdeae9d08 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 22 Mar 2026 19:09:26 -0700 Subject: [PATCH] test: default scoped vitest configs to no-isolate --- docs/help/testing.md | 3 ++- test/vitest-scoped-config.test.ts | 33 +++++++++++++++++++++++++++++++ test/vitest-unit-config.test.ts | 7 +++++++ vitest.scoped-config.ts | 11 +++++++++++ vitest.unit.config.ts | 2 ++ 5 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 test/vitest-scoped-config.test.ts diff --git a/docs/help/testing.md b/docs/help/testing.md index 17d97c3ddd1..2be59360b47 100644 --- a/docs/help/testing.md +++ b/docs/help/testing.md @@ -73,7 +73,8 @@ Think of the suites as “increasing realism” (and increasing flakiness/cost): - Base Vitest config still defaults to `forks`. - Unit wrapper lanes default to `threads`, with explicit manifest fork-only exceptions. - Extension scoped config defaults to `threads`. - - `pnpm test` also defaults to `--isolate=false` at the wrapper level for faster file startup. + - Unit, channel, and extension configs default to `isolate: false` for faster file startup. + - `pnpm test` also passes `--isolate=false` at the wrapper level. - Opt back into Vitest file isolation with `OPENCLAW_TEST_ISOLATE=1 pnpm test`. - `OPENCLAW_TEST_NO_ISOLATE=0` or `OPENCLAW_TEST_NO_ISOLATE=false` also force isolated runs. diff --git a/test/vitest-scoped-config.test.ts b/test/vitest-scoped-config.test.ts new file mode 100644 index 00000000000..8713f0939dd --- /dev/null +++ b/test/vitest-scoped-config.test.ts @@ -0,0 +1,33 @@ +import { describe, expect, it } from "vitest"; +import channelsConfig from "../vitest.channels.config.ts"; +import extensionsConfig from "../vitest.extensions.config.ts"; +import { createScopedVitestConfig, resolveVitestIsolation } from "../vitest.scoped-config.ts"; + +describe("resolveVitestIsolation", () => { + it("defaults shared scoped configs to non-isolated workers", () => { + expect(resolveVitestIsolation({})).toBe(false); + }); + + it("restores isolate mode when explicitly requested", () => { + expect(resolveVitestIsolation({ OPENCLAW_TEST_ISOLATE: "1" })).toBe(true); + expect(resolveVitestIsolation({ OPENCLAW_TEST_NO_ISOLATE: "0" })).toBe(true); + expect(resolveVitestIsolation({ OPENCLAW_TEST_NO_ISOLATE: "false" })).toBe(true); + }); +}); + +describe("createScopedVitestConfig", () => { + it("applies non-isolated mode by default", () => { + const config = createScopedVitestConfig(["src/example.test.ts"]); + expect(config.test?.isolate).toBe(false); + }); +}); + +describe("scoped vitest configs", () => { + it("defaults channel tests to non-isolated mode", () => { + expect(channelsConfig.test?.isolate).toBe(false); + }); + + it("defaults extension tests to non-isolated mode", () => { + expect(extensionsConfig.test?.isolate).toBe(false); + }); +}); diff --git a/test/vitest-unit-config.test.ts b/test/vitest-unit-config.test.ts index 312d468a28b..0af3f4f7ae2 100644 --- a/test/vitest-unit-config.test.ts +++ b/test/vitest-unit-config.test.ts @@ -2,6 +2,7 @@ import fs from "node:fs"; import os from "node:os"; import path from "node:path"; import { afterEach, describe, expect, it } from "vitest"; +import unitConfig from "../vitest.unit.config.ts"; import { loadExtraExcludePatternsFromEnv, loadIncludePatternsFromEnv, @@ -77,3 +78,9 @@ describe("loadExtraExcludePatternsFromEnv", () => { ).toThrow(/JSON array/u); }); }); + +describe("unit vitest config", () => { + it("defaults unit tests to non-isolated mode", () => { + expect(unitConfig.test?.isolate).toBe(false); + }); +}); diff --git a/vitest.scoped-config.ts b/vitest.scoped-config.ts index 220c16e35cf..a34ad5e73c4 100644 --- a/vitest.scoped-config.ts +++ b/vitest.scoped-config.ts @@ -1,6 +1,16 @@ import { defineConfig } from "vitest/config"; import baseConfig from "./vitest.config.ts"; +export function resolveVitestIsolation( + env: Record = process.env, +): boolean { + const forceIsolation = env.OPENCLAW_TEST_ISOLATE === "1" || env.OPENCLAW_TEST_ISOLATE === "true"; + if (forceIsolation) { + return true; + } + return env.OPENCLAW_TEST_NO_ISOLATE === "0" || env.OPENCLAW_TEST_NO_ISOLATE === "false"; +} + export function createScopedVitestConfig( include: string[], options?: { exclude?: string[]; pool?: "threads" | "forks" }, @@ -14,6 +24,7 @@ export function createScopedVitestConfig( ...base, test: { ...baseTest, + isolate: resolveVitestIsolation(), include, exclude, ...(options?.pool ? { pool: options.pool } : {}), diff --git a/vitest.unit.config.ts b/vitest.unit.config.ts index 31b2379a172..74c654f75c9 100644 --- a/vitest.unit.config.ts +++ b/vitest.unit.config.ts @@ -1,6 +1,7 @@ import fs from "node:fs"; import { defineConfig } from "vitest/config"; import baseConfig from "./vitest.config.ts"; +import { resolveVitestIsolation } from "./vitest.scoped-config.ts"; import { unitTestAdditionalExcludePatterns, unitTestIncludePatterns, @@ -41,6 +42,7 @@ export default defineConfig({ ...base, test: { ...baseTest, + isolate: resolveVitestIsolation(), runner: "./test/non-isolated-runner.ts", include: loadIncludePatternsFromEnv() ?? unitTestIncludePatterns, exclude: [