Skip to content

Commit 3b14a93

Browse files
authored
test(mcp): isolate catalog size checks from wall-clock load (#118871)
1 parent cd42cb7 commit 3b14a93

1 file changed

Lines changed: 23 additions & 17 deletions

File tree

‎src/node-host/mcp.test.ts‎

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { expectDefined } from "@openclaw/normalization-core";
55
import { MAX_TIMER_TIMEOUT_MS } from "@openclaw/normalization-core/number-coercion";
66
import { describe, expect, it, vi } from "vitest";
77
import { OpenClawSchema } from "../config/zod-schema.js";
8+
import { useFrozenTime, useRealTime } from "../test-utils/frozen-time.js";
89
import { startNodeHostMcpManager } from "./mcp.js";
910

1011
function tool(name: string, description?: string): Tool {
@@ -64,6 +65,18 @@ async function startManagerWithTools(listed: ReadonlyArray<{ serverName: string;
6465
);
6566
}
6667

68+
function itWithFrozenClock(name: string, run: () => Promise<void>): void {
69+
it(name, async () => {
70+
// Size and pagination proofs must not spend the separately tested catalog deadline.
71+
useFrozenTime(1_000);
72+
try {
73+
await run();
74+
} finally {
75+
useRealTime();
76+
}
77+
});
78+
}
79+
6780
describe("node host MCP manager", () => {
6881
it("counts only enabled servers with valid identifiers", async () => {
6982
const manager = await startNodeHostMcpManager(
@@ -193,7 +206,7 @@ describe("node host MCP manager", () => {
193206
await untrusted.close();
194207
});
195208

196-
it("bounds untrusted descriptor count and schema bytes", async () => {
209+
itWithFrozenClock("bounds untrusted descriptor count and schema bytes", async () => {
197210
const tools = Array.from({ length: 130 }, (_, index) =>
198211
tool(`tool-${String(index).padStart(3, "0")}`),
199212
);
@@ -213,7 +226,7 @@ describe("node host MCP manager", () => {
213226
await manager.close();
214227
});
215228

216-
it("keeps global descriptor ordering across catalog pages", async () => {
229+
itWithFrozenClock("keeps global descriptor ordering across catalog pages", async () => {
217230
const firstPage = Array.from({ length: 128 }, (_, index) =>
218231
tool(`z-${String(index).padStart(3, "0")}`),
219232
);
@@ -291,7 +304,7 @@ describe("node host MCP manager", () => {
291304
expect(healthy.close).toHaveBeenCalledOnce();
292305
});
293306

294-
it("isolates endless unique-cursor pagination at the page ceiling", async () => {
307+
itWithFrozenClock("isolates endless unique-cursor pagination at the page ceiling", async () => {
295308
let page = 0;
296309
const endless = createClient({
297310
list: async () => {
@@ -305,9 +318,7 @@ describe("node host MCP manager", () => {
305318
{ endless: { command: "endless" }, healthy: { command: "healthy" } },
306319
{
307320
createClient: (serverName) => (serverName === "endless" ? endless : healthy),
308-
// Prove the page ceiling without loaded CI accidentally hitting the
309-
// catalog deadline; timeout behavior has its own dedicated coverage.
310-
resolveTransport: () => ({ ...transport, requestTimeoutMs: 1_000 }),
321+
resolveTransport: () => transport,
311322
warn,
312323
},
313324
);
@@ -367,12 +378,9 @@ describe("node host MCP manager", () => {
367378
}
368379
});
369380

370-
it("isolates an oversized multi-page catalog at the accumulated byte ceiling", async () => {
371-
// Large-page byte counting must not spend this unrelated wall-clock deadline;
372-
// the preceding case separately proves strict catalog timeout enforcement.
373-
vi.useFakeTimers();
374-
vi.setSystemTime(1_000);
375-
try {
381+
itWithFrozenClock(
382+
"isolates an oversized multi-page catalog at the accumulated byte ceiling",
383+
async () => {
376384
const largeTool = {
377385
...tool("large"),
378386
inputSchema: { type: "object" as const, description: "x".repeat(6 * 1024 * 1024) },
@@ -399,12 +407,10 @@ describe("node host MCP manager", () => {
399407
expect(manager.descriptors.map((descriptor) => descriptor.name)).toEqual(["healthy_search"]);
400408

401409
await manager.close();
402-
} finally {
403-
vi.useRealTimers();
404-
}
405-
});
410+
},
411+
);
406412

407-
it("isolates a listing that exceeds the retained candidate ceiling", async () => {
413+
itWithFrozenClock("isolates a listing that exceeds the retained candidate ceiling", async () => {
408414
const overflowing = createClient({
409415
tools: Array.from({ length: 16_385 }, (_, index) => tool(`tool-${index}`)),
410416
});

0 commit comments

Comments
 (0)