test(macho): share analysis view page fixtures (#17088)

This commit is contained in:
Vincent Koc authored and GitHub committed 2026-12-05 21:45:21 +08:00
1 parent 1b0b5a6e8f
commit 8a58154f6a
1 file changed
+17 -48
+17 -48
View File
@@ -4,9 +4,18 @@ import { inspectMachoSchema } from "../native/nativeInspection.js";
import { projectAnalysisView } from "./analysisView.js";
import type { AnalysisViewParent } from "./analysisViewParent.js";
import type { AnalysisViewRequest } from "./analysisViewRequest.js";
import { evidenceSubject } from "../evidence.js";
import { analysisViewResultSchema } from "./analysisViewResult.js";
type MachoPage = Extract<AnalysisViewRequest, { kind: "macho" }>;
const machoPage = (
facet: MachoPage["facet"],
offset = 0,
limit = 64,
): MachoPage => ({ kind: "macho", facet, offset, limit });
it("binds every Mach-O facet to its rows, including empty pages", () => {
for (const facet of [
"entrypoints",
@@ -20,12 +29,7 @@ it("binds every Mach-O facet to its rows, including empty pages", () => {
"provenance",
] as const) {
for (const offset of [0, 999]) {
const projected = projectAnalysisView(parent(), {
kind: "macho",
facet,
offset,
limit: 64,
});
const projected = projectAnalysisView(parent(), machoPage(facet, offset));
if (!projected.ok) throw projected.error;
expect(analysisViewResultSchema.safeParse(projected.value).success).toBe(
true,
@@ -68,12 +72,7 @@ it("refuses symbols and encryption rows missing fields every producer writes", (
path,
);
expect(
projectAnalysisView(parent(source), {
kind: "macho",
facet: "encryption",
offset: 0,
limit: 10,
}).ok,
projectAnalysisView(parent(source), machoPage("encryption", 0, 10)).ok,
).toBe(false);
}
});
@@ -280,12 +279,7 @@ it("retains binary names and exact numbers alongside partial command fields", ()
["dependencies", dependency],
["load_commands", command],
] as const) {
const projected = projectAnalysisView(parent(observed), {
kind: "macho",
facet,
offset: 0,
limit: 64,
});
const projected = projectAnalysisView(parent(observed), machoPage(facet));
if (!projected.ok || projected.value.kind !== "macho")
throw new Error("Expected Mach-O page");
expect(projected.value.item).toEqual([expected]);
@@ -315,12 +309,7 @@ it("preserves ambiguous import facts without adding import fields to exports", (
};
const observed = { ...report, imports: coverage([imported], false) };
for (const facet of ["imports", "exports"] as const) {
const projected = projectAnalysisView(parent(observed), {
kind: "macho",
facet,
offset: 0,
limit: 64,
});
const projected = projectAnalysisView(parent(observed), machoPage(facet));
if (!projected.ok) throw projected.error;
expect(projected.value.kind === "macho" && projected.value.item).toEqual(
observed[facet].items,
@@ -360,12 +349,7 @@ describe("Mach-O analysis views", () => {
});
it("pages original rows with the producer's own coverage", () => {
const first = projectAnalysisView(parent(), {
kind: "macho",
facet: "imports",
offset: 1,
limit: 1,
});
const first = projectAnalysisView(parent(), machoPage("imports", 1, 1));
if (!first.ok) throw first.error;
expect(first.value).toMatchObject({
kind: "macho",
@@ -379,23 +363,13 @@ describe("Mach-O analysis views", () => {
);
// Rows whose keys include an earlier row shape's keys stay whole.
for (const facet of ["architectures", "segments", "encryption"] as const) {
const page = projectAnalysisView(parent(), {
kind: "macho",
facet,
offset: 0,
limit: 64,
});
const page = projectAnalysisView(parent(), machoPage(facet));
if (!page.ok) throw page.error;
expect(page.value.kind === "macho" && page.value.item).toEqual(
report[facet].items,
);
}
const provenance = projectAnalysisView(parent(), {
kind: "macho",
facet: "provenance",
offset: 0,
limit: 64,
});
const provenance = projectAnalysisView(parent(), machoPage("provenance"));
if (!provenance.ok) throw provenance.error;
expect(provenance.value).toMatchObject({
item: report.provenance,
@@ -403,12 +377,7 @@ describe("Mach-O analysis views", () => {
source_exhaustive: true,
coverage: { exhausted: true, next_offset: null },
});
const past = projectAnalysisView(parent(), {
kind: "macho",
facet: "exports",
offset: 5,
limit: 64,
});
const past = projectAnalysisView(parent(), machoPage("exports", 5));
if (!past.ok) throw past.error;
expect(past.value.coverage).toMatchObject({
status: "empty",