fix(test): restore thread-first vitest defaults

This commit is contained in:
Vincent Koc
2026-04-05 12:36:59 +01:00
parent b9d26fd1a4
commit 5f6ba749ff
10 changed files with 58 additions and 45 deletions

View File

@@ -12,11 +12,11 @@ describe("loadBoundaryIncludePatternsFromEnv", () => {
});
describe("boundary vitest config", () => {
it("keeps boundary suites isolated with shared test bootstrap", () => {
it("keeps boundary suites on the shared runner with shared test bootstrap", () => {
const config = createBoundaryVitestConfig({});
expect(config.test?.isolate).toBe(true);
expect(config.test?.runner).toBeUndefined();
expect(config.test?.isolate).toBe(false);
expect(config.test?.runner).toBe("./test/non-isolated-runner.ts");
expect(config.test?.include).toEqual(boundaryTestFiles);
expect(config.test?.setupFiles).toEqual(["test/setup.ts"]);
});

View File

@@ -13,38 +13,38 @@ describe("projects vitest config", () => {
expect(baseConfig.test?.projects).toEqual([...rootVitestProjects]);
});
it("keeps every root project on fork workers", () => {
it("keeps the heavy root projects on fork workers only where explicitly required", () => {
expect(createGatewayVitestConfig().test.pool).toBe("forks");
expect(createAgentsVitestConfig().test.pool).toBe("forks");
expect(createCommandsVitestConfig().test.pool).toBe("forks");
expect(createContractsVitestConfig().test.pool).toBe("forks");
expect(createContractsVitestConfig().test.pool).toBe("threads");
});
it("keeps the contracts lane isolated by default", () => {
it("keeps the contracts lane on the shared non-isolated runner", () => {
const config = createContractsVitestConfig();
expect(config.test.isolate).toBe(true);
expect(config.test.runner).toBeUndefined();
expect(config.test.isolate).toBe(false);
expect(config.test.runner).toBe("./test/non-isolated-runner.ts");
});
it("keeps the root ui lane aligned with the isolated jsdom setup", () => {
it("keeps the root ui lane aligned with the shared non-isolated jsdom setup", () => {
const config = createUiVitestConfig();
expect(config.test.environment).toBe("jsdom");
expect(config.test.isolate).toBe(true);
expect(config.test.runner).toBeUndefined();
expect(config.test.isolate).toBe(false);
expect(config.test.runner).toBe("./test/non-isolated-runner.ts");
expect(config.test.setupFiles).not.toContain("test/setup-openclaw-runtime.ts");
expect(config.test.setupFiles).toContain("ui/src/test-helpers/lit-warnings.setup.ts");
expect(config.test.deps?.optimizer?.web?.enabled).toBe(true);
});
it("keeps the unit lane isolated by default", () => {
it("keeps the unit lane on the shared non-isolated runner", () => {
const config = createUnitVitestConfig();
expect(config.test.isolate).toBe(true);
expect(config.test.runner).toBeUndefined();
expect(config.test.isolate).toBe(false);
expect(config.test.runner).toBe("./test/non-isolated-runner.ts");
});
it("keeps the bundled lane isolated on fork workers", () => {
expect(bundledConfig.test?.pool).toBe("forks");
expect(bundledConfig.test?.isolate).toBe(true);
expect(bundledConfig.test?.runner).toBeUndefined();
it("keeps the bundled lane on the shared non-isolated runner", () => {
expect(bundledConfig.test?.pool).toBe("threads");
expect(bundledConfig.test?.isolate).toBe(false);
expect(bundledConfig.test?.runner).toBe("./test/non-isolated-runner.ts");
});
});

View File

@@ -51,22 +51,22 @@ import { BUNDLED_PLUGIN_TEST_GLOB, bundledPluginFile } from "./helpers/bundled-p
const EXTENSIONS_CHANNEL_GLOB = ["extensions", "channel", "**"].join("/");
describe("resolveVitestIsolation", () => {
it("defaults shared scoped configs to isolated workers", () => {
expect(resolveVitestIsolation({})).toBe(true);
it("defaults shared scoped configs to non-isolated workers", () => {
expect(resolveVitestIsolation({})).toBe(false);
});
it("ignores the legacy isolation escape hatches", () => {
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);
expect(resolveVitestIsolation({ OPENCLAW_TEST_ISOLATE: "1" })).toBe(false);
expect(resolveVitestIsolation({ OPENCLAW_TEST_NO_ISOLATE: "0" })).toBe(false);
expect(resolveVitestIsolation({ OPENCLAW_TEST_NO_ISOLATE: "false" })).toBe(false);
});
});
describe("createScopedVitestConfig", () => {
it("applies isolated mode by default", () => {
it("applies non-isolated mode by default", () => {
const config = createScopedVitestConfig(["src/example.test.ts"], { env: {} });
expect(config.test?.isolate).toBe(true);
expect(config.test?.runner).toBeUndefined();
expect(config.test?.isolate).toBe(false);
expect(config.test?.runner).toBe("./test/non-isolated-runner.ts");
expect(config.test?.setupFiles).toEqual(["test/setup.ts", "test/setup-openclaw-runtime.ts"]);
});
@@ -160,30 +160,35 @@ describe("scoped vitest configs", () => {
const defaultUtilsConfig = createUtilsVitestConfig({});
const defaultWizardConfig = createWizardVitestConfig({});
it("keeps every scoped lane on fork workers with isolation enabled", () => {
it("keeps most scoped lanes on thread workers with the non-isolated runner", () => {
for (const config of [
defaultChannelsConfig,
defaultAcpConfig,
defaultExtensionsConfig,
defaultExtensionChannelsConfig,
defaultExtensionProvidersConfig,
defaultGatewayConfig,
defaultInfraConfig,
defaultCommandsConfig,
defaultAutoReplyConfig,
defaultAgentsConfig,
defaultToolingConfig,
defaultUiConfig,
]) {
expect(config.test?.pool).toBe("forks");
expect(config.test?.isolate).toBe(true);
expect(config.test?.runner).toBeUndefined();
expect(config.test?.pool).toBe("threads");
expect(config.test?.isolate).toBe(false);
expect(config.test?.runner).toBe("./test/non-isolated-runner.ts");
}
});
it("defaults channel tests to isolated fork mode", () => {
expect(defaultChannelsConfig.test?.isolate).toBe(true);
expect(defaultChannelsConfig.test?.pool).toBe("forks");
it("keeps gateway, commands, and agents on fork workers", () => {
for (const config of [defaultGatewayConfig, defaultCommandsConfig, defaultAgentsConfig]) {
expect(config.test?.pool).toBe("forks");
expect(config.test?.isolate).toBe(false);
expect(config.test?.runner).toBe("./test/non-isolated-runner.ts");
}
});
it("defaults channel tests to non-isolated thread mode", () => {
expect(defaultChannelsConfig.test?.isolate).toBe(false);
expect(defaultChannelsConfig.test?.pool).toBe("threads");
});
it("keeps the core channel lane limited to non-extension roots", () => {
@@ -217,9 +222,9 @@ describe("scoped vitest configs", () => {
}
});
it("defaults extension tests to isolated fork mode", () => {
expect(defaultExtensionsConfig.test?.isolate).toBe(true);
expect(defaultExtensionsConfig.test?.pool).toBe("forks");
it("defaults extension tests to non-isolated thread mode", () => {
expect(defaultExtensionsConfig.test?.isolate).toBe(false);
expect(defaultExtensionsConfig.test?.pool).toBe("threads");
});
it("normalizes extension channel include patterns relative to the scoped dir", () => {

View File

@@ -68,10 +68,10 @@ describe("loadExtraExcludePatternsFromEnv", () => {
});
describe("unit vitest config", () => {
it("defaults unit tests to isolated mode", () => {
it("defaults unit tests to non-isolated mode", () => {
const unitConfig = createUnitVitestConfig({});
expect(unitConfig.test?.isolate).toBe(true);
expect(unitConfig.test?.runner).toBeUndefined();
expect(unitConfig.test?.isolate).toBe(false);
expect(unitConfig.test?.runner).toBe("./test/non-isolated-runner.ts");
});
it("keeps acp and ui tests out of the generic unit lane", () => {

View File

@@ -5,6 +5,7 @@ export function createAgentsVitestConfig(env?: Record<string, string | undefined
dir: "src/agents",
env,
name: "agents",
pool: "forks",
});
}

View File

@@ -19,8 +19,12 @@ export function createBoundaryVitestConfig(
test: {
...sharedVitestConfig.test,
name: "boundary",
isolate: false,
runner: "./test/non-isolated-runner.ts",
include: loadBoundaryIncludePatternsFromEnv(env) ?? cliIncludePatterns ?? boundaryTestFiles,
...(cliIncludePatterns !== null ? { passWithNoTests: true } : {}),
// Boundary workers still need the shared isolated HOME/bootstrap. Only
// per-file module isolation is disabled here.
setupFiles: sharedVitestConfig.test.setupFiles,
},
});

View File

@@ -5,6 +5,7 @@ export function createCommandsVitestConfig(env?: Record<string, string | undefin
dir: "src/commands",
env,
name: "commands",
pool: "forks",
});
}

View File

@@ -5,6 +5,7 @@ export function createGatewayVitestConfig(env?: Record<string, string | undefine
dir: "src/gateway",
env,
name: "gateway",
pool: "forks",
});
}

View File

@@ -31,7 +31,7 @@ function relativizeScopedPatterns(values: string[], dir?: string): string[] {
export function resolveVitestIsolation(
_env: Record<string, string | undefined> = process.env,
): boolean {
return true;
return false;
}
export function createScopedVitestConfig(

View File

@@ -167,7 +167,7 @@ export function resolveLocalVitestScheduling(
export function resolveDefaultVitestPool(
_env: Record<string, string | undefined> = process.env,
): OpenClawVitestPool {
return "forks";
return "threads";
}
const repoRoot = path.dirname(fileURLToPath(import.meta.url));
@@ -211,8 +211,9 @@ export const sharedVitestConfig = {
hookTimeout: isWindows ? 180_000 : 120_000,
unstubEnvs: true,
unstubGlobals: true,
isolate: true,
isolate: false,
pool: defaultPool,
runner: "./test/non-isolated-runner.ts",
maxWorkers: isCI ? ciWorkers : localScheduling.maxWorkers,
fileParallelism: isCI ? true : localScheduling.fileParallelism,
forceRerunTriggers: [