fix(cli): retain correction details across adjacent browser commands (#2294)
* 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> * fix(browser): retain diagnostics from the selected input branch * fix(cli): recognize incomplete browser scenarios by their owned fields --------- Co-authored-by: LouisChen <3361008+chqcjq@users.noreply.github.com>
This commit is contained in:
@@ -93,7 +93,7 @@ it(
|
||||
const compared = await runCli(
|
||||
[
|
||||
"compare-web-captures",
|
||||
JSON.stringify({ inspection }),
|
||||
JSON.stringify({ inspection, scenario: { caller_metadata: true } }),
|
||||
JSON.stringify({ inspection }),
|
||||
"--json",
|
||||
],
|
||||
@@ -183,6 +183,119 @@ it(
|
||||
INTEGRATION_TEST_TIMEOUT_MS,
|
||||
);
|
||||
|
||||
describe("scenario comparison CLI diagnostics", () => {
|
||||
const rule = {
|
||||
rule_id: "domain",
|
||||
artifacts: ["url"],
|
||||
match: "app.example.test",
|
||||
replacement: "normalized.test",
|
||||
};
|
||||
it.each([
|
||||
{
|
||||
name: "duplicate rule IDs",
|
||||
normalization: { rules: [rule, rule] },
|
||||
issue: {
|
||||
path: ["normalization", "rules", 1, "rule_id"],
|
||||
reason: "invalid_value",
|
||||
message: "Normalization rule IDs must be unique",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "duplicate artifact kinds",
|
||||
normalization: { rules: [{ ...rule, artifacts: ["url", "url"] }] },
|
||||
issue: {
|
||||
path: ["normalization", "rules", 0, "artifacts"],
|
||||
reason: "invalid_value",
|
||||
message: "Normalization rule artifact kinds must be unique",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "structurally invalid rules",
|
||||
normalization: { rules: "invalid" },
|
||||
issue: {
|
||||
path: ["normalization", "rules"],
|
||||
reason: "invalid_type",
|
||||
expected: "array",
|
||||
},
|
||||
},
|
||||
])(
|
||||
"retains scenario normalization diagnostics for $name",
|
||||
async ({ normalization, issue }) => {
|
||||
const capture = JSON.stringify(completeScenarioCapture());
|
||||
const result = await runCli([
|
||||
"compare-web-captures",
|
||||
capture,
|
||||
capture,
|
||||
"--normalization-json",
|
||||
JSON.stringify(normalization),
|
||||
"--json",
|
||||
]);
|
||||
expect(result).toMatchObject({
|
||||
code: "invalid_request",
|
||||
details: { operation: "compare_web_captures", issues: [issue] },
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it("keeps malformed scenario diagnostics in the selected capture group", async () => {
|
||||
const capture = completeScenarioCapture();
|
||||
const result = await runCli([
|
||||
"compare-web-captures",
|
||||
JSON.stringify({ ...capture, duration_ms: "invalid" }),
|
||||
JSON.stringify(capture),
|
||||
"--json",
|
||||
]);
|
||||
expect(result).toMatchObject({
|
||||
code: "invalid_request",
|
||||
details: {
|
||||
operation: "compare_web_captures",
|
||||
issues: [
|
||||
{
|
||||
path: ["before_scenario", "duration_ms"],
|
||||
reason: "invalid_type",
|
||||
expected: "number",
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it.each(["omitted", "misspelled"])(
|
||||
"reports the missing scenario manifest when it is %s on both captures",
|
||||
async (kind) => {
|
||||
const { scenario, ...capture } = completeScenarioCapture();
|
||||
const input = JSON.stringify(
|
||||
kind === "omitted" ? capture : { ...capture, scneario: scenario },
|
||||
);
|
||||
const result = await runCli([
|
||||
"compare-web-captures",
|
||||
input,
|
||||
input,
|
||||
"--json",
|
||||
]);
|
||||
expect(result).toMatchObject({
|
||||
code: "invalid_request",
|
||||
details: {
|
||||
operation: "compare_web_captures",
|
||||
issues: expect.arrayContaining([
|
||||
{
|
||||
path: ["before_scenario", "scenario"],
|
||||
reason: "missing_argument",
|
||||
expected: "object",
|
||||
},
|
||||
{
|
||||
path: ["after_scenario", "scenario"],
|
||||
reason: "missing_argument",
|
||||
expected: "object",
|
||||
},
|
||||
]),
|
||||
},
|
||||
});
|
||||
expect(JSON.stringify(result)).not.toContain('"inspection"');
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe("browser CLI capture parity", () => {
|
||||
it(
|
||||
"runs analysis, session, WebMCP, screenshot, and comparison from explicit request scope",
|
||||
|
||||
@@ -61,8 +61,59 @@ 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("inspection branch diagnostics", () => {
|
||||
cliTest.for([[], ["--include-script-sources"]])(
|
||||
"reports only the selected inspection branch's endpoint error (%j)",
|
||||
async (flags, { cli, workspace }) => {
|
||||
const result = await cli.run({
|
||||
arguments: [
|
||||
"inspect-web-page",
|
||||
malformedEndpoint,
|
||||
"target",
|
||||
...flags,
|
||||
"--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: "inspect_web_page",
|
||||
issues: [
|
||||
{
|
||||
path: ["cdp_endpoint"],
|
||||
reason: "invalid_value",
|
||||
message: "Invalid CDP endpoint URL",
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe("browser and Inspector CLI input diagnostics", () => {
|
||||
cliTest.for(invalidInputs)(
|
||||
"$command retains the named contract's correction details",
|
||||
@@ -159,6 +210,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