fix(browser): report mismatched event family selection as unknown in capture comparison (#2239)

* fix(browser): report mismatched event family selection as unknown in capture comparison

* fix(browser): retain selected event families and unknown coverage

Fold the complementary implementation from #2253 into the earlier #2239 proposal, retaining the original contribution history.

Co-authored-by: itsF4LCON <107556180+itsF4LCON@users.noreply.github.com>

---------

Co-authored-by: LouisChen <3361008+chqcjq@users.noreply.github.com>
Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
Co-authored-by: itsF4LCON <107556180+itsF4LCON@users.noreply.github.com>
This commit is contained in:
LouisChen
2026-10-13 02:36:45 +08:00
committed by GitHub
co-authored by LouisChen morluto itsF4LCON
parent aeee5074d1
commit 0043d9b134
13 changed files with 206 additions and 15 deletions
+90
View File
@@ -62,6 +62,7 @@ const networkCapture = (sourceSequence: number, receiptStep: number) => {
response_body: false,
header_values: false,
},
event_families: ["network"],
},
events: { items: events, retained: 2, dropped: 0 },
});
@@ -146,6 +147,94 @@ it("reports content-selection mismatch as unknown instead of a website change",
).toBe(false);
});
it("reports event-family mismatch and legacy selection as unknown", () => {
const consoleOnly = scenarioCapture({});
const withFamilies = (
capture: BrowserScenarioCapture,
families: BrowserScenarioCapture["scenario"]["event_families"],
) =>
browserScenarioCaptureSchema.parse({
...capture,
scenario: { ...capture.scenario, event_families: families },
});
const compare = (
before: BrowserScenarioCapture,
after: BrowserScenarioCapture,
) =>
compareBrowserScenarios(
compareBrowserScenariosInputSchema.parse({
before_scenario: before,
after_scenario: after,
}),
);
const eventDiffs = (compared: ReturnType<typeof compare>) =>
compared.steps
.flatMap((step) => step.artifact_diffs)
.filter(({ artifact }) => artifact === "events");
const widened = withFamilies(consoleOnly, ["page-errors", "console"]);
const mismatched = compare(consoleOnly, widened);
expect(mismatched.overall_status).toBe("unknown");
expect(eventDiffs(mismatched)).toContainEqual(
expect.objectContaining({
status: "unknown",
before_state: "captured",
after_state: "captured",
reason: expect.stringContaining(
"Event family selections differ (console before, console, page-errors after)",
),
}),
);
expect(
compare(
withFamilies(consoleOnly, ["console", "page-errors"]),
withFamilies(consoleOnly, ["page-errors", "console"]),
).overall_status,
).toBe("unchanged");
const legacy = withFamilies(consoleOnly, undefined);
expect(legacy.scenario.event_families).toBeUndefined();
for (const [before, after] of [
[legacy, consoleOnly],
[legacy, legacy],
] as const)
expect(eventDiffs(compare(before, after))).toContainEqual(
expect.objectContaining({
status: "unknown",
reason: expect.stringContaining("Event family selection is unknown"),
}),
);
expect(
compareBrowserScenariosInputSchema.safeParse({
before_scenario: {
...consoleOnly,
scenario: { ...consoleOnly.scenario, event_families: ["dialogs"] },
},
after_scenario: consoleOnly,
}).success,
).toBe(false);
const quiet = browserScenarioCaptureSchema.parse({
...withFamilies(consoleOnly, []),
events: { retained: 0, dropped: 0, items: [] },
});
const differentEvents = compare(quiet, widened);
expect(differentEvents.overall_status).toBe("unknown");
expect(eventDiffs(differentEvents).map(({ status }) => status)).toEqual([
"unknown",
"unknown",
]);
const both = eventDiffs(compare(networkCapture(1, 0), consoleOnly));
expect(both).toContainEqual(
expect.objectContaining({
reason: expect.stringMatching(
/Event family selections differ.*content selections differ/u,
),
}),
);
});
describe("browser scenario comparison", () => {
it("records canonical literal normalization and ignores declared volatile fields", () => {
const before = scenarioCapture({
@@ -485,6 +574,7 @@ const scenarioCapture = (
response_body: false,
header_values: false,
},
event_families: ["console"],
},
duration_ms: options.elapsedMs ?? 10,
steps: [