fix(web): retain uncertainty for incomplete capture inventories (#513)
* fix(web): retain uncertainty for incomplete capture inventories Signed-off-by: Rudy Celekli <rudy@gradiahq.com> * test(web): keep incomplete capture cases in a focused suite Signed-off-by: RudyCelekli <47457359+rudycelekli@users.noreply.github.com> --------- Signed-off-by: Rudy Celekli <rudy@gradiahq.com> Signed-off-by: RudyCelekli <47457359+rudycelekli@users.noreply.github.com>
This commit is contained in:
@@ -80,7 +80,9 @@ const compareDimension = (
|
||||
complete: boolean,
|
||||
reason: string,
|
||||
): Dimension => {
|
||||
const all = compareIdentities(before, after);
|
||||
const all = compareIdentities(before, after).filter(
|
||||
({ change }) => complete || change === "modified",
|
||||
);
|
||||
if (all.length > 0)
|
||||
return {
|
||||
status: "changed",
|
||||
|
||||
@@ -44,6 +44,7 @@ describe("web capture diff", () => {
|
||||
}),
|
||||
);
|
||||
if (!captured.ok) throw captured.error;
|
||||
markSectionsComplete(captured.value, ["scripts"]);
|
||||
const after = structuredClone(captured.value);
|
||||
after.scripts.items = [];
|
||||
const request = after.network.requests[0];
|
||||
@@ -162,6 +163,64 @@ describe("web capture diff", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("web capture diff incomplete inventories", () => {
|
||||
it.each(["truncated_sections", "unavailable_sections"] as const)(
|
||||
"does not infer script additions or removals from %s",
|
||||
async (section) => {
|
||||
const browser = await startFakeCdpBrowser();
|
||||
browsers.push(browser);
|
||||
const captured = await new CdpBrowserProvider().inspectPage(
|
||||
inspectWebPageInputSchema.parse({
|
||||
cdp_endpoint: browser.endpoint,
|
||||
allowed_origins: [browser.allowedOrigin],
|
||||
target_id: "allowed-page",
|
||||
observation_ms: 0,
|
||||
}),
|
||||
);
|
||||
if (!captured.ok) throw captured.error;
|
||||
const complete = structuredClone(captured.value);
|
||||
markSectionsComplete(complete, ["scripts"]);
|
||||
expect(complete.scripts.items).toHaveLength(1);
|
||||
const incomplete = structuredClone(complete);
|
||||
incomplete.scripts.items = [];
|
||||
incomplete.completeness[section].push("scripts");
|
||||
const compare = (before: typeof complete, after: typeof complete) =>
|
||||
compareWebCaptures(
|
||||
compareWebCapturesInputSchema.parse({
|
||||
before: { inspection: before },
|
||||
after: { inspection: after },
|
||||
}),
|
||||
).dimensions.scripts;
|
||||
|
||||
expect(compare(complete, incomplete)).toMatchObject({
|
||||
status: "unknown",
|
||||
total_changes: 0,
|
||||
changes: [],
|
||||
});
|
||||
expect(compare(incomplete, complete)).toMatchObject({
|
||||
status: "unknown",
|
||||
total_changes: 0,
|
||||
changes: [],
|
||||
});
|
||||
markSectionsComplete(incomplete, ["scripts"]);
|
||||
expect(compare(complete, incomplete).changes).toEqual([
|
||||
expect.objectContaining({ change: "removed" }),
|
||||
]);
|
||||
expect(compare(incomplete, complete).changes).toEqual([
|
||||
expect.objectContaining({ change: "added" }),
|
||||
]);
|
||||
const modified = structuredClone(complete);
|
||||
modified.completeness[section].push("scripts");
|
||||
const script = modified.scripts.items[0];
|
||||
if (script === undefined) throw new Error("Missing captured script");
|
||||
script.url = `${script.url}?revision=2`;
|
||||
expect(compare(complete, modified).changes).toEqual([
|
||||
expect.objectContaining({ change: "modified" }),
|
||||
]);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe("web capture diff semantics and fingerprints", () => {
|
||||
it("detects accessibility semantics and storage inventory changes", async () => {
|
||||
const browser = await startFakeCdpBrowser({ extraCollections: true });
|
||||
|
||||
Reference in New Issue
Block a user