refactor(domain): encode comparison and lifecycle states exactly (#473)

* refactor(domain): encode comparison states exactly

* refactor(domain): make evidence lifecycles explicit

* refactor(browser): parse capture states once

* test: prefer behavior over implementation seams

* chore: refresh schema-derived metadata

* test(process): preserve lifecycle cleanup coverage

* test(hopper): bind rename cache coverage to dispatch
This commit is contained in:
morluto
2026-08-11 18:04:36 +08:00
committed by GitHub
parent e91c8c39c2
commit d65730c4c2
43 changed files with 1732 additions and 780 deletions
@@ -13,6 +13,9 @@ import {
} from "../../fixtures/fakeCdpBrowser.js";
const browsers: FakeCdpBrowser[] = [];
const expectInvalidDiff = (input: unknown): void => {
expect(webCaptureDiffSchema.safeParse(input).success).toBe(false);
};
afterEach(async () => {
await Promise.all(browsers.splice(0).map(async (browser) => browser.close()));
@@ -58,6 +61,21 @@ describe("web capture diff", () => {
status: "unknown",
total_changes: 0,
});
expectInvalidDiff({ ...result, overall_status: "unchanged" });
expectInvalidDiff({
...result,
dimensions: {
...result.dimensions,
webmcp: { ...result.dimensions.webmcp, reason: null },
},
});
expectInvalidDiff({
...result,
dimensions: {
...result.dimensions,
scripts: { ...result.dimensions.scripts, total_changes: 2 },
},
});
const {
accessibility: _accessibility,
storage: _storage,
@@ -1,7 +1,11 @@
import { describe, expect, it } from "vitest";
import { fetchWebSourceMaps } from "../../../src/browser/WebSourceMapFetcher.js";
import { analyzeWebBundleInputSchema } from "../../../src/domain/webBundleAnalysis.js";
import {
analyzeWebBundleInputSchema,
webSourceMapsSchema,
type WebSourceMaps,
} from "../../../src/domain/webBundleAnalysis.js";
const origin = "https://app.example.test";
const request = {
@@ -10,6 +14,18 @@ const request = {
fetchUrl: `${origin}/assets/app.js.map?token=secret`,
};
const expectInvalidSourceMaps = (value: unknown): void => {
expect(webSourceMapsSchema.safeParse(value).success).toBe(false);
};
const expectInvalidIncludedSourceMaps = (result: WebSourceMaps): void => {
expectInvalidSourceMaps({
...result,
items: [{ ...result.items[0], artifact: null }],
});
expectInvalidSourceMaps({ ...result, status: "unavailable" });
};
describe("web source-map fetching and validation", () => {
it("fetches without credentials and derives mappings and original modules", async () => {
const calls: Array<{ url: string; init: RequestInit | undefined }> = [];
@@ -77,6 +93,7 @@ describe("web source-map fetching and validation", () => {
},
],
});
expectInvalidIncludedSourceMaps(result);
});
it("validates sectioned maps and reports bounded mapping truncation", async () => {
@@ -136,6 +153,10 @@ describe("web source-map fetching and validation", () => {
status: "unavailable",
items: [{ status: "policy_filtered" }],
});
expectInvalidSourceMaps({
...result,
items: [{ ...result.items[0], limitation: null }],
});
});
it("distinguishes invalid JSON from declared or streamed byte truncation", async () => {