diff --git a/src/artifacts/ReleaseExposureReader.test.ts b/src/artifacts/ReleaseExposureReader.test.ts index 713620f488..22be0c48e6 100644 --- a/src/artifacts/ReleaseExposureReader.test.ts +++ b/src/artifacts/ReleaseExposureReader.test.ts @@ -1665,34 +1665,40 @@ describe("ReleaseExposureReader member allowances", () => { }, ); - it( - "keeps a later source map readable after many large binary members", - { tags: ["long-running"] }, - async () => { - const root = await createTestTempDirectory( - "rea-release-exposure-budget-", - ); - const binary = Buffer.alloc(MAX_RELEASE_EXPOSURE_TEXT_MEMBER_BYTES); - const oversizedScript = Buffer.alloc( - MAX_RELEASE_EXPOSURE_TEXT_MEMBER_BYTES + 1, - 0x20, - ); - await writeFile( - join(root, "app.asar"), - asarArchive([ - ...Array.from({ length: 160 }, (_, index) => ({ - name: `a${String(index)}.bin`, - bytes: binary, - })), - { name: "b.js", bytes: oversizedScript }, - { name: "z.js.map", bytes: embeddedSourceMap() }, - ]), - ); - const scanned = await inspect(join(root, "app.asar")); - expect(scanned.source_maps).toMatchObject({ embedded: 1, skipped: 1 }); - expect(scanned.extractable.readable_members).toBe(162); - }, - ); + it("keeps later text and maps readable after large ASAR binary members", async () => { + const root = await createTestTempDirectory("rea-release-exposure-budget-"); + const binary = Buffer.alloc(MAX_RELEASE_EXPOSURE_TEXT_MEMBER_BYTES); + const binaryCount = MAX_RELEASE_EXPOSURE_TEXT_BYTES / binary.length + 1; + const path = join(root, "app.asar"); + await writeFile( + path, + asarArchive([ + ...Array.from({ length: binaryCount }, (_, index) => ({ + name: `a${String(index)}.bin`, + bytes: binary, + })), + { + name: "b.js", + bytes: Buffer.alloc(MAX_RELEASE_EXPOSURE_TEXT_MEMBER_BYTES + 1, 0x20), + }, + { name: "z.txt", bytes: Buffer.from("release notes\n") }, + { name: "z.js.map", bytes: embeddedSourceMap() }, + ]), + ); + + const scanned = await inspect(path); + expect(scanned.source_maps).toMatchObject({ + embedded: 1, + embedded_paths: ["z.js.map"], + skipped: 1, + }); + expect(scanned.textLocations).toEqual(["z.js.map", "z.txt"]); + expect(scanned.text_members).toEqual({ scanned: 2, skipped: 1 }); + expect(scanned.extractable).toMatchObject({ + readable_members: binaryCount + 3, + unreadable_members: 0, + }); + }); it("reports an oversized linker map as a debug companion wherever it ships", async () => { const root = await createTestTempDirectory("rea-release-exposure-link-"); @@ -1725,29 +1731,27 @@ describe("ReleaseExposureReader member allowances", () => { expect(packaged.source_maps.skipped).toBe(0); }); - it("leaves an oversized JSON .map undecided as both map kinds", async () => { + it("keeps oversized generic maps with JSON or whitespace prefixes unresolved", async () => { const root = await createTestTempDirectory("rea-release-exposure-json-"); - const map = Buffer.alloc(MAX_RELEASE_EXPOSURE_SOURCE_MAP_BYTES + 1, 0x20); - map.write('{"version":3,"sources":[]}'); - await writeFile(join(root, "bundle.map"), map); - const scanned = await inspect(root); - expect(scanned.debug_companions).toEqual({ paths: [], skipped: 1 }); - expect(scanned.source_maps.skipped).toBe(1); - expect(scanned.text_members.skipped).toBe(1); - }); - - it("keeps whitespace-only prefixes of oversized maps unresolved", async () => { - const root = await createTestTempDirectory("rea-release-exposure-spaces-"); - await writeFile( - join(root, "bundle.map"), - Buffer.concat([ - Buffer.alloc(MAX_RELEASE_EXPOSURE_SOURCE_MAP_BYTES, 0x20), - embeddedSourceMap(), - ]), + const json = embeddedSourceMap(); + const whitespace = Buffer.alloc( + MAX_RELEASE_EXPOSURE_SOURCE_MAP_BYTES, + 0x20, ); + await writeFile(join(root, "json.map"), Buffer.concat([json, whitespace])); + await writeFile( + join(root, "spaces.map"), + Buffer.concat([whitespace, json]), + ); + const scanned = await inspect(root); - expect(scanned.source_maps.skipped).toBe(1); - expect(scanned.debug_companions).toEqual({ paths: [], skipped: 1 }); + expect(scanned.source_maps).toMatchObject({ + embedded: 0, + unparsed: 0, + skipped: 2, + }); + expect(scanned.debug_companions).toEqual({ paths: [], skipped: 2 }); + expect(scanned.text_members.skipped).toBe(2); }); it("does not spend the source-map allowance reading a JavaScript map past the count", async () => { @@ -4456,17 +4460,30 @@ describe("ReleaseExposureReader inline map reads", () => { const dataUrl = `data:application/json;base64,${map}`; - it.each([ - ["a classic script", "`; + await writeFile(join(root, "app.js"), "run();\n"); + await writeFile(join(root, "classic.html"), withMap("`, + join(root, "module.html"), + withMap('' + + '', + ); + const scanned = await inspect(root); - expect(scanned.source_maps).toMatchObject({ embedded: 1, skipped: 0 }); + expect(scanned.source_maps).toMatchObject({ + embedded: 2, + embedded_paths: [join(root, "classic.html"), join(root, "module.html")], + skipped: 0, + }); expect(sourceMapSourcesStatus(scanned)).toBe("exposed"); }); @@ -4487,19 +4504,6 @@ describe("ReleaseExposureReader inline map reads", () => { expect(sourceMapSourcesStatus(await inspect(path))).toBe("exposed"); }); - it("does not read a map in a data block or a script that loads by URL", async () => { - const root = await createTestTempDirectory("rea-release-exposure-html-"); - await writeFile(join(root, "app.js"), "run();\n"); - await writeFile( - join(root, "index.html"), - `` + - ``, - ); - const scanned = await inspect(root); - expect(scanned.source_maps).toMatchObject({ embedded: 0, skipped: 0 }); - expect(sourceMapSourcesStatus(scanned)).toBe("not_observed"); - }); - it("keeps HTML map coverage unknown for scripts it did not read", async () => { const root = await createTestTempDirectory("rea-release-exposure-html-"); const path = join(root, "index.html"); @@ -5105,24 +5109,6 @@ describe("ReleaseExposureReader map target allowance", () => { expect(debugCompanionsStatus(scanned)).toBe("unknown"); expect(scanned.source_maps.skipped).toBeGreaterThan(0); }); - - it("does not read a .map script past the target allowance as a linker map", async () => { - const baseBytes = 64 * 1024; - const references = Array.from( - { length: MAX_RELEASE_EXPOSURE_SCRIPT_TARGET_BYTES / baseBytes + 1 }, - (_, index) => ``, - ); - const root = await createTestTempDirectory("rea-release-exposure-maps-"); - await writeFile( - join(root, "a.html"), - `${references.join("")}`, - ); - await writeFile(join(root, "b.html"), ''); - await writeFile(join(root, "boot.map"), "run();\n"); - const scanned = await inspect(root); - expect(scanned.debug_companions.paths).toEqual([]); - expect(debugCompanionsStatus(scanned)).toBe("unknown"); - }); }); describe("ReleaseExposureReader script roles over a .map name", () => { @@ -5150,46 +5136,25 @@ describe("ReleaseExposureReader script roles over a .map name", () => { expect(scanned.debug_companions).toEqual({ paths: [], skipped: 0 }); }); - it("reads a .map script target whose bytes are a source map as a map", async () => { - const root = await createTestTempDirectory("rea-release-exposure-html-"); - await writeFile( - join(root, "index.html"), - '', - ); - await writeFile( - join(root, "main.map"), - JSON.stringify({ - version: 3, - sources: ["src/app.ts"], - sourcesContent: ["export {};"], - mappings: "", - }), - ); - const scanned = await inspect(root); - expect(scanned.source_maps).toMatchObject({ embedded: 1, skipped: 0 }); - expect(sourceMapSourcesStatus(scanned)).toBe("exposed"); - expect(scanned.debug_companions).toEqual({ paths: [], skipped: 0 }); - }); - it("reads a UTF-16 .map script target from the text that recognized it", async () => { const root = await createTestTempDirectory("rea-release-exposure-html-"); await writeFile( join(root, "index.html"), '', ); - const map = JSON.stringify({ - version: 3, - sources: ["src/app.ts"], - sourcesContent: ["export {};"], - mappings: "", - }); + const map = Buffer.from(embeddedSourceMap().toString("utf8"), "utf16le"); await writeFile( join(root, "main.map"), - Buffer.concat([Buffer.from([0xff, 0xfe]), Buffer.from(map, "utf16le")]), + Buffer.concat([Buffer.from([0xff, 0xfe]), map]), ); + const scanned = await inspect(root); - expect(scanned.source_maps).toMatchObject({ embedded: 1, skipped: 0 }); - expect(sourceMapSourcesStatus(scanned)).toBe("exposed"); + expect(scanned.source_maps).toMatchObject({ + embedded: 1, + embedded_paths: [join(root, "main.map")], + unparsed: 0, + skipped: 0, + }); expect(scanned.debug_companions).toEqual({ paths: [], skipped: 0 }); }); @@ -5216,9 +5181,8 @@ describe("ReleaseExposureReader script roles over a .map name", () => { ); for (const target of [root, archive]) { const scanned = await inspect(target); - expect(scanned.debug_companions.paths).toEqual([]); - expect(debugCompanionsStatus(scanned)).not.toBe("exposed"); - expect(scanned.source_maps.skipped).toBeGreaterThan(0); + expect(scanned.debug_companions).toEqual({ paths: [], skipped: 0 }); + expect(scanned.source_maps.skipped).toBe(1); expect(sourceMapSourcesStatus(scanned)).toBe("unknown"); } }); @@ -5243,17 +5207,6 @@ describe("ReleaseExposureReader HTML script references", () => { return root; }; - it("reads the inline map of an extensionless script an HTML file loads", async () => { - const scanned = await inspect( - await directory({ - "index.html": '', - main: inlineMap, - }), - ); - expect(scanned.source_maps).toMatchObject({ embedded: 1, skipped: 0 }); - expect(sourceMapSourcesStatus(scanned)).toBe("exposed"); - }); - it("reads an extensionless script an ASAR's HTML loads", async () => { const root = await createTestTempDirectory("rea-release-exposure-html-"); const path = join(root, "app.asar"); @@ -5270,44 +5223,37 @@ describe("ReleaseExposureReader HTML script references", () => { expect(sourceMapSourcesStatus(await inspect(path))).toBe("exposed"); }); - it("resolves a script against the document base", async () => { + it("resolves two pages' script URLs to the same extensionless member", async () => { const root = await directory({ - "index.html": '', + "a.html": '', + "z.html": '', }); await mkdir(join(root, "static")); - await writeFile(join(root, "static", "main"), inlineMap); - expect(sourceMapSourcesStatus(await inspect(root))).toBe("exposed"); - }); + const script = join(root, "static", "main"); + await writeFile(script, inlineMap); - it("does not count a script two pages share as unread", async () => { - const scanned = await inspect( - await directory({ - "a.html": '', - main: inlineMap, - "z.html": '', - }), - ); - expect(scanned.source_maps).toMatchObject({ embedded: 1, skipped: 0 }); - }); - - it("reads the scripts of a standalone SVG", async () => { - const scanned = await inspect( - await directory({ - "screen.svg": ``, - }), - ); - expect(scanned.source_maps.embedded).toBe(1); + const scanned = await inspect(root); + expect(scanned.source_maps).toMatchObject({ + embedded: 1, + embedded_paths: [script], + skipped: 0, + }); expect(sourceMapSourcesStatus(scanned)).toBe("exposed"); }); - it("finds nothing in an SVG without scripts", async () => { - const scanned = await inspect( - await directory({ - "icon.svg": - '', - }), - ); - expect(scanned.source_maps).toMatchObject({ embedded: 0, skipped: 0 }); + it("finds inline maps only in the standalone SVG that contains a script", async () => { + const root = await directory({ + "icon.svg": + '', + "screen.svg": ``, + }); + + const scanned = await inspect(root); + expect(scanned.source_maps).toMatchObject({ + embedded: 1, + embedded_paths: [join(root, "screen.svg")], + skipped: 0, + }); }); it("still reads a page another page loads as a script as HTML", async () => { @@ -5321,7 +5267,7 @@ describe("ReleaseExposureReader HTML script references", () => { expect(sourceMapSourcesStatus(scanned)).toBe("exposed"); }); - it("keeps a script past the target allowance unassessed", async () => { + it("keeps a .map script past the target allowance unassessed", async () => { const baseBytes = 64 * 1024; const references = Array.from( { length: MAX_RELEASE_EXPOSURE_SCRIPT_TARGET_BYTES / baseBytes + 1 }, @@ -5330,14 +5276,16 @@ describe("ReleaseExposureReader HTML script references", () => { const scanned = await inspect( await directory({ "a.html": `${references.join("")}`, - "b.html": '', - main: inlineMap, + "b.html": '', + "main.map": inlineMap, }), ); expect(scanned.source_maps).toMatchObject({ embedded: 0, - skipped: references.length + 1, + skipped: references.length + 2, }); + expect(debugCompanionsStatus(scanned)).toBe("unknown"); + expect(scanned.debug_companions).toEqual({ paths: [], skipped: 1 }); expect(sourceMapSourcesStatus(scanned)).toBe("unknown"); }); @@ -5371,20 +5319,6 @@ describe("ReleaseExposureReader HTML script references", () => { expect(scanned.source_maps.skipped).toBe(1); expect(sourceMapSourcesStatus(scanned)).toBe("unknown"); }); - - it("leaves coverage alone for remote, named, and data-block references", async () => { - const scanned = await inspect( - await directory({ - "app.js": "run();\n", - "index.html": - '' + - '' + - '', - }), - ); - expect(scanned.source_maps).toMatchObject({ embedded: 0, skipped: 0 }); - expect(sourceMapSourcesStatus(scanned)).toBe("not_observed"); - }); }); describe("ReleaseExposureReader cumulative text allowance", () => {