test(nuget): share default parser fixture inputs (#16797)

This commit is contained in:
Vincent Koc authored and GitHub committed 2026-12-05 01:08:44 +08:00
1 parent c94607feb5
commit a1021066e1
1 file changed
+18 -61
+18 -61
View File
@@ -40,20 +40,17 @@ const artifactOf = (bytes: Uint8Array) => ({
bytes: bytes.length,
});
const parseFixture = (bytes: Uint8Array) =>
parseNugetNupkg(bufferByteSource(bytes), artifactOf(bytes), defaults);
const parseFixtureReport = async (bytes: Uint8Array) =>
nugetNupkgSchema.parse(
await parseNugetNupkg(bufferByteSource(bytes), artifactOf(bytes), defaults),
);
nugetNupkgSchema.parse(await parseFixture(bytes));
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",
});
const result = await parseNugetNupkg(
bufferByteSource(bytes),
artifactOf(bytes),
defaults,
);
const result = await parseFixture(bytes);
expect(JSON.stringify(result)).not.toContain("user:password");
expect(result.limitations.join(" ")).toContain(
"//feed.invalid/missing.nuspec?token=visible",
@@ -65,11 +62,7 @@ it("keeps missing manifest target provenance separate from its normalized lookup
const bytes = await nugetNupkgFixture({
relsTarget: "./part/../missing.nuspec",
});
const result = await parseNugetNupkg(
bufferByteSource(bytes),
artifactOf(bytes),
defaults,
);
const result = await parseFixture(bytes);
expect(result.limitations).toContain(
'OPC manifest relationship Target "./part/../missing.nuspec" is missing from the package; identity was not decoded from that path.',
);
@@ -85,9 +78,7 @@ it("preserves a non-Error ZIP failure without classifying the package as malform
throw cause;
});
try {
await expect(
parseNugetNupkg(bufferByteSource(bytes), artifactOf(bytes), defaults),
).rejects.toBe(cause);
await expect(parseFixture(bytes)).rejects.toBe(cause);
} finally {
enumeration.mockRestore();
}
@@ -636,11 +627,7 @@ it("uses the root nuspec when an unrelated relationship ends in /manifest", asyn
"content/Other.nuspec": ungroupedNuspec,
},
});
const report = await parseNugetNupkg(
bufferByteSource(bytes),
artifactOf(bytes),
defaults,
);
const report = await parseFixture(bytes);
expect(report.nuspec).toMatchObject({
path: "Demo.Package.nuspec",
source: "root-nuspec",
@@ -704,11 +691,7 @@ it.each([
"content/Other.nuspec": ungroupedNuspec,
},
});
const report = await parseNugetNupkg(
bufferByteSource(bytes),
artifactOf(bytes),
defaults,
);
const report = await parseFixture(bytes);
expect(report.nuspec).toMatchObject({
path: selected ? "content/Other.nuspec" : "Demo.Package.nuspec",
source: selected ? "opc-relationship" : "root-nuspec",
@@ -809,11 +792,9 @@ it.each([
return true;
});
try {
const failure: unknown = await parseNugetNupkg(
bufferByteSource(bytes),
artifactOf(bytes),
defaults,
).catch((cause: unknown) => cause);
const failure: unknown = await parseFixture(bytes).catch(
(cause: unknown) => cause,
);
expect(failure).toMatchObject(classification);
const wrapped =
failure instanceof ParseFailureError ? failure.cause : failure;
@@ -914,11 +895,7 @@ it.each([
"content/É.nuspec": ungroupedNuspec,
},
});
const report = await parseNugetNupkg(
bufferByteSource(bytes),
artifactOf(bytes),
defaults,
);
const report = await parseFixture(bytes);
expect(report.nuspec?.source).toBe(source);
expect(report.identity?.id).toBe(id);
const warnings = report.limitations.filter((line) =>
@@ -1008,11 +985,7 @@ it("follows multiple relationship spellings of a single physical manifest", asyn
"content/Other.nuspec": ungroupedNuspec,
},
});
const report = await parseNugetNupkg(
bufferByteSource(bytes),
artifactOf(bytes),
defaults,
);
const report = await parseFixture(bytes);
expect(report.nuspec).toMatchObject({
path: "content/Other.nuspec",
source: "opc-relationship",
@@ -1035,11 +1008,7 @@ it("keeps a foreign group from suppressing ungrouped NuGet dependencies", async
</metadata>
</package>`,
});
const result = await parseNugetNupkg(
bufferByteSource(bytes),
artifactOf(bytes),
defaults,
);
const result = await parseFixture(bytes);
expect(result.dependency_groups).toMatchObject([
{ target_framework: null, dependencies: [{ id: "Declared" }] },
]);
@@ -1061,11 +1030,7 @@ it("selects the first nonempty leaf for indexed publisher metadata", async () =>
"<ID>Ignored</ID><id>Ungrouped.Package</id>",
),
});
const report = await parseNugetNupkg(
bufferByteSource(bytes),
artifactOf(bytes),
defaults,
);
const report = await parseFixture(bytes);
expect(report.identity).toMatchObject({
id: "Ungrouped.Package",
authors: "First publisher",
@@ -1085,11 +1050,7 @@ it.each([
first + "<authors>Later</authors>",
),
});
const report = await parseNugetNupkg(
bufferByteSource(bytes),
artifactOf(bytes),
defaults,
);
const report = await parseFixture(bytes);
expect(report.identity?.authors).toBe(expected);
});
@@ -1100,11 +1061,7 @@ it("inherits xml:space for publisher text until the field resets it", async () =
.replace("<authors>Casey", '<authors xml:space="default"> Casey ')
.replace("Ungrouped dependencies.", " first\r\n second\r\n"),
});
const report = await parseNugetNupkg(
bufferByteSource(bytes),
artifactOf(bytes),
defaults,
);
const report = await parseFixture(bytes);
expect(report.identity).toMatchObject({
authors: "Casey",
description: " first\n second\n",