test(nuget): share parser report fixture (#15851)

This commit is contained in:
Vincent Koc authored and GitHub committed 2026-12-02 08:51:56 +00:00
1 parent 95ac5084cc
commit 3f4e24bced
1 file changed
+23 -78
+23 -78
View File
@@ -40,6 +40,11 @@ const artifactOf = (bytes: Uint8Array) => ({
bytes: bytes.length,
});
const parseFixtureReport = async (bytes: Uint8Array) =>
nugetNupkgSchema.parse(
await parseNugetNupkg(bufferByteSource(bytes), artifactOf(bytes), defaults),
);
it("redacts an unfollowed authority manifest target before package-path normalization", async () => {
const bytes = await nugetNupkgFixture({
relsTarget: "//user:password@feed.invalid/missing.nuspec?token=visible",
@@ -90,9 +95,7 @@ it("preserves a non-Error ZIP failure without classifying the package as malform
it("reads identity, license, repository, dependency groups and folder roles", async () => {
const bytes = await nugetNupkgFixture();
const report = nugetNupkgSchema.parse(
await parseNugetNupkg(bufferByteSource(bytes), artifactOf(bytes), defaults),
);
const report = await parseFixtureReport(bytes);
expect(report.identity).toEqual({
id: "Demo.Package",
version: "1.2.3",
@@ -157,9 +160,7 @@ it("keeps the stored ZIP member name beside its logical path", async () => {
const bytes = await nugetNupkgFixture({
extraMembers: { "./lib/net8.0/Extra.txt": "x" },
});
const report = nugetNupkgSchema.parse(
await parseNugetNupkg(bufferByteSource(bytes), artifactOf(bytes), defaults),
);
const report = await parseFixtureReport(bytes);
expect(
report.contents.find((entry) => entry.path === "lib/net8.0/Extra.txt"),
).toMatchObject({
@@ -177,9 +178,7 @@ it("records ungrouped dependencies as a group with a null target framework", asy
nuspec: ungroupedNuspec,
includeRels: false,
});
const report = nugetNupkgSchema.parse(
await parseNugetNupkg(bufferByteSource(bytes), artifactOf(bytes), defaults),
);
const report = await parseFixtureReport(bytes);
expect(report.nuspec?.source).toBe("root-nuspec");
expect(report.dependency_groups).toEqual([
{
@@ -216,13 +215,7 @@ it.for([
nuspec: ungroupedNuspec.replace("<dependencies>", opening!),
includeRels: false,
});
const report = nugetNupkgSchema.parse(
await parseNugetNupkg(
bufferByteSource(bytes),
artifactOf(bytes),
defaults,
),
);
const report = await parseFixtureReport(bytes);
expect(report.dependency_groups).toEqual([
{
target_framework: "net8.0",
@@ -245,9 +238,7 @@ it.for([
it("inventories a package with no .nuspec and leaves identity unknown", async () => {
const bytes = await nugetNupkgMissingNuspecFixture();
const report = nugetNupkgSchema.parse(
await parseNugetNupkg(bufferByteSource(bytes), artifactOf(bytes), defaults),
);
const report = await parseFixtureReport(bytes);
expect(report.identity).toBeNull();
expect(report.nuspec).toBeNull();
expect(report.contents.some((entry) => entry.role === "lib")).toBe(true);
@@ -256,9 +247,7 @@ it("inventories a package with no .nuspec and leaves identity unknown", async ()
it("inventories a package with an ambiguous pair of root .nuspec members", async () => {
const bytes = await nugetNupkgAmbiguousNuspecFixture();
const report = nugetNupkgSchema.parse(
await parseNugetNupkg(bufferByteSource(bytes), artifactOf(bytes), defaults),
);
const report = await parseFixtureReport(bytes);
expect(report.identity).toBeNull();
expect(report.nuspec).toBeNull();
expect(
@@ -269,9 +258,7 @@ it("inventories a package with an ambiguous pair of root .nuspec members", async
it("inventories a package whose .nuspec is not well-formed XML", async () => {
const bytes = await nugetNupkgMalformedNuspecFixture();
const report = nugetNupkgSchema.parse(
await parseNugetNupkg(bufferByteSource(bytes), artifactOf(bytes), defaults),
);
const report = await parseFixtureReport(bytes);
expect(report.identity).toBeNull();
expect(report.nuspec?.path).toBe("Demo.Package.nuspec");
expect(report.limitations).toContain(NUPKG_LIMITATIONS.malformedNuspec);
@@ -282,9 +269,7 @@ it("counts an unreadable manifest's bytes and keeps its selected path", async ()
const writer = new ZipWriter(new Uint8ArrayWriter());
await writer.add("Demo.Package.nuspec", new Uint8ArrayReader(manifest));
const bytes = await writer.close();
const report = nugetNupkgSchema.parse(
await parseNugetNupkg(bufferByteSource(bytes), artifactOf(bytes), defaults),
);
const report = await parseFixtureReport(bytes);
expect(report).toMatchObject({
identity: null,
license: null,
@@ -617,13 +602,7 @@ it.each([
"content/Other.nuspec": ungroupedNuspec,
},
});
const report = nugetNupkgSchema.parse(
await parseNugetNupkg(
bufferByteSource(bytes),
artifactOf(bytes),
defaults,
),
);
const report = await parseFixtureReport(bytes);
expect(report.nuspec).toMatchObject({
path: selected ? "content/Other.nuspec" : "Demo.Package.nuspec",
source: selected ? "opc-relationship" : "root-nuspec",
@@ -750,13 +729,7 @@ it.for(["manifests/./Actual.nuspec", "/manifests/extra/../Actual.nuspec"])(
"manifests/Actual.nuspec": ungroupedNuspec,
},
});
const report = nugetNupkgSchema.parse(
await parseNugetNupkg(
bufferByteSource(bytes),
artifactOf(bytes),
defaults,
),
);
const report = await parseFixtureReport(bytes);
expect(report.nuspec).toMatchObject({
path: "manifests/Actual.nuspec",
source: "opc-relationship",
@@ -770,9 +743,7 @@ it("does not follow a manifest relationship Target that resolves above the packa
includeRels: false,
extraMembers: { "_rels/.rels": manifestRels("../Actual.nuspec") },
});
const report = nugetNupkgSchema.parse(
await parseNugetNupkg(bufferByteSource(bytes), artifactOf(bytes), defaults),
);
const report = await parseFixtureReport(bytes);
expect(report.limitations).toContain(
'OPC manifest relationship Target "../Actual.nuspec" leaves the package and was not followed.',
);
@@ -794,13 +765,7 @@ it.for([true, false])(
const bytes = await nugetNupkgFixture({
nuspecBytes: utf16Nuspec(littleEndian),
});
const report = nugetNupkgSchema.parse(
await parseNugetNupkg(
bufferByteSource(bytes),
artifactOf(bytes),
defaults,
),
);
const report = await parseFixtureReport(bytes);
expect(report.identity?.id).toBe("Ungrouped.Package");
expect(report.dependency_groups).not.toEqual([]);
},
@@ -872,9 +837,7 @@ it("reads manifest text written as CDATA and as mixed text and CDATA", async ()
"<description>A <![CDATA[& B]]> C</description>",
),
});
const report = nugetNupkgSchema.parse(
await parseNugetNupkg(bufferByteSource(bytes), artifactOf(bytes), defaults),
);
const report = await parseFixtureReport(bytes);
expect(report.identity).toMatchObject({
id: "Ungrouped.Package",
description: "A & B C",
@@ -890,9 +853,7 @@ it("applies XML end-of-line handling to manifest text", async () => {
"<description>First line.\r\nSecond line.\rThird line.</description>",
),
});
const report = nugetNupkgSchema.parse(
await parseNugetNupkg(bufferByteSource(bytes), artifactOf(bytes), defaults),
);
const report = await parseFixtureReport(bytes);
expect(report.identity?.description).toBe(
"First line.\nSecond line.\nThird line.",
);
@@ -902,13 +863,7 @@ it.for(["constructor/file.txt", "__proto__/file.txt", "toString/file.txt"])(
"keeps payload folder %s at the unknown role",
async (name) => {
const bytes = await nugetNupkgFixture({ extraMembers: { [name]: "x" } });
const report = nugetNupkgSchema.parse(
await parseNugetNupkg(
bufferByteSource(bytes),
artifactOf(bytes),
defaults,
),
);
const report = await parseFixtureReport(bytes);
expect(report.contents.find((entry) => entry.path === name)?.role).toBe(
"unknown",
);
@@ -926,13 +881,7 @@ it.each(["/FIRST.nuspec", "/First.nuspec", "/first.nuspec"])(
"first.nuspec": ungroupedNuspec,
},
});
const report = nugetNupkgSchema.parse(
await parseNugetNupkg(
bufferByteSource(bytes),
artifactOf(bytes),
defaults,
),
);
const report = await parseFixtureReport(bytes);
expect(report.identity).toBeNull();
expect(report.nuspec).toBeNull();
expect(report.coverage).toMatchObject({
@@ -1015,9 +964,7 @@ it("follows no relationships when two members normalize to _rels/.rels", async (
"content/Other.nuspec": ungroupedNuspec,
},
});
const report = nugetNupkgSchema.parse(
await parseNugetNupkg(bufferByteSource(bytes), artifactOf(bytes), defaults),
);
const report = await parseFixtureReport(bytes);
expect(report.nuspec).toMatchObject({
path: "Demo.Package.nuspec",
source: "root-nuspec",
@@ -1040,9 +987,7 @@ it("reports unknown coverage when the central directory leaves bytes unaccounted
packed.subarray(directory),
]);
bytes.writeUInt32LE(directory + hidden.length, eocd + hidden.length + 16);
const report = nugetNupkgSchema.parse(
await parseNugetNupkg(bufferByteSource(bytes), artifactOf(bytes), defaults),
);
const report = await parseFixtureReport(bytes);
expect(report.coverage.status).toBe("unknown");
expect(report.identity?.id).toBe("Demo.Package");
expect(