test(rust): consolidate carrier budgets and retained views (#12872)

* test(rust): consolidate authenticated dependency views

* test(rust): consolidate carrier and report budget checks
This commit is contained in:
morluto authored and GitHub committed 2026-11-20 10:50:58 -05:00
1 parent 5486394715
commit 75908cc1fa
4 files changed
+138 -154

No files matched your search

+25 -64
View File
@@ -6,7 +6,6 @@ import {
import { metadataReportSubjectFormat } from "../apple/machoTargetSelection.js";
import { binaryMetadataArchitecture } from "../binaryMetadataArchitecture.js";
import { createEvidence } from "../evidence.js";
import { freezeJsonSnapshot } from "../immutableJson.js";
import type { RustBinary } from "../rust/rustBinary.js";
import { projectAnalysisView } from "./analysisView.js";
import type { AnalysisViewParent } from "./analysisViewParent.js";
@@ -84,37 +83,6 @@ it("revalidates mutable and merely frozen Rust imports despite a claimed seal",
).toBe(false);
});
it.each([false, true])(
"pages historical Rust feature omissions with a sealed source: %s",
(sealed) => {
const previous = structuredClone(report);
const metadata = previous.auditable_metadata;
if (metadata === null) throw new Error("Expected Rust metadata");
const legacy = {
...previous,
auditable_metadata: {
...metadata,
packages: metadata.packages.map(
({ features: _features, ...pkg }) => pkg,
),
},
} as unknown as RustBinary;
if (sealed) freezeJsonSnapshot(legacy);
const input = { ...parent(legacy), sealedResult: sealed };
const result = projectAnalysisView(input, {
kind: "rust",
collection: "packages",
fields: ["features"],
offset: 0,
limit: 10,
});
if (!result.ok) throw result.error;
expect(result.value).toMatchObject({
page: { rows: [{ index: 0, features: null }] },
});
},
);
it("checks exact artifact identity and subject architecture for every Rust view", () => {
for (const changed of [
{ format: "pe" as const },
@@ -208,7 +176,6 @@ it("bounds inherited warnings and retains cycle counts without walking a cyclic
it("pages matching original indices and omits dependency vectors unless selected", () => {
const value = structuredClone(report);
expect(value.auditable_metadata?.packages[0]?.features).toEqual([]);
value.auditable_metadata!.packages.push({
name: "other",
version: "1",
@@ -262,38 +229,32 @@ it("pages matching original indices and omits dependency vectors unless selected
});
it.each(["packages", "edges"] as const)(
"distinguishes unavailable Rust %s from decoded empty records",
"reports decoded empty Rust %s as fully examined",
(collection) => {
for (const available of [false, true]) {
const metadata = report.auditable_metadata!;
const result = projectAnalysisView(
parent({
...report,
auditable_metadata: available
? {
...metadata,
packages: [],
root_package_index: null,
dependency_edges: [],
cyclic_dependency_indices: [],
}
: null,
}),
{ kind: "rust", collection, offset: 3, limit: 1 },
);
if (!result.ok) throw result.error;
expect(result.value.coverage).toEqual({
status: available ? "empty" : "unavailable",
examined: 0,
total: available ? 0 : null,
next_offset: null,
exhausted: available,
});
expect(result.value).toMatchObject({
source_coverage: {
embedded_records: available ? "complete" : "unknown",
const result = projectAnalysisView(
parent({
...report,
auditable_metadata: {
...report.auditable_metadata!,
packages: [],
root_package_index: null,
dependency_edges: [],
cyclic_dependency_indices: [],
},
});
}
}),
{ kind: "rust", collection, offset: 3, limit: 1 },
);
if (!result.ok) throw result.error;
expect(result.value).toMatchObject({
page: { collection, rows: [] },
source_coverage: { embedded_records: "complete" },
});
expect(result.value.coverage).toEqual({
status: "empty",
examined: 0,
total: 0,
next_offset: null,
exhausted: true,
});
},
);
+43 -9
View File
@@ -269,11 +269,6 @@ cliTest(
expect(fullReply.isError).not.toBe(true);
const full = parseEvidence(fullReply.structuredContent);
const report = rustBinarySchema.parse(full.normalized_result);
const explicit = await call("inspect_rust_binary", {
path,
detail: "complete",
});
expect(parseEvidence(explicit.structuredContent)).toEqual(full);
const selection = {
collection: "packages",
names: ["same"],
@@ -398,6 +393,11 @@ cliTest(
const captured = await call("inspect_rust_binary", { path });
expect(captured.isError, JSON.stringify(captured.content)).not.toBe(true);
const full = parseEvidence(captured.structuredContent);
const explicit = await call("inspect_rust_binary", {
path,
detail: "complete",
});
expect(parseEvidence(explicit.structuredContent)).toEqual(full);
const report = rustBinarySchema.parse(full.normalized_result);
const metadata = report.auditable_metadata;
if (metadata === null) throw new Error("Expected Rust dependency metadata");
@@ -429,6 +429,18 @@ cliTest(
await writeFile(record, JSON.stringify(historical));
await unlink(path);
const view = { kind: "rust", collection: "packages", fields: ["features"] };
const expected = {
parent_evidence_id: historical.evidence_id,
page: { rows: [{ index: 0, features: null }] },
};
const inline = await call("inspect_analysis_view", {
source: { kind: "inline", evidence: historical },
view,
});
expect(inline.isError, JSON.stringify(inline.content)).not.toBe(true);
expect(
parseEvidence(inline.structuredContent).normalized_result,
).toMatchObject(expected);
for (const source of [
{ kind: "retained-evidence", evidence_id: historical.evidence_id },
{ kind: "evidence-file", path: record },
@@ -444,10 +456,9 @@ cliTest(
],
});
expect(reply.exitCode, reply.stderr + JSON.stringify(reply.json)).toBe(0);
expect(parseEvidence(reply.json).normalized_result).toMatchObject({
parent_evidence_id: historical.evidence_id,
page: { rows: [{ index: 0, features: null }] },
});
expect(parseEvidence(reply.json).normalized_result).toMatchObject(
expected,
);
}
const imported = await call("import_evidence_bundle", { path: bundle });
expect(imported.isError, JSON.stringify(imported.content)).not.toBe(true);
@@ -500,6 +511,29 @@ cliTest(
runtime_dependencies: "unknown",
},
});
const collection = await call("inspect_analysis_view", {
source: {
kind: "retained-evidence",
evidence_id: view.parent_evidence_id,
},
view: { kind: "rust", collection: "edges", offset: 3, limit: 1 },
});
expect(collection.isError, JSON.stringify(collection.content)).not.toBe(
true,
);
expect(
parseEvidence(collection.structuredContent).normalized_result,
).toMatchObject({
page: { collection: "edges", rows: [] },
source_coverage: { embedded_records: "unknown" },
coverage: {
status: "unavailable",
examined: 0,
total: null,
next_offset: null,
exhausted: false,
},
});
const missing = join(root, "never-created");
for (const args of [
["--detail", "summary"],
+50 -44
View File
@@ -11,25 +11,6 @@ import {
import { elfFrameAllowanceFixture } from "../../fixtures/binaryDiagnostics/elfFrameAllowance.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
it("reports a recoverable compiler prefix without refusing the dependency report", async () => {
const root = await createTestTempDirectory("rea-rust-hash-budget-");
const path = join(root, "many-hashes.elf");
await writeFile(path, createRustHashOverflowImage());
const result = await new RustBinaryProvider().inspect({ path });
if (!result.ok) throw result.error;
expect(result.value.rustc_commit?.coverage).toMatchObject({
reason: "max_rustc_hashes",
effective_limit: 64,
limit: { parameter: "max_rustc_hashes", effective_value: 64 },
});
expect(result.value.auditable_metadata?.packages).toHaveLength(2);
expect(result.value.limitations).toContainEqual(
expect.stringContaining("rustc_commit.coverage.limit"),
);
// The producer names the contract field; the CLI renders its own option.
expect(result.value.limitations.join(" ")).not.toContain("--");
});
it("recovers the same complete Rust image after input and report budget changes", async () => {
const root = await createTestTempDirectory("rea-rust-input-budget-");
const path = join(root, "selected.elf");
@@ -141,7 +122,6 @@ it("describes compiler coverage from the retained result when report trimming dr
const trimmed = await inspect(admitted);
if (!trimmed.ok) throw trimmed.error;
expect(trimmed.value.rustc_commit).toBeNull();
expect(trimmed.value.auditable_metadata?.packages).toHaveLength(2);
const text = trimmed.value.limitations.join(" ");
// The reader's partial-prefix guidance referred to a record that no
// longer exists; the trimming guidance names its control directly.
@@ -176,32 +156,58 @@ it("reports byte trimming only when it removes a compiler path", async () => {
provider.inspect({ path, producer_limits: { output_bytes } });
const complete = await inspect(1024 * 1024);
if (!complete.ok) throw complete.error;
const hashes = complete.value.rustc_commit?.hashes.length;
expect(complete.value.rustc_commit?.coverage?.reason).toBe(
"max_rustc_hashes",
const commit = complete.value.rustc_commit;
if (commit === null) throw new Error("Expected a compiler-path prefix");
expect(commit.hashes).toHaveLength(64);
expect(commit.coverage).toMatchObject({
reason: "max_rustc_hashes",
effective_limit: 64,
limit: { parameter: "max_rustc_hashes", effective_value: 64 },
});
const guidance = complete.value.limitations.find((text) =>
text.includes("rustc_commit.coverage.limit"),
);
if (guidance === undefined)
throw new Error("Expected compiler-path guidance");
expect(guidance).not.toContain("--max-rustc-hashes");
expect(complete.value.auditable_metadata?.packages).toHaveLength(2);
const fullBytes = Buffer.byteLength(JSON.stringify(complete.value));
// Below the complete report, swapping the reader's guidance for the
// shorter trimming guidance can make every path fit again.
let keptEveryPath = 0;
for (let output = fullBytes - 1; output > fullBytes - 120; output -= 1) {
const result = await inspect(output);
if (!result.ok) continue;
const commit = result.value.rustc_commit;
if (commit === null) continue;
const text = result.value.limitations.join(" ");
if (commit.hashes.length === hashes) {
keptEveryPath += 1;
expect(commit, `output_bytes ${output}`).toEqual(
complete.value.rustc_commit,
);
expect(text).not.toContain("Compiler paths were omitted");
} else
expect(commit.coverage?.reason, `output_bytes ${output}`).toBe(
"report_bytes",
);
}
expect(keptEveryPath).toBeGreaterThan(0);
// Pick a budget halfway into the observed guidance's size. This leaves
// room for the existing prefix even if the numeric budget's width changes.
const tight = await inspect(
fullBytes - Math.floor(Buffer.byteLength(JSON.stringify(guidance)) / 2),
);
if (!tight.ok) throw tight.error;
expect(tight.value.rustc_commit).toEqual(commit);
expect(tight.value.limitations).not.toContain(guidance);
expect(tight.value).not.toHaveProperty("rustc_commit_omission");
expect(tight.value.auditable_metadata).toEqual(
complete.value.auditable_metadata,
);
const outputBytes =
fullBytes - Math.floor(Buffer.byteLength(JSON.stringify(commit)) / 2);
const trimmed = await inspect(outputBytes);
if (!trimmed.ok) throw trimmed.error;
const partial = trimmed.value.rustc_commit;
if (partial === null)
throw new Error("Expected some retained compiler paths");
expect(partial.hashes.length).toBeLessThan(commit.hashes.length);
expect(partial.hashes).toEqual(
commit.hashes.slice(0, partial.hashes.length),
);
expect(partial.coverage).toMatchObject({
status: "partial",
reason: "report_bytes",
effective_limit: outputBytes,
limit: {
parameter: "producer_limits.output_bytes",
effective_value: outputBytes,
},
});
expect(trimmed.value.auditable_metadata).toEqual(
complete.value.auditable_metadata,
);
} finally {
await provider.close();
}
+20 -37
View File
@@ -269,13 +269,6 @@ it.each([
field: "custom section name",
},
],
[
"a duplicate .dep-v0 custom section",
createRustWasmModule({
sections: [wasmCustomSection(".dep-v0", rustDependencyPayload())],
}),
{ kind: "malformed", format: "rust-auditable" },
],
[
"a second data section",
createRustWasmModule({ sections: [wasmSection(11, Buffer.from([0]))] }),
@@ -425,16 +418,6 @@ it("recognizes zero-virtual-size PE raw padding without accepting payload junk",
);
});
it("returns null metadata when the dependency section is absent", () => {
const image = readRustBinaryImage(
createRustImage({ format: "elf", omitSection: true }),
);
expect(image.auditable_metadata).toBeNull();
expect(image.rustc_commit?.hashes).toEqual([
{ hash: RUSTC_HASH, file_offset: 2048 },
]);
});
it.each([1, 2])(
"reads dependency metadata through ELF section-name compression %i",
(compressionType) => {
@@ -501,11 +484,24 @@ it("finds rustc paths in read-only ELF load data without section headers", () =>
expect(readRustBinaryImage(bytes).rustc_commit).toBeNull();
});
const thrown = (read: () => unknown): unknown => {
try {
read();
} catch (cause: unknown) {
return cause;
}
throw new Error("expected a container failure");
};
it("refuses a universal Mach-O container", () => {
expect(() => readRustBinaryImage(fat([0x0100000c]))).toThrow(
ParseFailureError,
);
expect(() => readRustBinaryImage(fat([0x0100000c]))).toThrow(/thin slice/);
const cause = thrown(() => readRustBinaryImage(fat([0x0100000c])));
expect(cause).toBeInstanceOf(ParseFailureError);
expect(cause).toMatchObject({
failure: {
kind: "unsupported",
detail: expect.stringContaining("thin slice"),
},
});
});
it("keeps the container's truncated failure and its facts unchanged", () => {
@@ -514,14 +510,6 @@ it("keeps the container's truncated failure and its facts unchanged", () => {
// p_memsz are at +32 and +40.
bytes.writeBigUInt64LE(BigInt(bytes.length) * 2n, 128 + 32);
bytes.writeBigUInt64LE(BigInt(bytes.length) * 2n, 128 + 40);
const thrown = (read: () => unknown): unknown => {
try {
read();
} catch (cause: unknown) {
return cause;
}
throw new Error("expected a container failure");
};
const container = thrown(() => readBinaryContainer(bytes, "elf-directory"));
const rust = thrown(() => readRustBinaryImage(bytes));
expect(rust).toBeInstanceOf(ParseFailureError);
@@ -540,14 +528,9 @@ it("does not read SHT_NOBITS dependency sections as stored bytes", () => {
const bytes = createRustImage({ format: "elf" });
// The fixture writes the .dep-v0 section header at byte 384.
bytes.writeUInt32LE(8, 384 + 4);
let metadata: unknown;
try {
metadata = readRustBinaryImage(bytes).auditable_metadata;
} catch (cause: unknown) {
expect(cause).toBeInstanceOf(ParseFailureError);
return;
}
expect(metadata).toBeNull();
expect(thrown(() => readRustBinaryImage(bytes))).toMatchObject({
failure: { kind: "malformed", format: "rust-auditable" },
});
});
it("reads a rustc path from a read-only ELF section whose name exceeds 64 bytes", () => {