diff --git a/src/domain/analysisView/machoView.test.ts b/src/domain/analysisView/machoView.test.ts index b396cb090d7..523fae56d42 100644 --- a/src/domain/analysisView/machoView.test.ts +++ b/src/domain/analysisView/machoView.test.ts @@ -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; + +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",