Skip to content

Commit 49cd600

Browse files
committed
test(gateway): give module-mocking Gateway tests a private module graph
`server.sessions.compaction-read-errors` mocks `config/sessions/session-accessor.sqlite-read.js`, but production reaches `loadTranscriptEvents` through re-exports: `server-methods/sessions-compact.ts` imports it from the `session-accessor.js` barrel and `preflightSessionTranscriptForManualCompact` imports it from the leaf. The `gateway-server` project is `isolate: false`, so when a neighbour has already evaluated those importers they stay bound to the real implementation and the mock never fires -- the injected read error simply does not happen and all three tests fail with `expected true to be false`, reading like a product regression. Trigger: 3374458 added `server.chat-metadata-boundary.test.ts`, which boots a full non-minimal Gateway in `beforeAll` and lands immediately before this file in the shard. Main has gone red on it repeatedly since (32338154086, 32339521003, 32339928383, 32341300955, 32341946296); e294c15 fixed only the sibling symptom where the factory had not run yet. Route the file to a new `gateway-server-isolated` project instead, mirroring `unit-fast-isolated` -- whose comment describes this exact hazard. A fresh graph per file makes both symptoms structurally impossible rather than order-dependent. The list is explicit so the reason travels with the file. Not reproducible on macOS: the exact 24-file stripe in CI's own order, and the triggering pair three times, are green locally every time.
1 parent a6a8f74 commit 49cd600

8 files changed

Lines changed: 72 additions & 9 deletions

‎scripts/lib/ci-node-test-plan.mts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
import { commandsLightTestFiles } from "../../test/vitest/vitest.commands-light-paths.mjs";
88
import {
99
gatewayServerExcludedTestFiles,
10+
gatewayServerIsolatedTestFiles,
1011
isGatewayServerBackedHttpTestFile,
1112
isGatewayServerTestFile,
1213
} from "../../test/vitest/vitest.gateway-server-paths.mjs";
@@ -264,6 +265,8 @@ const COMPACT_GROUP_SECONDS_HINTS = new Map<string, number>([
264265
["agentic-gateway-core-1", 99],
265266
["agentic-gateway-core-2", 99],
266267
["agentic-gateway-core-3", 99],
268+
// One small file that pays a full cold module graph because it runs isolated.
269+
["agentic-gateway-server-isolated", 30],
267270
["agentic-gateway-methods", 157],
268271
["agentic-plugin-sdk", 45],
269272
["auto-reply-core-top-level", 27],
@@ -1637,7 +1640,10 @@ function createCoreRuntimeMediaUiSplitShards(): NodeTestSplitShard[] {
16371640

16381641
function createAgenticGatewayCoreSplitShards(): NodeTestSplitShard[] {
16391642
const unitFastFiles = new Set(getUnitFastTestFiles());
1640-
const excludedGatewayFiles = new Set(gatewayServerExcludedTestFiles);
1643+
const excludedGatewayFiles = new Set([
1644+
...gatewayServerExcludedTestFiles,
1645+
...gatewayServerIsolatedTestFiles,
1646+
]);
16411647
const gatewayFiles = listTestFiles("src/gateway").filter(
16421648
(file) =>
16431649
isStripeEligibleTestFile(file, unitFastFiles) &&
@@ -1747,6 +1753,11 @@ const SPLIT_NODE_SHARDS = new Map<string, NodeTestSplitShard[]>([
17471753
"agentic",
17481754
[
17491755
...createGatewayServerSplitShards(),
1756+
{
1757+
shardName: "agentic-gateway-server-isolated",
1758+
configs: ["test/vitest/vitest.gateway-server-isolated.config.ts"],
1759+
requiresDist: false,
1760+
},
17501761
// Split per config: the combined pair owned a ~206s hosted wall that no
17511762
// bin packing could shorten, while the halves fit normal lanes.
17521763
{

‎test/scripts/ci-node-test-plan.test.ts‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -318,27 +318,27 @@ describe("scripts/lib/ci-node-test-plan.mts", () => {
318318
name: "Blacksmith",
319319
pullRequest: pullRequestCompact,
320320
pullRequestJobs: 34,
321-
pullRequestMax: 204,
321+
pullRequestMax: 207,
322322
push: compact,
323323
pushJobs: 25,
324-
pushMax: 204,
324+
pushMax: 207,
325325
},
326326
{
327327
name: "GitHub-hosted",
328328
pullRequest: githubPullRequestCompact,
329-
pullRequestJobs: 79,
329+
pullRequestJobs: 80,
330330
pullRequestMax: 186,
331331
push: githubCompact,
332-
pushJobs: 70,
332+
pushJobs: 71,
333333
pushMax: 149,
334334
},
335335
{
336336
name: "hybrid",
337337
pullRequest: hybridPullRequestCompact,
338-
pullRequestJobs: 56,
338+
pullRequestJobs: 57,
339339
pullRequestMax: 140,
340340
push: hybridCompact,
341-
pushJobs: 48,
341+
pushJobs: 49,
342342
pushMax: 140,
343343
},
344344
]) {
@@ -355,7 +355,7 @@ describe("scripts/lib/ci-node-test-plan.mts", () => {
355355
`${profile.name} pull-request max`,
356356
).toBe(profile.pullRequestMax);
357357
}
358-
expect(hybridCompact.filter((shard) => !shard.requiresDist)).toHaveLength(47);
358+
expect(hybridCompact.filter((shard) => !shard.requiresDist)).toHaveLength(48);
359359
expect(githubCompact.length - hybridCompact.length).toBeGreaterThanOrEqual(20);
360360
expect(githubPullRequestCompact.length).toBeLessThanOrEqual(96);
361361
// Nondist expanded-profile lanes stay under the 150-second body ceiling;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Vitest gateway server isolated config wires module-mocking Gateway tests out of
2+
// the shared module cache.
3+
import { defineConfig } from "vitest/config";
4+
import { gatewayServerIsolatedTestFiles } from "./vitest.gateway-server-paths.mjs";
5+
import { loadPatternListFromEnv, narrowIncludePatternsForCli } from "./vitest.pattern-file.ts";
6+
import { resolveRepoRootPath, sharedVitestConfig } from "./vitest.shared.config.ts";
7+
8+
export function createGatewayServerIsolatedVitestConfig(
9+
env: Record<string, string | undefined> = process.env,
10+
options: { argv?: string[] } = {},
11+
) {
12+
const sharedTest = sharedVitestConfig.test ?? {};
13+
const includeFromEnv = loadPatternListFromEnv("OPENCLAW_VITEST_INCLUDE_FILE", env);
14+
const cliInclude = narrowIncludePatternsForCli(gatewayServerIsolatedTestFiles, options.argv);
15+
16+
return defineConfig({
17+
...sharedVitestConfig,
18+
test: {
19+
...sharedTest,
20+
name: "gateway-server-isolated",
21+
// These files replace a module the Gateway reaches through re-exports, so a
22+
// neighbour that already bound the real implementation would defeat the mock.
23+
isolate: true,
24+
runner: undefined,
25+
setupFiles: [resolveRepoRootPath("test/setup.env.ts")],
26+
include: includeFromEnv ?? cliInclude ?? gatewayServerIsolatedTestFiles,
27+
exclude: sharedTest.exclude ?? [],
28+
passWithNoTests: true,
29+
},
30+
});
31+
}
32+
33+
export default createGatewayServerIsolatedVitestConfig();
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export const gatewayServerBackedHttpTestFiles: string[];
22
export const gatewayServerExcludedTestFiles: string[];
3+
export const gatewayServerIsolatedTestFiles: string[];
34
export function isGatewayServerBackedHttpTestFile(file: string): boolean;
45
export function isGatewayServerTestFile(file: string): boolean;

‎test/vitest/vitest.gateway-server-paths.mjs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ export const gatewayServerBackedHttpTestFiles = [
77
"src/gateway/probe.auth.integration.test.ts",
88
];
99

10+
// Gateway server tests that replace a module the Gateway reaches only through
11+
// re-exports. `gateway-server` is `isolate: false`, so a neighbour that boots a
12+
// full Gateway leaves those importers bound to the real implementation and the
13+
// mock silently never fires. These run in `gateway-server-isolated` instead,
14+
// which gives each file a fresh module graph.
15+
export const gatewayServerIsolatedTestFiles = [
16+
"src/gateway/server.sessions.compaction-read-errors.test.ts",
17+
];
18+
1019
export const gatewayServerExcludedTestFiles = [
1120
"src/gateway/gateway.test.ts",
1221
"src/gateway/server.startup-matrix-migration.integration.test.ts",
@@ -15,6 +24,7 @@ export const gatewayServerExcludedTestFiles = [
1524

1625
const gatewayServerBackedHttpTestFileSet = new Set(gatewayServerBackedHttpTestFiles);
1726
const gatewayServerExcludedTestFileSet = new Set(gatewayServerExcludedTestFiles);
27+
const gatewayServerIsolatedTestFileSet = new Set(gatewayServerIsolatedTestFiles);
1828

1929
export function isGatewayServerBackedHttpTestFile(file) {
2030
return gatewayServerBackedHttpTestFileSet.has(file.replaceAll("\\", "/"));
@@ -24,6 +34,7 @@ export function isGatewayServerTestFile(file) {
2434
const normalized = file.replaceAll("\\", "/");
2535
if (
2636
gatewayServerExcludedTestFileSet.has(normalized) ||
37+
gatewayServerIsolatedTestFileSet.has(normalized) ||
2738
normalized.startsWith("src/gateway/server-methods/") ||
2839
normalized.endsWith(".e2e.test.ts")
2940
) {

‎test/vitest/vitest.gateway-server.config.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
gatewayServerBackedHttpTestFiles,
33
gatewayServerExcludedTestFiles,
4+
gatewayServerIsolatedTestFiles,
45
} from "./vitest.gateway-server-paths.mjs";
56
// Vitest gateway server config wires the gateway server test shard.
67
import { createScopedVitestConfig } from "./vitest.scoped-config.ts";
@@ -11,7 +12,11 @@ export function createGatewayServerVitestConfig(env?: Record<string, string | un
1112
{
1213
dir: "src/gateway",
1314
env,
14-
exclude: ["src/gateway/server-methods/**/*.test.ts", ...gatewayServerExcludedTestFiles],
15+
exclude: [
16+
"src/gateway/server-methods/**/*.test.ts",
17+
...gatewayServerExcludedTestFiles,
18+
...gatewayServerIsolatedTestFiles,
19+
],
1520
fileParallelism: false,
1621
// Gateway child projects share one include file; preserve this project's ownership.
1722
intersectIncludeFile: true,

‎test/vitest/vitest.gateway.config.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const gatewayProjectConfigs = [
77
"test/vitest/vitest.gateway-client.config.ts",
88
"test/vitest/vitest.gateway-methods.config.ts",
99
"test/vitest/vitest.gateway-server.config.ts",
10+
"test/vitest/vitest.gateway-server-isolated.config.ts",
1011
] as const;
1112

1213
export function createGatewayVitestConfig(env?: Record<string, string | undefined>) {

‎test/vitest/vitest.test-shards.mjs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ export const fullSuiteVitestShards = [
9999
"test/vitest/vitest.gateway-client.config.ts",
100100
"test/vitest/vitest.gateway-methods.config.ts",
101101
"test/vitest/vitest.gateway-server.config.ts",
102+
"test/vitest/vitest.gateway-server-isolated.config.ts",
102103
"test/vitest/vitest.cli-process.config.ts",
103104
"test/vitest/vitest.cli.config.ts",
104105
"test/vitest/vitest.commands-light.config.ts",

0 commit comments

Comments
 (0)