Skip to content

Commit d2a3269

Browse files
committed
Merge remote-tracking branch 'origin/main' into codex/audit-continuation-20261020-refresh20
2 parents fd7da77 + eac296a commit d2a3269

5 files changed

Lines changed: 169 additions & 23 deletions

File tree

‎docs/browser-scenario-contract.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ Through MCP, pass the same object as the `capture_browser_scenario` arguments.
107107
The final step's DOM and accessibility artifacts retain the page state at that
108108
capture time inline. REA still launches and cleans up the browser profile.
109109

110+
Action `timeout_ms` and `wait_for_timeout.duration_ms` accept integers from 1
111+
through 2,147,483,647 milliseconds, matching the underlying timer representation.
112+
Larger values receive an input error before browser launch. Omit `timeout_ms`
113+
to keep an action pending until completion or request cancellation.
114+
110115
The click's `timeout_ms` covers the click action. A non-navigating `fetch` or
111116
delayed render can finish later, so use `wait_for` to observe a page-specific
112117
ready condition before final capture. A page that updates synchronously can

‎src/domain/browserScenario.test.ts‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,60 @@ it("accepts caller-selected viewport sizes and click counts without ceilings", (
196196
});
197197
expect(parsed.actions[0]).toMatchObject({ click_count: 4 });
198198
});
199+
200+
it.each([
201+
{
202+
field: "duration_ms",
203+
action: { action: "wait_for_timeout", duration_ms: 2_147_483_648 },
204+
},
205+
{
206+
field: "timeout_ms",
207+
action: {
208+
action: "wait_for",
209+
locator: { kind: "css", selector: "#btn" },
210+
state: "visible",
211+
timeout_ms: 2_147_483_648,
212+
},
213+
},
214+
])("rejects $field at its precise owning field", ({ field, action }) => {
215+
const parsed = browserScenarioSchema.safeParse({
216+
browser: { mode: "launch", executable_path: "/opt/chromium" },
217+
start_url: { url: "https://app.example.test/" },
218+
actions: [{ step_id: "overflow", ...action }],
219+
});
220+
if (parsed.success)
221+
throw new Error("Expected unrepresentable timer rejection");
222+
expect(parsed.error.issues).toMatchObject([
223+
{ code: "too_big", maximum: 2_147_483_647, path: ["actions", 0, field] },
224+
]);
225+
});
226+
227+
it("preserves the largest representable timers and an omitted action deadline", () => {
228+
const parsed = browserScenarioSchema.parse({
229+
browser: { mode: "launch", executable_path: "/opt/chromium" },
230+
start_url: { url: "https://app.example.test/" },
231+
actions: [
232+
{
233+
step_id: "max-wait",
234+
action: "wait_for_timeout",
235+
duration_ms: 2_147_483_647,
236+
},
237+
{
238+
step_id: "max-deadline",
239+
action: "wait_for",
240+
locator: { kind: "css", selector: "#btn" },
241+
state: "visible",
242+
timeout_ms: 2_147_483_647,
243+
},
244+
{
245+
step_id: "unbounded",
246+
action: "wait_for",
247+
locator: { kind: "css", selector: "#btn" },
248+
state: "visible",
249+
},
250+
],
251+
});
252+
expect(parsed.actions[0]).toMatchObject({ duration_ms: 2_147_483_647 });
253+
expect(parsed.actions[1]).toMatchObject({ timeout_ms: 2_147_483_647 });
254+
expect(parsed.actions[2]).not.toHaveProperty("timeout_ms");
255+
});

‎src/domain/browserScenarioValues.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,16 @@ const locatorSchema = z.discriminatedUnion("kind", [
157157
}),
158158
]);
159159

160+
// Playwright forwards these intervals to Node timers.
161+
const MAX_BROWSER_SCENARIO_TIMEOUT_MS = 2_147_483_647;
162+
160163
const stepBase = {
161164
step_id: scenarioIdentifierSchema,
162165
timeout_ms: z
163166
.number()
164167
.int()
165168
.min(1)
169+
.max(MAX_BROWSER_SCENARIO_TIMEOUT_MS)
166170
.optional()
167171
.describe(
168172
"Optional action deadline in milliseconds; omitted means wait until completion or request cancellation.",
@@ -219,6 +223,7 @@ export const browserScenarioActionSchema = z.discriminatedUnion("action", [
219223
.number()
220224
.int()
221225
.min(1)
226+
.max(MAX_BROWSER_SCENARIO_TIMEOUT_MS)
222227
.describe(
223228
"Wait this many milliseconds; the wait ends early on cancellation.",
224229
),

‎tests/boundary/cli/filteredFailureOutput.test.ts‎

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,21 @@ const runCli = async (arguments_: readonly string[]) => {
5050
};
5151

5252
const expectMissingInputFailureText = (text: string, path: string): void => {
53+
const normalizedText = text.replace(/\s+/g, " ");
5354
for (const value of [
5455
"invalid_request",
5556
"invalid_input",
56-
"Correct the listed arguments and retry.",
57+
"Read the declared input schema or CLI usage",
58+
"trace-application-feature",
59+
"tools/list",
60+
"Correct the listed fields, then retry.",
61+
"Do not repeat the unchanged call.",
62+
"inspect_input_contract",
5763
path,
5864
"read-failed",
5965
"ENOENT",
6066
])
61-
expect(text).toContain(value);
67+
expect(normalizedText).toContain(value);
6268
};
6369

6470
it.each(["json", "toon", "yaml", "md"] as const)(
@@ -81,13 +87,22 @@ it.each(["json", "toon", "yaml", "md"] as const)(
8187
expect(result.output.failed).toBe(false);
8288
expect(result.fallback).toBe("");
8389
expect(result.output.handled).toBe(true);
84-
if (format === "json") {
85-
expect(JSON.parse(result.text)).toMatchObject({
90+
expectMissingInputFailureText(result.text, missingPath);
91+
if (format === "json" || format === "yaml") {
92+
const document =
93+
format === "json"
94+
? JSON.parse(result.text)
95+
: parseYaml(result.text);
96+
expect(document).toMatchObject({
8697
code: "invalid_request",
8798
category: "invalid_input",
8899
retryable: true,
89100
remediation: {
90-
action: "Correct the listed arguments and retry.",
101+
action: expect.stringContaining("tools/list"),
102+
},
103+
recovery: {
104+
kind: "inspect_input_contract",
105+
operation: "trace-application-feature",
91106
},
92107
details: {
93108
input_path: missingPath,
@@ -99,7 +114,7 @@ it.each(["json", "toon", "yaml", "md"] as const)(
99114
],
100115
},
101116
});
102-
} else expectMissingInputFailureText(result.text, missingPath);
117+
}
103118
} finally {
104119
process.exitCode = previousExitCode;
105120
}
@@ -127,6 +142,13 @@ it.each(["json", "toon", "yaml", "md"] as const)(
127142
code: "invalid_request",
128143
category: "invalid_input",
129144
retryable: true,
145+
remediation: {
146+
action: expect.stringContaining("tools/list"),
147+
},
148+
recovery: {
149+
kind: "inspect_input_contract",
150+
operation: "trace-application-feature",
151+
},
130152
details: {
131153
input_path: missingPath,
132154
input_reason: "read-failed",

‎tests/boundary/mcp/browserScenarioInputDiagnosticsMcp.test.ts‎

Lines changed: 74 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ import { cliTest } from "../../support/cli/cliFixture.js";
1212
const scenarios = [
1313
{
1414
name: "undeclared secret references",
15-
issuePath: ["secrets"],
16-
issueMessage: "Secret reference pw is not declared",
15+
fullSchemaValid: true,
16+
issue: {
17+
path: ["secrets"],
18+
reason: "invalid_value",
19+
message: "Secret reference pw is not declared",
20+
},
1721
actions: [
1822
{
1923
step_id: "pw",
@@ -25,18 +29,57 @@ const scenarios = [
2529
},
2630
{
2731
name: "duplicate action step IDs",
28-
issuePath: ["actions"],
29-
issueMessage: "Action step IDs must be unique",
32+
fullSchemaValid: true,
33+
issue: {
34+
path: ["actions"],
35+
reason: "invalid_value",
36+
message: "Action step IDs must be unique",
37+
},
3038
actions: [
3139
{ step_id: "wait", action: "wait_for_timeout", duration_ms: 1 },
3240
{ step_id: "wait", action: "wait_for_timeout", duration_ms: 1 },
3341
],
3442
},
43+
{
44+
name: "overflowing wait duration",
45+
fullSchemaValid: false,
46+
issue: {
47+
path: ["actions", 0, "duration_ms"],
48+
reason: "out_of_range",
49+
maximum: 2_147_483_647,
50+
},
51+
actions: [
52+
{
53+
step_id: "wait",
54+
action: "wait_for_timeout",
55+
duration_ms: 2_147_483_648,
56+
},
57+
],
58+
},
59+
{
60+
name: "overflowing action deadline",
61+
fullSchemaValid: false,
62+
issue: {
63+
path: ["actions", 0, "timeout_ms"],
64+
reason: "out_of_range",
65+
maximum: 2_147_483_647,
66+
},
67+
actions: [
68+
{
69+
step_id: "visible",
70+
action: "wait_for",
71+
locator: { kind: "css", selector: "#btn" },
72+
state: "visible",
73+
timeout_ms: 2_147_483_648,
74+
},
75+
],
76+
},
3577
] as const;
3678

37-
cliTest(
38-
"projects refined browser scenario validation into CLI-equivalent diagnostics over stdio MCP",
39-
async ({ cli }) => {
79+
cliTest.for(["full", "compact"] as const)(
80+
"projects browser scenario input diagnostics over stdio MCP (%s)",
81+
{ timeout: 60_000 },
82+
async (profile, { cli }) => {
4083
const home = await createTestTempDirectory(
4184
"rea-browser-scenario-mcp-home-",
4285
);
@@ -52,6 +95,7 @@ cliTest(
5295
PATH: process.env.PATH ?? "",
5396
HOME: home,
5497
REA_LOG_LEVEL: "silent",
98+
REA_MCP_INPUT_SCHEMA_PROFILE: profile,
5599
},
56100
stderr: "pipe",
57101
});
@@ -81,7 +125,7 @@ cliTest(
81125
expect(
82126
validate(input),
83127
`${scenario.name}: ${JSON.stringify(validate.errors)}`,
84-
).toBe(true);
128+
).toBe(scenario.fullSchemaValid || profile === "compact");
85129

86130
const cliResult = await cli.run({
87131
arguments: [
@@ -111,13 +155,7 @@ cliTest(
111155
},
112156
details: {
113157
operation: "capture_browser_scenario",
114-
issues: [
115-
{
116-
path: scenario.issuePath,
117-
reason: "invalid_value",
118-
message: scenario.issueMessage,
119-
},
120-
],
158+
issues: [scenario.issue],
121159
},
122160
});
123161

@@ -126,12 +164,31 @@ cliTest(
126164
arguments: input,
127165
});
128166
expect(mcpResult.structuredContent).toBeUndefined();
129-
expect(parseMcpToolError(mcpResult).error).toEqual(cliDiagnostic);
167+
const mcpError = parseMcpToolError(mcpResult).error;
168+
if (scenario.fullSchemaValid) expect(mcpError).toEqual(cliDiagnostic);
169+
else {
170+
// The SDK validates the canonical schema before invoking the handler.
171+
expect(mcpError).toMatchObject({
172+
code: "invalid_request",
173+
category: "invalid_input",
174+
retryable: true,
175+
recovery: { kind: "inspect_input_contract", operation: tool.name },
176+
details: {
177+
operation: tool.name,
178+
issues: [
179+
{
180+
message: expect.stringContaining(
181+
`${scenario.issue.path.join(".")}: Too big: expected number to be <=2147483647`,
182+
),
183+
},
184+
],
185+
},
186+
});
187+
}
130188
await expect(client.ping()).resolves.toEqual({});
131189
}
132190
} finally {
133191
await Promise.all([client.close(), transport.close()]);
134192
}
135193
},
136-
60_000,
137194
);

0 commit comments

Comments
 (0)