test(nuget): consolidate filename provenance and retained Evidence checks (#13396)

This commit is contained in:
morluto authored and GitHub committed 2026-11-22 11:25:14 +00:00
1 parent 66c192a450
commit c45decb70b
4 files changed
+158 -169

No files matched your search

@@ -113,21 +113,3 @@ it("retains completed Evidence and caller selections on late cancellation", asyn
});
}
});
it.each([undefined, 67108864, 128])(
"preserves the caller's selected file budget %s",
async (maximum) => {
const input = {
path: report.artifact.path,
...(maximum === undefined ? {} : { max_file_bytes: maximum }),
};
const service = new NugetNupkgService({
close: async () => {},
identity,
inspect: async () => ok(report),
});
const result = await service.inspect(input);
if (!result.ok) throw result.error;
expect(result.value.parameters).toEqual(input);
},
);
+33 -28
View File
@@ -22,29 +22,25 @@ const report = {
dependency_groups: [
{
target_framework: "net8.0",
dependencies: [
{
id: "Newtonsoft.Json",
version: "13.0.1",
include: null,
exclude: null,
development_dependency: null,
},
],
},
],
contents: [
{
name: "./Demo.Package.nuspec",
path: "Demo.Package.nuspec",
uncompressed_size: 12,
compressed_size: 12,
role: "nuspec",
encrypted: false,
dependencies: ["Newtonsoft.Json", "Demo.Support"].map((id) => ({
id,
version: "13.0.1",
include: null,
exclude: null,
development_dependency: null,
})),
},
],
contents: ["Demo.Package.nuspec", "README.md", "build.props"].map((path) => ({
name: path,
path,
uncompressed_size: 12,
compressed_size: 12,
role: path.endsWith(".nuspec") ? "nuspec" : "unknown",
encrypted: false,
})),
nuspec: { path: "Demo.Package.nuspec", bytes: 12, source: "root-nuspec" },
coverage: { status: "complete", entries: 1, examined_nuspec_bytes: 12 },
coverage: { status: "unknown", entries: 3, examined_nuspec_bytes: 12 },
limitations: ["Package condition"],
};
@@ -60,7 +56,7 @@ const parent = (): AnalysisViewParent => {
operation: "inspect_nuget_nupkg",
parameters: {},
result: report,
limitations: ["Parent condition"],
limitations: ["Parent condition", "Selection condition"],
},
);
return {
@@ -73,9 +69,10 @@ const parent = (): AnalysisViewParent => {
};
};
it("summarizes NuGet package Evidence with identity and counts", () => {
it("keeps source coverage and both limitation owners in the retained summary", () => {
const input = parent();
const result = projectAnalysisView(
parent(),
input,
analysisViewRequestSchema.parse({ kind: "summary" }),
);
if (!result.ok) throw result.error;
@@ -83,11 +80,19 @@ it("summarizes NuGet package Evidence with identity and counts", () => {
expect(view.summary).toMatchObject({
identity: { id: "Demo.Package", version: "1.2.3" },
dependency_group_count: 1,
dependency_count: 1,
content_count: 1,
dependency_count: 2,
content_count: 3,
limitation_count: 1,
coverage: { status: "unknown", entries: 3, examined_nuspec_bytes: 12 },
});
expect(view.limitations).toEqual(
expect.arrayContaining(["Parent condition", "Package condition"]),
);
expect(view).toMatchObject({
parent_evidence_id: input.evidenceId,
parent_digest: input.evidenceId.slice(3),
coverage: { status: "complete-within-view", examined: 3, total: 3 },
});
expect(view.limitations).toEqual([
"Package condition",
"Parent condition",
"Selection condition",
]);
});
+29 -32
View File
@@ -7,67 +7,64 @@ import {
import { crc32 } from "node:zlib";
/** Real ZIP filename carriers and their independent, format-defined readings. */
export const NUPKG_NAME_ENCODING_CASES = [
const nupkgNameEncodingCases = [
{
encoding: "legacy",
rawName: Buffer.from("6c69622f6e6574382e302f822e646c6c", "hex"),
utf8: false,
unicodePath: null,
name: "lib/net8.0/é.dll",
uncertain: true,
},
{
encoding: "ascii",
rawName: Buffer.from("lib/net8.0/demo.dll"),
utf8: false,
unicodePath: null,
name: "lib/net8.0/demo.dll",
uncertain: false,
},
{
encoding: "utf8",
rawName: Buffer.from("lib/net8.0/é.dll"),
rawName: Buffer.from("lib/net8.0/π.dll"),
utf8: true,
unicodePath: null,
name: "lib/net8.0/é.dll",
uncertain: false,
},
{
encoding: "unicode-path",
rawName: Buffer.from("6c69622f6e6574382e302f822e646c6c", "hex"),
utf8: false,
unicodePath: "lib/net8.0/café.dll",
name: "lib/net8.0/café.dll",
uncertain: false,
},
] as const;
/** Inert package with an independently selected raw filename, EFS flag and Unicode Path claim. */
export const nugetNupkgNameEncodingFixture = async (
input: (typeof NUPKG_NAME_ENCODING_CASES)[number],
): Promise<Uint8Array> => {
/** Inert ZIP members use independently selected names, EFS flags and Unicode Path extras. */
export const nugetNupkgNameEncodingFixture = async (): Promise<Uint8Array> => {
const writer = new ZipWriter(new Uint8ArrayWriter(), {
encodeText: (text, type) =>
type === "filename" && text === "asset" ? input.rawName : undefined,
type === "filename"
? nupkgNameEncodingCases.find(({ encoding }) => encoding === text)
?.rawName
: undefined,
});
await writer.add("Demo.Package.nuspec", new TextReader(defaultNuspec), {
level: 0,
});
let unicodeField: Buffer | undefined;
if (input.unicodePath !== null) {
const name = Buffer.from(input.unicodePath);
unicodeField = Buffer.alloc(5 + name.length);
unicodeField[0] = 1;
unicodeField.writeUInt32LE(crc32(input.rawName), 1);
name.copy(unicodeField, 5);
await addText(writer, "Demo.Package.nuspec", defaultNuspec);
for (const {
encoding,
rawName,
utf8,
unicodePath,
} of nupkgNameEncodingCases) {
let extraField: Map<number, Uint8Array> | undefined;
if (unicodePath !== null) {
const name = Buffer.from(unicodePath);
const unicodeField = Buffer.alloc(5 + name.length);
unicodeField[0] = 1;
unicodeField.writeUInt32LE(crc32(rawName), 1);
name.copy(unicodeField, 5);
extraField = new Map([[0x7075, unicodeField]]);
}
await writer.add(encoding, new TextReader("benign asset bytes"), {
level: 0,
useUnicodeFileNames: utf8,
...(extraField === undefined ? {} : { extraField }),
});
}
await writer.add("asset", new TextReader("benign asset bytes"), {
level: 0,
useUnicodeFileNames: input.utf8,
...(unicodeField === undefined
? {}
: { extraField: new Map([[0x7075, unicodeField]]) }),
});
return writer.close();
};