Skip to content

Commit aa52eba

Browse files
authored
fix(test): serialize default e2e runner (#122203)
* fix(test): serialize default e2e runner * docs(test): document serial e2e default
1 parent ce466fc commit aa52eba

4 files changed

Lines changed: 52 additions & 39 deletions

File tree

‎docs/help/testing.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -781,10 +781,10 @@ Native dependency policy:
781781
- Files: `src/**/*.e2e.test.ts`, `test/**/*.e2e.test.ts`, and bundled-plugin E2E tests under `extensions/`
782782
- Runtime defaults:
783783
- Uses Vitest `threads` with `isolate: false`, matching the rest of the repo.
784-
- Uses adaptive workers (CI: up to 2, local: 1 by default).
784+
- Uses one worker by default to keep non-isolated gateway state deterministic.
785785
- Runs in silent mode by default to reduce console I/O overhead.
786786
- Useful overrides:
787-
- `OPENCLAW_E2E_WORKERS=<n>` to force worker count (capped at 16).
787+
- `OPENCLAW_E2E_WORKERS=<n>` to opt into parallel workers (capped at 16).
788788
- `OPENCLAW_E2E_VERBOSE=1` to re-enable verbose console output.
789789
- Scope:
790790
- Multi-instance gateway end-to-end behavior

‎docs/reference/test.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ Test wrapper runs end with a short `[test] passed|failed|skipped ... in ...` sum
113113

114114
- Gateway tests are included in the untargeted `pnpm test` full suite; run them alone with `pnpm test:gateway`.
115115
- `pnpm test:e2e`: repo E2E aggregate = `pnpm test:e2e:gateway && pnpm test:ui:e2e`.
116-
- `pnpm test:e2e:gateway`: gateway end-to-end smoke tests (multi-instance WS/HTTP/node pairing). Defaults to `threads` + `isolate: false` with adaptive workers in `vitest.e2e.config.ts`; tune with `OPENCLAW_E2E_WORKERS=<n>`, verbose logs with `OPENCLAW_E2E_VERBOSE=1`.
116+
- `pnpm test:e2e:gateway`: gateway end-to-end smoke tests (multi-instance WS/HTTP/node pairing). Defaults to `threads` + `isolate: false` with one worker in `vitest.e2e.config.ts`; opt into parallelism with `OPENCLAW_E2E_WORKERS=<n>` (capped at 16), and enable verbose logs with `OPENCLAW_E2E_VERBOSE=1`.
117117
- `pnpm test:live`: provider live tests (Claude/Minimax/DeepSeek/z.ai/etc, gated by `*.live.test.ts`). Requires API keys and `LIVE=1` (or `OPENCLAW_LIVE_TEST=1`) to unskip; verbose output with `OPENCLAW_LIVE_TEST_QUIET=0`.
118118

119119
## Full Docker suite (`pnpm test:docker:all`)

‎src/infra/vitest-e2e-config.test.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
normalizeConfigPaths,
66
} from "../../test/helpers/vitest-config-paths.js";
77
import { BUNDLED_PLUGIN_E2E_TEST_GLOB } from "../../test/vitest/vitest.bundled-plugin-paths.ts";
8-
import e2eConfig from "../../test/vitest/vitest.e2e.config.ts";
8+
import e2eConfig, { createE2EVitestConfig } from "../../test/vitest/vitest.e2e.config.ts";
99

1010
describe("e2e vitest config", () => {
1111
it("runs as a standalone config instead of inheriting unit projects", () => {
@@ -32,4 +32,12 @@ describe("e2e vitest config", () => {
3232
"test/setup-openclaw-runtime.ts",
3333
]);
3434
});
35+
36+
it("serializes default e2e runs while preserving explicit worker overrides", () => {
37+
expect(createE2EVitestConfig({}).test?.maxWorkers).toBe(1);
38+
expect(createE2EVitestConfig({ OPENCLAW_E2E_WORKERS: "4" }).test?.maxWorkers).toBe(4);
39+
expect(createE2EVitestConfig({ OPENCLAW_E2E_WORKERS: "99" }).test?.maxWorkers).toBe(16);
40+
expect(createE2EVitestConfig({ OPENCLAW_E2E_WORKERS: "0" }).test?.maxWorkers).toBe(1);
41+
expect(createE2EVitestConfig({ OPENCLAW_E2E_WORKERS: "invalid" }).test?.maxWorkers).toBe(1);
42+
});
3543
});

‎test/vitest/vitest.e2e.config.ts‎

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
11
// Vitest e2e config wires the e2e test shard.
2-
import os from "node:os";
32
import { defineConfig } from "vitest/config";
43
import { BUNDLED_PLUGIN_E2E_TEST_GLOB } from "./vitest.bundled-plugin-paths.ts";
54
import baseConfig from "./vitest.config.ts";
65
import { resolveRepoRootPath } from "./vitest.shared.config.ts";
76

8-
const base = baseConfig as unknown as Record<string, unknown>;
9-
const isCI = process.env.CI === "true" || process.env.GITHUB_ACTIONS === "true";
10-
const cpuCount = os.cpus().length;
11-
// Keep e2e runs cheap by default; callers can still override via OPENCLAW_E2E_WORKERS.
12-
const defaultWorkers = isCI ? Math.min(2, Math.max(1, Math.floor(cpuCount * 0.25))) : 1;
13-
const requestedWorkers = Number.parseInt(process.env.OPENCLAW_E2E_WORKERS ?? "", 10);
14-
const e2eWorkers =
15-
Number.isFinite(requestedWorkers) && requestedWorkers > 0
7+
function resolveE2EWorkerCount(env: Record<string, string | undefined>): number {
8+
const requestedWorkers = Number.parseInt(env.OPENCLAW_E2E_WORKERS ?? "", 10);
9+
return Number.isFinite(requestedWorkers) && requestedWorkers > 0
1610
? Math.min(16, requestedWorkers)
17-
: defaultWorkers;
18-
const verboseE2E = process.env.OPENCLAW_E2E_VERBOSE === "1";
11+
: 1;
12+
}
1913

14+
const base = baseConfig as unknown as Record<string, unknown>;
2015
const baseTestWithProjects =
2116
(baseConfig as { test?: { exclude?: string[]; projects?: string[]; setupFiles?: string[] } })
2217
.test ?? {};
@@ -33,27 +28,37 @@ const exclude = [
3328
...tuiPtyExcludes,
3429
];
3530

36-
export default defineConfig({
37-
...base,
38-
test: {
39-
...baseTest,
40-
maxWorkers: e2eWorkers,
41-
silent: !verboseE2E,
42-
globalSetup: [resolveRepoRootPath("test/vitest/vitest.e2e.global-setup.ts")],
43-
setupFiles: [
44-
...new Set(
45-
[...(baseTest.setupFiles ?? []), "test/setup-openclaw-runtime.ts"].map(resolveRepoRootPath),
46-
),
47-
],
48-
include: [
49-
"test/**/*.e2e.test.ts",
50-
"src/**/*.e2e.test.ts",
51-
"packages/**/*.e2e.test.ts",
52-
"src/gateway/gateway.test.ts",
53-
"src/gateway/server.startup-matrix-migration.integration.test.ts",
54-
"src/gateway/sessions-history-http.test.ts",
55-
BUNDLED_PLUGIN_E2E_TEST_GLOB,
56-
],
57-
exclude,
58-
},
59-
});
31+
export function createE2EVitestConfig(env: Record<string, string | undefined> = process.env) {
32+
// Keep e2e runs deterministic by default; callers can still opt into parallelism.
33+
const e2eWorkers = resolveE2EWorkerCount(env);
34+
const verboseE2E = env.OPENCLAW_E2E_VERBOSE === "1";
35+
36+
return defineConfig({
37+
...base,
38+
test: {
39+
...baseTest,
40+
maxWorkers: e2eWorkers,
41+
silent: !verboseE2E,
42+
globalSetup: [resolveRepoRootPath("test/vitest/vitest.e2e.global-setup.ts")],
43+
setupFiles: [
44+
...new Set(
45+
[...(baseTest.setupFiles ?? []), "test/setup-openclaw-runtime.ts"].map(
46+
resolveRepoRootPath,
47+
),
48+
),
49+
],
50+
include: [
51+
"test/**/*.e2e.test.ts",
52+
"src/**/*.e2e.test.ts",
53+
"packages/**/*.e2e.test.ts",
54+
"src/gateway/gateway.test.ts",
55+
"src/gateway/server.startup-matrix-migration.integration.test.ts",
56+
"src/gateway/sessions-history-http.test.ts",
57+
BUNDLED_PLUGIN_E2E_TEST_GLOB,
58+
],
59+
exclude,
60+
},
61+
});
62+
}
63+
64+
export default createE2EVitestConfig();

0 commit comments

Comments
 (0)