Reverse engineer anything with agents, from app behavior down to native binaries.
TypeScript agent-skillsai-agentsbinary-analysisclaude-codeclicodexcordisdecompilerdeveloper-toolsdshdsh-pluginghidrahopperllmmcpmodel-context-protocolreareverse-engineeringstatic-analysistouhou
fix(browser): preserve uncertainty and compare redirect observations
morluto2b60e097f281
diff --git a/src/domain/browserScenarioDiff.test.ts b/src/domain/browserScenarioDiff.test.tsindex aaf3ab9d8..0eb5e593d 100644--- a/src/domain/browserScenarioDiff.test.ts+++ b/src/domain/browserScenarioDiff.test.ts@@ -539,6 +539,65 @@ describe("browser scenario network comparison stability", () => {});});+describe("scenario comparison recovery guidance", () => {+ it("retains network guidance beside a changed console event", () => {+ const before = scenarioCapture({});+ const afterBase = scenarioCapture({});+ const consoleEvent = afterBase.events.items[0];+ if (consoleEvent?.kind !== "console")+ throw new Error("Expected console fixture");+ const after = browserScenarioCaptureSchema.parse({+ ...afterBase,+ scenario: {+ ...afterBase.scenario,+ network_content: {+ ...afterBase.scenario.network_content,+ response_body: true,+ },+ },+ events: {+ ...afterBase.events,+ items: [{ ...consoleEvent, text: "settings-ready-again" }],+ },+ });+ const compare = (left: typeof before, right: typeof before) =>+ compareBrowserScenarios(+ compareBrowserScenariosInputSchema.parse({+ before_scenario: left,+ after_scenario: right,+ }),+ );++ const changed = compare(before, after);+ expect(changed.overall_status).toBe("changed");+ expect(changed.steps.flatMap((step) => step.artifact_diffs)).toContainEqual(+ expect.objectContaining({+ artifact: "events",+ status: "changed",+ reason: expect.stringContaining("Network content selections differ"),+ }),+ );+ const sameSelection = compare(before, scenarioCapture({}));+ expect(sameSelection.overall_status).toBe("unchanged");+ expect(+ sameSelection.steps.flatMap((step) => step.artifact_diffs),+ ).not.toContainEqual(expect.objectContaining({ artifact: "events" }));+ const quietMismatch = compare(+ before,+ browserScenarioCaptureSchema.parse({ ...after, events: before.events }),+ );+ expect(+ quietMismatch.steps.flatMap((step) => step.artifact_diffs),+ ).toContainEqual(+ expect.objectContaining({+ artifact: "events",+ status: "unknown",+ reason: expect.stringContaining("Network content selections differ"),+ }),+ );+ });+});+describe("browser scenario comparison", () => {it("records canonical literal normalization and ignores declared volatile fields", () => {const before = scenarioCapture({diff --git a/src/domain/browserScenarioDiff.ts b/src/domain/browserScenarioDiff.tsindex 55c8901bc..e2a0fe0a5 100644--- a/src/domain/browserScenarioDiff.ts+++ b/src/domain/browserScenarioDiff.ts@@ -425,7 +425,7 @@ const compareScenarioEvents = (after_state: afterState,before_sha256: beforeSha256,after_sha256: afterSha256,- reason: null,+ reason: input.incomparableReason ?? null,},};if (diff --git a/src/domain/webCaptureDiff.ts b/src/domain/webCaptureDiff.tsindex e062582a5..da4533690 100644--- a/src/domain/webCaptureDiff.ts+++ b/src/domain/webCaptureDiff.ts@@ -1,5 +1,8 @@import { digestCanonicalValue } from "./canonicalDigest.js";-import { compareUnicodeCodePoints } from "./unicodeCodePointOrder.js";+import {+ compareUnicodeCodePoints,+ compositeKey,+} from "./unicodeCodePointOrder.js";import type { WebPageInspection } from "./browserObservationSchemas.js";import {webCaptureDiffSchema,@@ -258,14 +261,34 @@ const sharedNetworkResponseFields = (for (const inspection of [before, after])for (const request of inspection.network.requests) {const identity = networkIdentity(request);- const fields = shared.get(identity) ?? new Set(networkResponseFields);- for (const field of networkResponseFields)- if (request[field] === null) fields.delete(field);- shared.set(identity, fields);+ retainSharedResponseFields(shared, identity, request);+ for (const [index, redirect] of (request.redirects ?? []).entries())+ retainSharedResponseFields(+ shared,+ redirectNetworkIdentity(identity, index),+ redirect,+ );}return shared;};+const retainSharedResponseFields = (+ shared: Map<string, Set<NetworkResponseField>>,+ identity: string,+ response: Pick<+ WebPageInspection["network"]["requests"][number],+ NetworkResponseField+ >,+): void => {+ const fields = shared.get(identity) ?? new Set(networkResponseFields);+ for (const field of networkResponseFields)+ if (response[field] === null) fields.delete(field);+ shared.set(identity, fields);+};++const redirectNetworkIdentity = (identity: string, index: number): string =>+ compositeKey([identity, "redirect", index]);+const networkDimension = (before: WebPageInspection,after: WebPageInspection,@@ -359,14 +382,19 @@ const networkDimension = ("Network capture or selected HTTP/WebSocket payload-shape coverage is attach-window limited, unavailable, or incomplete.",inventoryComplete,);- return compared.status === "unchanged" && !responseFieldsComplete- ? {- ...compared,- status: "unknown",- reason:- "HTTP response status, MIME type, or byte-count evidence is incomplete.",- }- : compared;+ if (responseFieldsComplete) return compared;+ const responseEvidenceReason =+ "HTTP response or redirect status, MIME type, or byte-count evidence is incomplete.";+ if (compared.status === "changed") return compared;+ return {+ status: "unknown",+ total_changes: 0,+ changes: [],+ reason:+ compared.reason === null+ ? responseEvidenceReason+ : `${responseEvidenceReason} ${compared.reason}`,+ };};const networkMap = (@@ -385,11 +413,29 @@ const networkMap = (values.push({...response,redirects: (request.redirects ?? []).map(- ({- request_timestamp: _requestTimestamp,- redirect_event_timestamp: _redirectEventTimestamp,- ...redirect- }) => redirect,+ (+ {+ request_timestamp: _requestTimestamp,+ redirect_event_timestamp: _redirectEventTimestamp,+ ...redirect+ },+ index,+ ) => {+ const response: Partial<+ Record<NetworkResponseField, number | string>+ > = {};+ for (const field of responseFields.get(+ redirectNetworkIdentity(identity, index),+ ) ?? [])+ if (redirect[field] !== null) response[field] = redirect[field];+ return {+ url: redirect.url,+ response_url: redirect.response_url,+ method: redirect.method,+ resource_type: redirect.resource_type,+ ...response,+ };+ },),initiator: request.initiator,...(shapes?.request === truediff --git a/tests/boundary/browser/webCaptureDiff.test.ts b/tests/boundary/browser/webCaptureDiff.test.tsindex 11d992fa4..955b63714 100644--- a/tests/boundary/browser/webCaptureDiff.test.ts+++ b/tests/boundary/browser/webCaptureDiff.test.ts@@ -869,6 +869,89 @@ describe("web capture redirect comparison", () => {changes: [expect.objectContaining({ change: "modified" })],});});++ it.each([+ ["status", 302],+ ["mime_type", "text/plain"],+ ["encoded_data_length", 12],+ ] as const)(+ "keeps unavailable redirect %s evidence unknown without suppressing known changes",+ async (field, knownValue) => {+ 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 before = structuredClone(captured.value);+ const beforeRequest = before.network.requests[0];+ if (beforeRequest === undefined)+ throw new Error("Missing network request");+ beforeRequest.redirects = [+ {+ url: `${browser.allowedOrigin}/prior`,+ response_url: `${browser.allowedOrigin}/prior`,+ method: "GET",+ resource_type: "Fetch",+ status: 302,+ mime_type: "text/plain",+ encoded_data_length: 12,+ request_timestamp: 1,+ redirect_event_timestamp: 2,+ },+ ];+ markSectionsComplete(before, [+ "network_requests",+ "websocket_connections",+ "websocket_frames",+ ]);++ const compare = (left: typeof before, right: typeof before) =>+ compareWebCaptures(+ compareWebCapturesInputSchema.parse({+ before: { inspection: left },+ after: { inspection: right },+ }),+ ).dimensions.network;+ for (const missingOnRight of [false, true]) {+ const known = structuredClone(before);+ const missing = structuredClone(before);+ const knownHop = known.network.requests[0]?.redirects?.[0];+ const missingHop = missing.network.requests[0]?.redirects?.[0];+ if (knownHop === undefined || missingHop === undefined)+ throw new Error("Missing redirect fixture");+ Reflect.set(knownHop, field, knownValue);+ Reflect.set(missingHop, field, null);+ const result = missingOnRight+ ? compare(known, missing)+ : compare(missing, known);+ expect(result).toMatchObject({+ status: "unknown",+ total_changes: 0,+ reason: expect.stringContaining("redirect"),+ });+ expect(compare(missing, missing)).toMatchObject({+ status: "unknown",+ total_changes: 0,+ reason: expect.stringContaining("redirect"),+ });+ }++ const changed = structuredClone(before);+ const changedHop = changed.network.requests[0]?.redirects?.[0];+ if (changedHop === undefined) throw new Error("Missing redirect fixture");+ changedHop.status = 307;+ expect(compare(before, changed)).toMatchObject({+ status: "changed",+ changes: [expect.objectContaining({ change: "modified" })],+ });+ },+ );});describe("web capture diff incomplete inventories", () => {diff --git a/tests/boundary/cli/browserCli.test.ts b/tests/boundary/cli/browserCli.test.tsindex 56daccafb..01fc53b53 100644--- a/tests/boundary/cli/browserCli.test.ts+++ b/tests/boundary/cli/browserCli.test.ts@@ -183,6 +183,51 @@ it(INTEGRATION_TEST_TIMEOUT_MS,);+it(+ "compares redirect metadata uncertainty through the public CLI",+ async () => {+ const browser = await startFakeCdpBrowser();+ browsers.push(browser);+ const inspected = await runCli(+ [+ "inspect-web-page",+ browser.endpoint,+ "allowed-page",+ "--observation-ms",+ "0",+ "--json",+ ],+ process.env,+ );+ const inspection = normalizedResult(inspected);+ const missingVsKnown = await compareCapturesCli(+ redirectCapture(inspection, browser.allowedOrigin, null),+ redirectCapture(inspection, browser.allowedOrigin, 302),+ );+ expect(missingVsKnown).toMatchObject({+ normalized_result: {+ dimensions: {+ network: {+ status: "unknown",+ total_changes: 0,+ reason: expect.stringContaining("redirect"),+ },+ },+ },+ });+ const knownDifference = await compareCapturesCli(+ redirectCapture(inspection, browser.allowedOrigin, 302),+ redirectCapture(inspection, browser.allowedOrigin, 307),+ );+ expect(knownDifference).toMatchObject({+ normalized_result: {+ dimensions: { network: { status: "changed", total_changes: 1 } },+ },+ });+ },+ INTEGRATION_TEST_TIMEOUT_MS,+);+it("browser CLI attaches through a browser socket and records it redacted",async () => {@@ -344,6 +389,68 @@ describe("scenario comparison CLI diagnostics", () => {);});+describe("scenario comparison recovery guidance", () => {+ it("reports independent network recovery alongside console differences", async () => {+ const base = completeScenarioCapture();+ const matchingSelection = scenarioCaptureWithConsole(+ "before",+ base.scenario.network_content,+ );+ const differentSelection = scenarioCaptureWithConsole("after", {+ ...base.scenario.network_content,+ response_body: true,+ });+ const changed = await compareCapturesCli(+ matchingSelection,+ differentSelection,+ );+ expect(changed).toMatchObject({+ normalized_result: {+ overall_status: "changed",+ steps: expect.arrayContaining([+ expect.objectContaining({+ step_id: "open-settings",+ artifact_diffs: expect.arrayContaining([+ expect.objectContaining({+ artifact: "events",+ status: "changed",+ reason: expect.stringContaining(+ "Network content selections differ",+ ),+ }),+ ]),+ }),+ ]),+ },+ });+ const quietMismatch = await compareCapturesCli(+ matchingSelection,+ scenarioCaptureWithConsole(+ "before",+ differentSelection.scenario.network_content,+ ),+ );+ expect(quietMismatch).toMatchObject({+ normalized_result: {+ steps: expect.arrayContaining([+ expect.objectContaining({+ step_id: "open-settings",+ artifact_diffs: expect.arrayContaining([+ expect.objectContaining({+ artifact: "events",+ status: "unknown",+ reason: expect.stringContaining(+ "Network content selections differ",+ ),+ }),+ ]),+ }),+ ]),+ },+ });+ });+});+describe("browser CLI capture parity", () => {it("runs analysis, session, WebMCP, screenshot, and comparison from explicit request scope",@@ -468,6 +575,43 @@ const normalizedResult = (value: unknown): Record<string, unknown> => {return value.normalized_result;};+const redirectCapture = (+ inspection: Record<string, unknown>,+ origin: string,+ status: number | null,+) => {+ const copy = structuredClone(inspection);+ if (!isRecord(copy.network) || !Array.isArray(copy.network.requests))+ throw new Error("Missing network capture");+ const request = copy.network.requests[0];+ if (!isRecord(request)) throw new Error("Missing network request");+ request.redirects = [+ {+ url: `${origin}/prior`,+ response_url: `${origin}/prior`,+ method: "GET",+ resource_type: "Fetch",+ status,+ mime_type: "text/plain",+ encoded_data_length: 12,+ request_timestamp: 1,+ redirect_event_timestamp: 2,+ },+ ];+ return { inspection: copy };+};++const compareCapturesCli = (before: unknown, after: unknown) =>+ runCli(+ [+ "compare-web-captures",+ JSON.stringify(before),+ JSON.stringify(after),+ "--json",+ ],+ process.env,+ );+const completeScenarioCapture = () => {const url = {url: "https://app.example.test/",@@ -533,5 +677,38 @@ const completeScenarioCapture = () => {};};+const scenarioCaptureWithConsole = (+ text: string,+ networkContent: {+ readonly request_body: boolean;+ readonly response_body: boolean;+ readonly header_values: boolean;+ },+) => {+ const capture = completeScenarioCapture();+ return {+ ...capture,+ scenario: {+ ...capture.scenario,+ network_content: networkContent,+ event_families: ["console"],+ },+ events: {+ retained: 1,+ dropped: 0,+ items: [+ {+ sequence: 1,+ step_index: 1,+ kind: "console",+ level: "info",+ text,+ url: null,+ },+ ],+ },+ };+};+const isRecord = (value: unknown): value is Record<string, unknown> =>typeof value === "object" && value !== null && !Array.isArray(value);