test(sourcemap): consolidate browser capture coverage checks (#13063)

test(sourcemap): consolidate capture coverage and validation
This commit is contained in:
morluto authored and GitHub committed 2026-11-21 10:06:40 +00:00
1 parent 7b3457cdfe
commit d69a7fdbf6
2 files changed
+68 -69

No files matched your search

-60
View File
@@ -645,66 +645,6 @@ describe("web bundle analyzer", () => {
});
});
describe("web bundle source-map coverage", () => {
it("reports unavailable source maps as partial without dropping requested maps", () => {
const analysis = analyzeWebBundleFixture(inspection("export {};"), {
status: "unavailable",
requested: 1,
processed: 1,
items: [
{
script_key: `scr_${"1".repeat(64)}`,
declared_url: "https://app.example.test/app.js.map",
effective_url: null,
status: "fetch_failed",
artifact: null,
original_sources: [],
original_module_edges: [],
mappings: [],
limitation: "Source-map fetch failed.",
},
],
});
expect(analysis.completeness.status).toBe("partial");
expect(analysis.unknowns).toContainEqual({
dimension: "source_maps",
reason: expect.stringMatching(
/requested source maps.*unavailable or incomplete/i,
),
affected_script_keys: [`scr_${"1".repeat(64)}`],
});
});
it("keeps map-less captured source complete when no maps were requested", () => {
const analysis = analyzeWebBundleFixture(inspection("export {};"), {
status: "not_requested",
requested: 0,
processed: 0,
items: [],
});
expect(analysis.completeness.status).toBe("complete");
expect(analysis.unknowns).toEqual([]);
});
it("rejects inconsistent source-map coverage counts", () => {
const result = analyzeWebBundleFixture(inspection("export {};"));
expect(
webBundleAnalysisSchema.safeParse({
...result,
observations: {
...result.observations,
source_maps: {
...result.observations.source_maps,
requested: 1,
},
},
}).success,
).toBe(false);
});
});
describe("web bundle static-analysis parity", () => {
it("qualifies network spellings through nested dynamic receivers", () => {
const result = analyzeWebBundleFixture(
@@ -1,9 +1,71 @@
import { expect, it } from "vitest";
import { CdpBrowserProvider } from "../../../src/browser/CdpBrowserProvider.js";
import { analyzeWebBundleInputSchema } from "../../../src/domain/webBundleAnalysis.js";
import {
analyzeWebBundleInputSchema,
webBundleAnalysisSchema,
type WebBundleAnalysis,
type WebSourceMaps,
} from "../../../src/domain/webBundleAnalysis.js";
import { startFakeCdpBrowser } from "../../fixtures/fakeCdpBrowser.js";
import { trackBrowser } from "./cdpBrowserProvider.support.js";
const expectMapCoverageIssue = (
analysis: WebBundleAnalysis,
changes: Partial<WebSourceMaps>,
...path: string[]
): void => {
expect(
webBundleAnalysisSchema.safeParse({
...analysis,
observations: {
...analysis.observations,
source_maps: { ...analysis.observations.source_maps, ...changes },
},
}),
).toMatchObject({
success: false,
error: { issues: [{ path: ["observations", "source_maps", ...path] }] },
});
};
const expectMaplessCoverageRefusals = (analysis: WebBundleAnalysis): void => {
expectMapCoverageIssue(analysis, {
status: "unavailable",
requested: 1,
processed: 1,
});
expectMapCoverageIssue(
analysis,
{ status: "unavailable", requested: 1 },
"limitation",
);
expectMapCoverageIssue(
analysis,
{ requested: 1, limitation: "Source map pending" },
"status",
);
};
const expectRedirectCoverage = (analysis: WebBundleAnalysis): void => {
const { chunks, source_maps: maps } = analysis.observations;
const scriptKey = chunks.nodes[0]?.script_key;
expect(maps).toMatchObject({
status: "unavailable",
requested: 1,
processed: 1,
items: [{ script_key: scriptKey, status: "policy_filtered" }],
});
expect(maps.excluded).toBeUndefined();
expectMapCoverageIssue(analysis, { requested: 0 });
expect(analysis.unknowns).toContainEqual({
dimension: "source_maps",
reason: expect.stringMatching(
/requested source maps.*unavailable or incomplete/i,
),
affected_script_keys: [scriptKey],
});
};
it("distinguishes unrequested maps, map exclusions, and usable map evidence", async () => {
const modes = [
"not-selected",
@@ -80,18 +142,15 @@ it("distinguishes unrequested maps, map exclusions, and usable map evidence", as
});
expect(result.value.completeness.status, mode).toBe("complete");
expect(result.value.unknowns, mode).toEqual([]);
if (mode === "none") expectMaplessCoverageRefusals(result.value);
} else {
expect(result.value.completeness.status, mode).toBe("partial");
expect(result.value.unknowns, mode).toContainEqual(
expect.objectContaining({ dimension: "source_maps" }),
);
if (mode === "redirect") {
expect(maps, mode).toMatchObject({
status: "unavailable",
items: [{ status: "policy_filtered" }],
});
expect(maps.excluded).toBeUndefined();
expectRedirectCoverage(result.value);
} else {
expect(result.value.unknowns, mode).toContainEqual(
expect.objectContaining({ dimension: "source_maps" }),
);
expect(maps.excluded, mode).toEqual([
{ section: "source_maps", reason: "disallowed_origin", count: 1 },
]);