mirror of
https://github.com/morluto/rea
synced 2026-10-27 14:42:18 -04:00
76 lines
2.5 KiB
TypeScript
76 lines
2.5 KiB
TypeScript
import { createHash } from "node:crypto";
|
|
import { writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { build } from "plist";
|
|
import { expect, it } from "vitest";
|
|
import { createTestTempDirectory } from "../../tests/fixtures/temporaryDirectory.js";
|
|
import { scanCanonicalArtifactInventory } from "../../tests/fixtures/artifactInventory.js";
|
|
import {
|
|
NativeDmgArtifactReader,
|
|
type NativeDmgHost,
|
|
} from "./NativeDmgArtifactReader.js";
|
|
import { translateArtifactFailure } from "./ArtifactOperationFailure.js";
|
|
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
|
|
|
|
it("retains authenticated carrier facts and unknown child coverage when native attachment is unavailable", async () => {
|
|
const root = await createTestTempDirectory("rea-dmg-unavailable-root-");
|
|
const path = join(root, "image.dmg");
|
|
const bytes = Buffer.alloc(1024);
|
|
bytes.write("koly", bytes.length - 512, "ascii");
|
|
await writeFile(path, bytes);
|
|
const host: NativeDmgHost = {
|
|
run: async (args) => {
|
|
if (args[0] === "verify") return { stdout: "", exitCode: 0 };
|
|
if (args[0] === "info")
|
|
return { stdout: build({ images: [] }), exitCode: 0 };
|
|
if (args[0] === "attach")
|
|
return {
|
|
stdout: "",
|
|
stderr: "hdiutil: attach failed - Resource busy",
|
|
exitCode: 1,
|
|
};
|
|
throw new Error(`Unexpected command ${String(args[0])}`);
|
|
},
|
|
};
|
|
let failure: unknown;
|
|
try {
|
|
await scanCanonicalArtifactInventory(
|
|
path,
|
|
{},
|
|
() => new NativeDmgArtifactReader(path, {}, host),
|
|
);
|
|
} catch (cause: unknown) {
|
|
failure = cause;
|
|
}
|
|
expect(failure).toBeDefined();
|
|
const projected = projectAnalysisError(
|
|
translateArtifactFailure("inspect_artifact", failure),
|
|
);
|
|
expect(projected).toMatchObject({
|
|
category: "unavailable",
|
|
details: {
|
|
partial_observation: {
|
|
kind: "artifact-inventory",
|
|
inventory: {
|
|
manifest: {
|
|
root_sha256: createHash("sha256").update(bytes).digest("hex"),
|
|
root_format: "dmg",
|
|
},
|
|
coverage: { status: "unknown" },
|
|
occurrences: [{ logical_path: "." }],
|
|
provenance: [
|
|
{ arguments: ["verify", path], exit_code: 0 },
|
|
{
|
|
arguments: expect.arrayContaining(["attach", path]),
|
|
exit_code: 1,
|
|
},
|
|
],
|
|
},
|
|
},
|
|
},
|
|
});
|
|
expect(projected.details?.partial_observation).toEqual(
|
|
expect.objectContaining({ kind: "artifact-inventory" }),
|
|
);
|
|
});
|