mirror of
https://github.com/morluto/rea.git
synced 2026-11-21 22:15:50 +00:00
test(asar): consolidate CLI hash-uncertainty coverage (#12951)
This commit is contained in:
1 parent
93aaf18e18
commit
2ff9917d20
1 file changed
+27
-28
@@ -3,16 +3,14 @@ import { join } from "node:path";
|
||||
import { createPackageWithOptions } from "@electron/asar";
|
||||
import { expect } from "vitest";
|
||||
import { z } from "zod";
|
||||
import { artifactInventorySummaryViewResultSchema } from "../../../src/domain/analysisView/analysisViewResult.js";
|
||||
import { ARTIFACT_INVENTORY_VIEW_CAVEATS } from "../../../src/domain/analysisView/artifactInventoryViewCaveats.js";
|
||||
import { parseEvidenceBundle } from "../../../src/domain/evidenceBundle.js";
|
||||
import { artifactInspectionResultSchema } from "../../../src/domain/artifactInspection.js";
|
||||
import { parseEvidence } from "../../../src/domain/evidence.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { cliTest } from "../../support/cli/cliFixture.js";
|
||||
|
||||
const summarySchema = z.object({
|
||||
unknowns: z.array(z.string()),
|
||||
summary: z.object({ source_complete: z.boolean() }),
|
||||
});
|
||||
|
||||
cliTest(
|
||||
"discloses unavailable ASAR content hashes in both summary routes and retains the parent",
|
||||
async ({ cli }) => {
|
||||
@@ -25,9 +23,7 @@ cliTest(
|
||||
const archive = join(root, "app.asar");
|
||||
await createPackageWithOptions(source, archive, { unpack: "*.node" });
|
||||
const companion = join(`${archive}.unpacked`, "native", "addon.node");
|
||||
const caveat =
|
||||
"Content hashes are unknown for some recorded files; missing node IDs do not prove content absence.";
|
||||
for (const phase of ["present", "missing", "restored"]) {
|
||||
for (const phase of ["missing", "restored"] as const) {
|
||||
if (phase === "missing") await rm(companion);
|
||||
if (phase === "restored") await writeFile(companion, bytes);
|
||||
const bundle = join(root, `${phase}-evidence.json`);
|
||||
@@ -43,16 +39,19 @@ cliTest(
|
||||
],
|
||||
});
|
||||
expect(direct.exitCode).toBe(0);
|
||||
const compact = z
|
||||
.object({ summary: z.object({ normalized_result: summarySchema }) })
|
||||
.parse(direct.json);
|
||||
const retained = z
|
||||
.object({ records: z.array(z.unknown()) })
|
||||
.parse(JSON.parse(await readFile(bundle, "utf8")));
|
||||
const parent = retained.records
|
||||
.map(parseEvidence)
|
||||
.find((record) => record.operation === "inspect_artifact");
|
||||
expect(parent).toBeDefined();
|
||||
const delivered = z.object({ summary: z.unknown() }).parse(direct.json);
|
||||
const compact = artifactInventorySummaryViewResultSchema.parse(
|
||||
parseEvidence(delivered.summary).normalized_result,
|
||||
);
|
||||
const retained = parseEvidenceBundle(
|
||||
JSON.parse(await readFile(bundle, "utf8")),
|
||||
);
|
||||
const parent = retained.records.find(
|
||||
({ evidence_id }) => evidence_id === compact.parent_evidence_id,
|
||||
);
|
||||
if (parent === undefined)
|
||||
throw new Error("Delivery omitted the complete Evidence parent");
|
||||
expect(parent.operation).toBe("inspect_artifact");
|
||||
const request = join(root, "request.json");
|
||||
await writeFile(
|
||||
request,
|
||||
@@ -65,11 +64,9 @@ cliTest(
|
||||
arguments: ["inspect-analysis-view", request, "--json"],
|
||||
});
|
||||
expect(inline.exitCode).toBe(0);
|
||||
const summary = summarySchema.parse(
|
||||
parseEvidence(inline.json).normalized_result,
|
||||
);
|
||||
const summary = parseEvidence(inline.json).normalized_result;
|
||||
const inspection = artifactInspectionResultSchema.parse(
|
||||
parent!.normalized_result,
|
||||
parent.normalized_result,
|
||||
);
|
||||
const occurrence = inspection.substeps
|
||||
.flatMap((step) => step.evidence.normalized_result.occurrences)
|
||||
@@ -78,12 +75,14 @@ cliTest(
|
||||
hash_status: phase === "missing" ? "unavailable" : "verified",
|
||||
...(phase === "missing" ? { artifact_id: null } : {}),
|
||||
});
|
||||
for (const result of [compact.summary.normalized_result, summary]) {
|
||||
expect(result.summary.source_complete).toBe(true);
|
||||
expect(result.unknowns.includes(caveat), phase).toBe(
|
||||
phase === "missing",
|
||||
);
|
||||
}
|
||||
expect(summary).toEqual(compact);
|
||||
expect(compact.summary.source_complete).toBe(true);
|
||||
expect(
|
||||
compact.unknowns.includes(
|
||||
ARTIFACT_INVENTORY_VIEW_CAVEATS.unknownContentHashes,
|
||||
),
|
||||
phase,
|
||||
).toBe(phase === "missing");
|
||||
}
|
||||
},
|
||||
);
|
||||
Reference in new issue
Block a user