From e7ea60ace19eba45ba12febcc92b64279ad3aed6 Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Thu, 19 Nov 2026 20:49:51 -0500 Subject: [PATCH] fix(deno): retain valid specifiers beside undecodable rows (#12667) --- src/artifacts/DenoStandaloneArtifactReader.ts | 3 +- src/artifacts/deno/DenoSectionLayout.test.ts | 22 +++-- src/artifacts/deno/DenoSectionLayout.ts | 26 +++--- .../deno/DenoStandaloneArtifactReader.test.ts | 83 +++++++++++-------- 4 files changed, 75 insertions(+), 59 deletions(-) diff --git a/src/artifacts/DenoStandaloneArtifactReader.ts b/src/artifacts/DenoStandaloneArtifactReader.ts index bce60859f1..e66aaba097 100644 --- a/src/artifacts/DenoStandaloneArtifactReader.ts +++ b/src/artifacts/DenoStandaloneArtifactReader.ts @@ -487,8 +487,7 @@ const remoteDestination = ( module: DenoRemoteModule, ): RemoteDestination => { const fallback = `deno-remote/${String(module.index)}`; - // A listed remote table has every specifier. Missing text is unsupported. - const text = section.specifierText?.get(module.specifierId) ?? null; + const text = section.specifierText.get(module.specifierId) ?? null; if (text === null) return { path: fallback, diff --git a/src/artifacts/deno/DenoSectionLayout.test.ts b/src/artifacts/deno/DenoSectionLayout.test.ts index 24302daa90..31225c96cd 100644 --- a/src/artifacts/deno/DenoSectionLayout.test.ts +++ b/src/artifacts/deno/DenoSectionLayout.test.ts @@ -91,7 +91,7 @@ it("parses metadata, tables, remote regions, and embedded configuration", async data: { length: original.length }, transpiled: { length: transpiled.length }, }); - expect(parsed.specifierText?.get(1)).toBe("https://example.com/mod.ts"); + expect(parsed.specifierText.get(1)).toBe("https://example.com/mod.ts"); expect(parsed.vfs.listing).toBe("listed"); expect(parsed.vfs.members[0]).toMatchObject({ role: "vfs-file", @@ -215,7 +215,7 @@ it("stops on unrecognized remote flags and duplicate specifier ids", async () => parseDenoSectionBytes( buildDenoSection({ specifiers: [ - { text: "file:///a.ts", id: 0 }, + { bytes: Buffer.from([0xff]), id: 0 }, { text: "file:///b.ts", id: 0 }, ], }), @@ -226,14 +226,22 @@ it("stops on unrecognized remote flags and duplicate specifier ids", async () => }); }); -it("reports an invalid specifier as an unsupported listing", async () => { +it("limits unsupported listings to the tables that need invalid specifier text", async () => { const parsed = await parseDenoSectionBytes( buildDenoSection({ - specifiers: [{ bytes: Buffer.from([0xff]), id: 0 }], + specifiers: [ + { bytes: Buffer.from([0xff]), id: 0 }, + { text: "https://example.com/mod.ts", id: 1 }, + { text: "https://example.com/start.ts", id: 2 }, + ], + redirects: [{ from: 2, to: 1 }], + remoteModules: [{ specifierId: 1, data: "known" }], }), ); expect(parsed.specifiers.listing).toBe("unsupported"); - expect(parsed.specifierText).toBeNull(); + expect(parsed.redirects.listing).toBe("listed"); + expect(parsed.remoteModules.listing).toBe("listed"); + expect(parsed.specifierText.get(0)).toBeNull(); }); it("keeps decoded specifiers when another remote id is missing", async () => { @@ -247,8 +255,8 @@ it("keeps decoded specifiers when another remote id is missing", async () => { }), ); expect(parsed.remoteModules.listing).toBe("unsupported"); - expect(parsed.specifierText?.get(1)).toBe("https://example.com/mod.ts"); - expect(parsed.specifierText?.has(2)).toBe(false); + expect(parsed.specifierText.get(1)).toBe("https://example.com/mod.ts"); + expect(parsed.specifierText.has(2)).toBe(false); }); it("honors cancellation before parsing", async () => { diff --git a/src/artifacts/deno/DenoSectionLayout.ts b/src/artifacts/deno/DenoSectionLayout.ts index 73e9a0b2c4..7b5baca751 100644 --- a/src/artifacts/deno/DenoSectionLayout.ts +++ b/src/artifacts/deno/DenoSectionLayout.ts @@ -111,8 +111,8 @@ export interface DenoParsedSection { readonly vfsHeaderByteLength: number; readonly vfsFileData: DenoByteRange; readonly vfs: DenoVfsWalk; - /** Specifier text when every specifier was valid UTF-8. */ - readonly specifierText: ReadonlyMap | null; + /** Declared specifier IDs. A null value identifies a row with invalid UTF-8. */ + readonly specifierText: ReadonlyMap; } export type DenoSectionRead = ( @@ -201,8 +201,7 @@ export const parseDenoSection = async ( const specifierStart = cursor; const specifierCount = await u32(); assertTableCount(specifierCount, "specifier"); - const specifierIds = new Set(); - const specifierText = new Map(); + const specifierText = new Map(); let textBytes = 0; let invalidUtf8 = false; for (let index = 0; index < specifierCount; index += 1) { @@ -218,26 +217,25 @@ export const parseDenoSection = async ( ); const bytes = await readExact(range.sectionOffset, range.length); const id = await u32(); - if (specifierIds.has(id)) + if (specifierText.has(id)) throw denoFormatFailure(`duplicate specifier id ${String(id)}`); - specifierIds.add(id); const decoded = decodeStrict(bytes, specifierDecoder); if (decoded === undefined) invalidUtf8 = true; - else specifierText.set(id, decoded); + specifierText.set(id, decoded ?? null); } const specifiers: DenoCountedRegion = { count: specifierCount, byteLength: Number(cursor - specifierStart), listing: invalidUtf8 ? "unsupported" : "listed", }; - const namedSpecifiers = invalidUtf8 ? null : specifierText; + const hasSpecifierText = (id: number): boolean => + typeof specifierText.get(id) === "string"; const redirectStart = cursor; const redirectCount = await u32(); assertTableCount(redirectCount, "redirect"); const redirectIds = new Set(); - let redirectListing: DenoListing = - namedSpecifiers === null ? "unsupported" : "listed"; + let redirectListing: DenoListing = "listed"; for (let index = 0; index < redirectCount; index += 1) { abortIfNeeded(signal); const from = await u32(); @@ -247,7 +245,7 @@ export const parseDenoSection = async ( `duplicate redirect specifier id ${String(from)}`, ); redirectIds.add(from); - if (!specifierIds.has(from) || !specifierIds.has(to)) + if (!hasSpecifierText(from) || !hasSpecifierText(to)) redirectListing = "unsupported"; } const redirects: DenoCountedRegion = { @@ -267,7 +265,7 @@ export const parseDenoSection = async ( remoteBodies = addRemoteBody(remoteBodies, length); return range; }; - let unresolvedRemote = namedSpecifiers === null; + let unresolvedRemote = false; for (let index = 0; index < remoteCount; index += 1) { abortIfNeeded(signal); const specifierId = await u32(); @@ -276,7 +274,7 @@ export const parseDenoSection = async ( `duplicate remote specifier id ${String(specifierId)}`, ); remoteIds.add(specifierId); - if (namedSpecifiers?.has(specifierId) !== true) unresolvedRemote = true; + if (!hasSpecifierText(specifierId)) unresolvedRemote = true; const mediaType = await u8(); const data = takeRemoteBody(await u32(), "remote module"); const flags = await u8(); @@ -344,7 +342,7 @@ export const parseDenoSection = async ( vfsHeaderByteLength: vfsHeader.length, vfsFileData, vfs: walkDenoVirtualFs(vfsJson, vfsFileData.length, signal), - specifierText: namedSpecifiers, + specifierText, }; }; diff --git a/src/artifacts/deno/DenoStandaloneArtifactReader.test.ts b/src/artifacts/deno/DenoStandaloneArtifactReader.test.ts index e0605031e3..645c69928b 100644 --- a/src/artifacts/deno/DenoStandaloneArtifactReader.test.ts +++ b/src/artifacts/deno/DenoStandaloneArtifactReader.test.ts @@ -329,42 +329,53 @@ it("reports cancellation and keeps indexed paths for an unsupported remote listi }); }); -it("keeps a resolved remote module beside one with a missing specifier", async () => { - const url = "https://example.com/mod.ts"; - const snapshot = await inventoryOf( - "partial-remote", - denoElf( - buildDenoSection({ - metadata: { ...defaultDenoMetadata(), entrypoint_key: url }, - specifiers: [{ text: url, id: 1 }], - remoteModules: [ - { specifierId: 1, data: "known" }, - { specifierId: 2, data: "missing" }, - ], - }), - ), - ); - expect( - snapshot.occurrences.find((row) => row.logical_path === "."), - ).toMatchObject({ - format_metadata: { remote_module_listing: "unsupported" }, - }); - expect( - snapshot.occurrences.find( - (row) => row.logical_path === "deno-remote/example.com/mod.ts", - ), - ).toMatchObject({ - format_metadata: { source_path: url, entry_point: true }, - }); - expect( - snapshot.occurrences.find((row) => row.logical_path === "deno-remote/1"), - ).toMatchObject({ - format_metadata: { source_path: null, entry_point: false }, - limitations: expect.arrayContaining([ - expect.stringContaining("not available as a logical path"), - ]), - }); -}); +it.each(["missing", "invalid UTF-8"] as const)( + "keeps a resolved remote module beside a %s specifier", + async (specifier) => { + const url = "https://example.com/mod.ts"; + const snapshot = await inventoryOf( + "partial-remote", + denoElf( + buildDenoSection({ + metadata: { ...defaultDenoMetadata(), entrypoint_key: url }, + specifiers: [ + { text: url, id: 1 }, + ...(specifier === "invalid UTF-8" + ? [{ bytes: Buffer.from([0xff]), id: 2 }] + : []), + ], + remoteModules: [ + { specifierId: 1, data: "known" }, + { specifierId: 2, data: "missing" }, + ], + }), + ), + ); + expect( + snapshot.occurrences.find((row) => row.logical_path === "."), + ).toMatchObject({ + format_metadata: { + specifier_listing: specifier === "missing" ? "listed" : "unsupported", + remote_module_listing: "unsupported", + }, + }); + expect( + snapshot.occurrences.find( + (row) => row.logical_path === "deno-remote/example.com/mod.ts", + ), + ).toMatchObject({ + format_metadata: { index: 0, source_path: url, entry_point: true }, + }); + expect( + snapshot.occurrences.find((row) => row.logical_path === "deno-remote/1"), + ).toMatchObject({ + format_metadata: { index: 1, source_path: null, entry_point: false }, + limitations: expect.arrayContaining([ + expect.stringContaining("not available as a logical path"), + ]), + }); + }, +); it.each([ ["a port", "http://localhost:8000/mod.ts", "localhost%3A8000/mod.ts"],