diff --git a/tests/boundary/browser/webSourceMapFetcher.test.ts b/tests/boundary/browser/webSourceMapFetcher.test.ts index 874eef6680..f55e8bb7c4 100644 --- a/tests/boundary/browser/webSourceMapFetcher.test.ts +++ b/tests/boundary/browser/webSourceMapFetcher.test.ts @@ -882,38 +882,6 @@ it("shares the caller's fetch byte budget across completed map responses", async expect(result.items[1]?.limitation).toContain("retained budget"); }); -it.each([ - { line: 0, column: -1 }, - { line: -1, column: 0 }, - { line: "0", column: 0 }, - { line: 0, column: 0.5 }, - { line: 0 }, - { line: 0, column: Number.MAX_SAFE_INTEGER + 1 }, -])("retains an invalid-map item for malformed offset %j", async (offset) => { - const text = JSON.stringify({ - version: 3, - sections: [ - { - offset, - map: { - version: 3, - sources: ["original.js"], - names: [], - mappings: "AAAA", - }, - }, - ], - }); - const result = await fetchWebSourceMapsOk([request], input(), undefined, { - fetch: async () => new Response(text), - }); - - expect(result).toMatchObject({ - status: "unavailable", - items: [{ status: "invalid", artifact: null, mappings: [] }], - }); -}); - describe("web source-map sourcesContent validation", () => { it.each([ ["a scalar sourcesContent value", { sourcesContent: "source" }], diff --git a/tests/boundary/browser/webSourceMapNestedCoordinates.test.ts b/tests/boundary/browser/webSourceMapNestedCoordinates.test.ts index d59d5252a2..b50e409760 100644 --- a/tests/boundary/browser/webSourceMapNestedCoordinates.test.ts +++ b/tests/boundary/browser/webSourceMapNestedCoordinates.test.ts @@ -4,12 +4,6 @@ import { analyzeWebBundleInputSchema } from "../../../src/domain/webBundleAnalys import { fetchWebSourceMapsOk } from "../../fixtures/fetchWebSourceMapsOk.js"; const origin = "https://example.test"; -const url = `${origin}/app.js.map`; -const request = { - scriptKey: `scr_${"1".repeat(64)}`, - declaredUrl: url, - fetchUrl: url, -}; const input = analyzeWebBundleInputSchema.parse({ cdp_endpoint: "http://127.0.0.1:9222", allowed_origins: [origin], @@ -41,72 +35,62 @@ const section = ( const indexed = (...sections: Section[]) => ({ version: 3, sections }); -const fetchMap = (text: string) => - fetchWebSourceMapsOk([request], input, undefined, { - fetch: async () => new Response(text), - }); +const fetchMaps = (...texts: string[]) => { + const replies = new Map( + texts.map((text, index) => [`${origin}/map-${index}.js.map`, text]), + ); + return fetchWebSourceMapsOk( + [...replies.keys()].map((url, index) => ({ + scriptKey: `scr_${String(index + 1).padStart(64, "0")}`, + declaredUrl: url, + fetchUrl: url, + })), + input, + undefined, + { fetch: async (url) => new Response(replies.get(String(url))) }, + ); +}; -it.each([ - { - name: "a later nested line discards the outer column", - map: indexed(section(5, 10, indexed(section(1, 3, leaf("a.ts"))))), - line: 7, - column: 3, - }, - { - name: "three offsets on the same line add their columns", - map: indexed( +const identity = (text: string) => ({ + sha256: createHash("sha256").update(text).digest("hex"), + bytes: Buffer.byteLength(text), +}); + +it("adds nested same-line columns and resets the column on a later line", async () => { + const text = JSON.stringify( + indexed( section( 0, 2, - indexed(section(0, 3, indexed(section(0, 4, leaf("a.ts"))))), + indexed(section(0, 3, indexed(section(0, 4, leaf("same-line.ts"))))), ), + section(5, 10, indexed(section(1, 3, leaf("later-line.ts")))), ), - line: 1, - column: 9, - }, -])("publishes nested coordinates when $name", async ({ map, line, column }) => { - const text = JSON.stringify(map); - const result = await fetchMap(text); - expect(result).toMatchObject({ + ); + const sameLine = `${origin}/same-line.ts`; + const laterLine = `${origin}/later-line.ts`; + expect(await fetchMaps(text)).toMatchObject({ status: "included", items: [ { - artifact: { - sha256: createHash("sha256").update(text).digest("hex"), - bytes: Buffer.byteLength(text), - }, - original_sources: [{ source: `${origin}/a.ts` }], + artifact: identity(text), + original_sources: [{ source: sameLine }, { source: laterLine }], mappings: [ - { - generated_line: line, - generated_column: column, - source: `${origin}/a.ts`, - }, + { generated_line: 1, generated_column: 9, source: sameLine }, + { generated_line: 7, generated_column: 3, source: laterLine }, ], }, ], }); }); -it.each([ - { - name: "a following indexed section starts before its first child", - map: indexed( - section(0, 0, leaf("a.ts", "AAAA,QAAQ")), - section(0, 5, indexed(section(0, 6, leaf("b.ts")))), - ), - }, - { - name: "a following indexed section is empty", - map: indexed( - section(0, 0, leaf("a.ts", "AAAA,QAAQ")), - section(0, 5, indexed()), - ), - }, - { - name: "a descendant mapping passes its parent's multiline stop", - map: indexed( +it("rejects overlaps at declared section starts and inherited stops", async () => { + const beforeNested = section(0, 0, leaf("a.ts", "AAAA,QAAQ")); + const maps = [ + // The next declared start applies even when its own first child starts later. + indexed(beforeNested, section(0, 5, indexed(section(0, 6, leaf("b.ts"))))), + indexed(beforeNested, section(0, 5, indexed())), + indexed( section( 0, 0, @@ -114,53 +98,60 @@ it.each([ ), section(3, 1, leaf("b.ts")), ), - }, -])("rejects an overlap when $name", async ({ map }) => { - const text = JSON.stringify(map); - expect(await fetchMap(text)).toMatchObject({ + indexed( + section(0, 0, leaf("a.ts", "AAAA,UAAA,CAAA")), + section(0, 10, leaf("b.ts")), + ), + ]; + const texts = maps.map((map) => JSON.stringify(map)); + expect(await fetchMaps(...texts)).toMatchObject({ status: "unavailable", - items: [ - { - status: "invalid", - artifact: null, - mappings: [], - limitation: expect.stringContaining("overlap"), - response_identity: { - sha256: createHash("sha256").update(text).digest("hex"), - bytes: Buffer.byteLength(text), - }, - }, - ], + requested: texts.length, + processed: texts.length, + items: texts.map((text, index) => ({ + declared_url: `${origin}/map-${index}.js.map`, + status: "invalid", + artifact: null, + mappings: [], + limitation: expect.stringContaining("overlap"), + response_identity: identity(text), + })), }); }); -it("accepts mappings at the next section start and rejects mappings beyond it", async () => { - const fetchSiblings = (firstMappings: string) => - fetchMap( - JSON.stringify( - indexed( - section(0, 0, leaf("a.ts", firstMappings)), - section(0, 10, leaf("b.ts")), - ), - ), - ); - - expect(await fetchSiblings("AAAA,QAAQ")).toMatchObject({ - status: "included", - items: [ - { - mappings: [ - { generated_line: 1, generated_column: 0, source: `${origin}/a.ts` }, - { generated_line: 1, generated_column: 8, source: `${origin}/a.ts` }, - { generated_line: 1, generated_column: 10, source: `${origin}/b.ts` }, - ], - }, - ], +it("rejects each malformed section offset and keeps its response identity", async () => { + const offsets = [ + { line: 0, column: -1 }, + { line: -1, column: 0 }, + { line: "0", column: 0 }, + { line: 0, column: 0.5 }, + { line: 0 }, + { line: 0, column: Number.MAX_SAFE_INTEGER + 1 }, + ]; + const texts = offsets.map((offset) => + JSON.stringify({ + version: 3, + sections: [{ offset, map: leaf("original.js") }], + }), + ); + expect(await fetchMaps(...texts)).toMatchObject({ + status: "unavailable", + requested: offsets.length, + processed: offsets.length, + items: texts.map((text) => ({ + status: "invalid", + artifact: null, + mappings: [], + response_identity: identity(text), + })), }); +}); + +it("keeps named mappings before and at a shared section boundary", async () => { const text = JSON.stringify( indexed( section(0, 0, { - ...leaf("same.ts", "AAAAA,UAAAA", ["first"]), + ...leaf("same.ts", "AAAAA,QAAAA,EAAAA", ["first"]), sourcesContent: ["export const first = 1;"], }), section(0, 10, { @@ -169,14 +160,11 @@ it("accepts mappings at the next section start and rejects mappings beyond it", }), ), ); - expect(await fetchMap(text)).toMatchObject({ + expect(await fetchMaps(text)).toMatchObject({ status: "included", items: [ { - artifact: { - sha256: createHash("sha256").update(text).digest("hex"), - bytes: Buffer.byteLength(text), - }, + artifact: identity(text), original_sources: [ { source: `${origin}/same.ts`, declaration_index: 0 }, { source: `${origin}/same.ts`, declaration_index: 1 }, @@ -188,6 +176,12 @@ it("accepts mappings at the next section start and rejects mappings beyond it", declaration_index: 0, name: "first", }, + { + generated_line: 1, + generated_column: 8, + declaration_index: 0, + name: "first", + }, { generated_line: 1, generated_column: 10, @@ -204,15 +198,4 @@ it("accepts mappings at the next section start and rejects mappings beyond it", }, ], }); - expect(await fetchSiblings("AAAA,UAAA,CAAA")).toMatchObject({ - status: "unavailable", - items: [ - { - status: "invalid", - artifact: null, - mappings: [], - limitation: expect.stringContaining("overlap"), - }, - ], - }); });