diff --git a/scripts/verify/advertised-schemas/tools/capture_electron_scenario.json b/scripts/verify/advertised-schemas/tools/capture_electron_scenario.json index c0874ac63e..31bda6287d 100644 --- a/scripts/verify/advertised-schemas/tools/capture_electron_scenario.json +++ b/scripts/verify/advertised-schemas/tools/capture_electron_scenario.json @@ -1,6 +1,6 @@ { "schemas": { - "input compact": "1966487f98e87f51", + "input compact": "88ba9b1c0d33d10f", "output compact": "4bda7c3651bfc579" }, "patterns": { diff --git a/src/domain/analysisResourceLimits.ts b/src/domain/analysisResourceLimits.ts index 3c4db8f799..5eac06b621 100644 --- a/src/domain/analysisResourceLimits.ts +++ b/src/domain/analysisResourceLimits.ts @@ -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) diff --git a/src/domain/javascript/electronActiveObservation.ts b/src/domain/javascript/electronActiveObservation.ts index 82bf312ab0..3522e9874c 100644 --- a/src/domain/javascript/electronActiveObservation.ts +++ b/src/domain/javascript/electronActiveObservation.ts @@ -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({ diff --git a/tests/boundary/mcp/electronMcp.test.ts b/tests/boundary/mcp/electronMcp.test.ts index a5ba91b9c4..f8b6c15b7f 100644 --- a/tests/boundary/mcp/electronMcp.test.ts +++ b/tests/boundary/mcp/electronMcp.test.ts @@ -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 () => {