test: guard first-catalog, child CDP and queue regressions at the test deadline (#11675)

Three remaining wall-clock bounds become hang guards at the test's own
deadline, each with an observable outcome asserted:

- MCP startup: the pending initialize and tools/list phases get the largest
  budget Node can schedule, so only the first-catalog budget can end the
  wait before the test deadline. The elapsed bounds are deleted.
- Playwright storage child CDP reply: the elapsed bound is deleted. A
  missing command deadline leaves settle pending until the test deadline,
  and the asserted message names the value that was applied.
- Environment create explanation: the body has 1,000,000 values, so a
  quadratic queue walk runs past the test deadline (about 65 s). The
  linear walk takes under 200 ms. The elapsed bound is deleted.

Refs #10513
This commit is contained in:
morluto authored and GitHub committed 2026-11-15 21:51:05 -05:00
1 parent bdb3e67c62
commit d4c2be509e
3 files changed
+14 -22

No files matched your search

@@ -552,6 +552,8 @@ it("cancels a pending storage-key reply and still releases its CDP owner", async
expect(cdp.detachCalls).toBe(1);
});
// The child reply never arrives, so a missing command deadline leaves settle
// pending until the test's deadline; the message names the value applied.
it("bounds a stalled child CDP reply by command_timeout_ms", async () => {
const cdp = new FakeCdp();
const { page, contextApi } = fixture(cdp);
@@ -559,7 +561,6 @@ it("bounds a stalled child CDP reply by command_timeout_ms", async () => {
...scenario(),
command_timeout_ms: 40,
});
const started = performance.now();
const owner = await createInitializedStorage(contextApi, page, input);
expect(owner).toBeDefined();
cdp.emit("Target.attachedToTarget", {
@@ -577,7 +578,6 @@ it("bounds a stalled child CDP reply by command_timeout_ms", async () => {
"Set command_timeout_ms in the capture-browser-scenario JSON above 40",
),
});
expect(performance.now() - started).toBeLessThan(4_000);
await owner?.close();
});
@@ -994,13 +994,13 @@ it("explains many copied and slugged fields of a wide body without searching it
});
it("searches a wide request body for a copied value in linear time", () => {
// Shifting each value off the queue made one fruitless search over 500,000 zeros take about a minute.
const wide = Array.from({ length: 500_000 }, () => 0);
const started = performance.now();
// Shifting each value off the queue makes the search quadratic: about 18 s
// for 500,000 zeros and about a minute for this body, past the test's
// deadline, which is the guard. The linear walk takes well under a second.
const wide = Array.from({ length: 1_000_000 }, () => 0);
const result = explainCreate(
created({ id: 1, note: "not anywhere in the body" }, { items: wide }),
);
expect(performance.now() - started).toBeLessThan(5_000);
expect(ruleFor(result.rules, "note")).toBeUndefined();
});
+8 -16
View File
@@ -4,6 +4,7 @@ import { readFile } from "node:fs/promises";
import { join, resolve } from "node:path";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
import { MAX_NODE_TIMER_DELAY_MS } from "../../../src/domain/analysisResourceLimits.js";
import {
createEsmModuleProfileCollector,
@@ -257,15 +258,15 @@ describe("packaged MCP startup probe failures", () => {
});
});
// The pending phase's own budget is the largest Node can schedule, longer
// than any test deadline, so only the first-catalog budget can end the wait
// before the test's deadline does.
describe("packaged MCP first-catalog budget while a phase is pending", () => {
it("stops a pending initialize at the shorter first-catalog budget", async () => {
const firstCatalogMs = 250;
const initializeMs = 8_000;
const policy = probePolicy({
initializeBudgetMs: initializeMs,
firstCatalogBudgetMs: firstCatalogMs,
initializeBudgetMs: MAX_NODE_TIMER_DELAY_MS,
firstCatalogBudgetMs: 250,
});
const started = performance.now();
let caught: unknown;
try {
await measureMcpStartup({
@@ -281,21 +282,15 @@ describe("packaged MCP first-catalog budget while a phase is pending", () => {
const message = errorMessage(caught);
expectPhaseText(message, policy.firstCatalog);
expect(message).not.toContain("REA_MCP_INITIALIZE_BUDGET_MS");
// The phase request names the first-catalog budget once it is the shorter
// bound, so only elapsed time shows the stop beat the phase's own deadline.
expect(performance.now() - started).toBeLessThan(initializeMs);
});
it("stops a pending tools/list at the remaining first-catalog budget", async () => {
const firstCatalogMs = 800;
const toolsListMs = 8_000;
const root = await createTestTempDirectory("rea-mcp-startup-");
const initializedPath = join(root, "initialized");
const policy = probePolicy({
toolsListBudgetMs: toolsListMs,
firstCatalogBudgetMs: firstCatalogMs,
toolsListBudgetMs: MAX_NODE_TIMER_DELAY_MS,
firstCatalogBudgetMs: 800,
});
const started = performance.now();
let caught: unknown;
try {
await measureMcpStartup({
@@ -315,9 +310,6 @@ describe("packaged MCP first-catalog budget while a phase is pending", () => {
const message = errorMessage(caught);
expectPhaseText(message, policy.firstCatalog);
expect(message).not.toContain("REA_MCP_TOOLS_LIST_BUDGET_MS");
// The phase request names the first-catalog budget once it is the shorter
// bound, so only elapsed time shows the stop beat the phase's own deadline.
expect(performance.now() - started).toBeLessThan(toolsListMs);
expect(await readFile(initializedPath, "utf8")).toBe("ready");
});