fix(cli): retain correction details across browser commands
Fold the complementary implementation from #2247 into the earlier #2230 proposal, retaining the original contribution history. Co-authored-by: LouisChen <3361008+chqcjq@users.noreply.github.com>
This commit is contained in:
@@ -59,13 +59,18 @@ const registerWebMcp = (
|
||||
run: ({ args, options }) =>
|
||||
logCliCommand(logger, "discover-webmcp-tools", async () => {
|
||||
const context = browserContext();
|
||||
const parsed = discoverWebMcpToolsInputSchema.safeParse({
|
||||
const input = {
|
||||
cdp_endpoint: args.endpoint,
|
||||
allowed_origins: options.allowedOrigins,
|
||||
target_id: args.targetId,
|
||||
observation_ms: options.observationMs,
|
||||
});
|
||||
if (!parsed.success) return inputError("discover_webmcp_tools");
|
||||
};
|
||||
const parsed = discoverWebMcpToolsInputSchema.safeParse(input);
|
||||
if (!parsed.success)
|
||||
return inputError(
|
||||
"discover_webmcp_tools",
|
||||
projectInputIssues(parsed.error.issues, input),
|
||||
);
|
||||
const result = await discoverWebMcpTools(context.provider, parsed.data);
|
||||
return result.ok ? result.value : browserCliError(result.error);
|
||||
}),
|
||||
@@ -113,7 +118,11 @@ const registerCaptureDiff = (
|
||||
const parsed = scenarioComparison.success
|
||||
? scenarioComparison
|
||||
: browserCaptureComparisonInputSchema.safeParse({ before, after });
|
||||
if (!parsed.success) return inputError("compare_web_captures");
|
||||
if (!parsed.success)
|
||||
return inputError(
|
||||
"compare_web_captures",
|
||||
projectInputIssues(parsed.error.issues, { before, after }),
|
||||
);
|
||||
const result = await compareWebCaptureEvidence(
|
||||
new CdpBrowserProvider(),
|
||||
parsed.data,
|
||||
@@ -140,12 +149,17 @@ const registerScreenshot = (
|
||||
run: ({ args, options }) =>
|
||||
logCliCommand(logger, "capture-web-screenshot", async () => {
|
||||
const context = browserContext();
|
||||
const parsed = captureWebScreenshotInputSchema.safeParse({
|
||||
const input = {
|
||||
cdp_endpoint: args.endpoint,
|
||||
allowed_origins: options.allowedOrigins,
|
||||
target_id: args.targetId,
|
||||
});
|
||||
if (!parsed.success) return inputError("capture_web_screenshot");
|
||||
};
|
||||
const parsed = captureWebScreenshotInputSchema.safeParse(input);
|
||||
if (!parsed.success)
|
||||
return inputError(
|
||||
"capture_web_screenshot",
|
||||
projectInputIssues(parsed.error.issues, input),
|
||||
);
|
||||
const result = await captureWebScreenshot(
|
||||
context.provider,
|
||||
parsed.data,
|
||||
|
||||
@@ -61,6 +61,24 @@ const invalidInputs = [
|
||||
error: "JavaScript runtime observation failed",
|
||||
issue: { path: ["target_id"], reason: "out_of_range", minimum: 1 },
|
||||
},
|
||||
{
|
||||
command: "discover-webmcp-tools",
|
||||
arguments: [malformedEndpoint, "target"],
|
||||
operation: "discover_webmcp_tools",
|
||||
error: "Browser observation failed",
|
||||
issue: {
|
||||
path: ["cdp_endpoint"],
|
||||
reason: "invalid_value",
|
||||
message: "Invalid CDP endpoint URL",
|
||||
},
|
||||
},
|
||||
{
|
||||
command: "capture-web-screenshot",
|
||||
arguments: [browserEndpoint, ""],
|
||||
operation: "capture_web_screenshot",
|
||||
error: "Browser observation failed",
|
||||
issue: { path: ["target_id"], reason: "out_of_range", minimum: 1 },
|
||||
},
|
||||
] as const;
|
||||
|
||||
describe("browser and Inspector CLI input diagnostics", () => {
|
||||
@@ -159,6 +177,28 @@ describe("browser and Inspector CLI input diagnostics", () => {
|
||||
},
|
||||
);
|
||||
|
||||
cliTest(
|
||||
"retains correction details for invalid capture comparison inputs",
|
||||
async ({ cli, workspace }) => {
|
||||
const result = await cli.run({
|
||||
arguments: ["compare-web-captures", "{}", "{}", "--json"],
|
||||
cwd: workspace.root,
|
||||
environment: { ...workspace.environment, REA_LOG_LEVEL: "silent" },
|
||||
});
|
||||
|
||||
expect(result.exitCode).toBe(1);
|
||||
expect(result.json).toMatchObject({
|
||||
code: "invalid_request",
|
||||
details: {
|
||||
operation: "compare_web_captures",
|
||||
issues: expect.arrayContaining([
|
||||
expect.objectContaining({ reason: expect.any(String) }),
|
||||
]),
|
||||
},
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
cliTest(
|
||||
"preserves the parser diagnostic for an omitted endpoint",
|
||||
async ({ cli, workspace }) => {
|
||||
|
||||
Reference in New Issue
Block a user