fix(electron): refuse a wait longer than Node can schedule (#11606)

An Electron scenario wait accepted any non-negative duration_ms, and
Playwright's waitForTimeout schedules a delay above 2147483647 ms as 1 ms,
so a very long wait returned at once. Bound it at admission with the shared
Node timer maximum, as the browser scenario wait already does.

Refs #11601
This commit is contained in:
morluto authored and GitHub committed 2026-11-16 08:48:38 +08:00
1 parent a80a47f143
commit 2910fc0b13
4 files changed
+44 -6

No files matched your search

@@ -1,6 +1,6 @@
{
"schemas": {
"input compact": "1966487f98e87f51",
"input compact": "88ba9b1c0d33d10f",
"output compact": "4bda7c3651bfc579"
},
"patterns": {
+4 -4
View File
@@ -79,10 +79,6 @@ export const MINIMUM_HOPPER_CALLER_SCAN_BUDGET_MS = 1;
*/
export const MAX_NODE_TIMER_DELAY_MS = 2_147_483_647;
/**
* A positive whole-millisecond duration Node can schedule exactly. Zero and
* negative values are not a deadline.
*/
/**
* The per-call control of a caller-selectable millisecond deadline, named by
* its contract field; each adapter names the option that sets it.
@@ -102,6 +98,10 @@ export const deadlineParameterLimit = (
applies_at: "next_call",
});
/**
* A positive whole-millisecond duration Node can schedule exactly. Zero and
* negative values are not a deadline.
*/
export const timerDurationMsSchema = z
.int()
.min(1)
@@ -1,4 +1,5 @@
import { z } from "zod";
import { MAX_NODE_TIMER_DELAY_MS } from "../analysisResourceLimits.js";
import { absoluteLocalPathStringSchema } from "../localPath.js";
const absolutePathSchema = z
@@ -37,7 +38,13 @@ const actionSchema = z.discriminatedUnion("kind", [
z.strictObject({
step_id: z.string().min(1),
kind: z.literal("wait"),
duration_ms: z.int().min(0),
duration_ms: z
.int()
.min(0)
.max(MAX_NODE_TIMER_DELAY_MS)
.describe(
`Wait this many milliseconds, from 0 to ${String(MAX_NODE_TIMER_DELAY_MS)}; the wait ends early on cancellation.`,
),
window_index: windowIndexSchema.optional(),
}),
z.strictObject({
+31
View File
@@ -838,6 +838,37 @@ it("reports every unresolved Electron path without starting a provider", async (
await client.ping();
});
it("refuses an Electron wait longer than Node can schedule", async () => {
const capture = vi.fn();
const client = await activePathAdmissionClient(capture);
// Playwright's waitForTimeout(2 ** 31) returns after 1 ms.
const result = await client.callTool({
name: "capture_electron_scenario",
arguments: {
executable_path: process.execPath,
application_path: process.execPath,
actions: [{ step_id: "settle", kind: "wait", duration_ms: 2 ** 31 }],
},
});
expect(result.isError).toBe(true);
expect(parseMcpToolError(result)).toMatchObject({
error: {
code: "invalid_request",
details: {
issues: expect.arrayContaining([
expect.objectContaining({
path: ["actions", 0, "duration_ms"],
reason: "out_of_range",
maximum: 2_147_483_647,
}),
]),
},
},
});
expect(capture).not.toHaveBeenCalled();
await client.ping();
});
it.skipIf(process.platform === "win32")(
"refuses obstructed Electron selections and admits native symlink traversal through MCP",
async () => {