mirror of
https://github.com/morluto/rea.git
synced 2026-11-03 13:26:10 +00:00
* fix(artifacts): refuse thin Mach-O extraction before inventory Extraction admitted both Mach-O formats and fell through to the universal slice reader for a thin file, which yields a slices/<arch> entry that the root-only inventory never recorded. The writer then reported an integrity mismatch and recommended an integrity policy retry that cannot succeed. Only mach-o-universal has an extraction reader, matching the inventory reader selection. A thin Mach-O now receives the typed unsupported-target refusal before any inventory or output work. Refs #6098 * test(artifacts): cover the thin Mach-O extraction refusal A thin arm64e Mach-O image is refused with the typed unsupported-target error and no output directory is created. Refs #6098 * fix(artifacts): keep embedded packs behind a thin Mach-O extractable Refusing every thin Mach-O before inventory also refused PyInstaller onefile executables and embedded Godot packs whose bootloader is a thin Mach-O. Inventory classifies those roots as pyinstaller or godot-pck, and createReader selects that reader before the Mach-O fallback, so they were extractable on the parent revision. A thin Mach-O now takes the same embedded-pack probe as ELF and PE: a detected pack proceeds to inventory, and a plain image keeps the unsupported-target refusal. Refs #6098 * test(artifacts): cover a thin Mach-O PyInstaller onefile extraction Refs #6098
162 lines
5.4 KiB
TypeScript
162 lines
5.4 KiB
TypeScript
import { access, symlink, writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
import { writeOrderedZip } from "../../../fixtures/artifactEntryOrder.js";
|
|
import { createTestTempDirectory } from "../../../fixtures/temporaryDirectory.js";
|
|
|
|
import { ArtifactProvider } from "../../../../src/artifacts/ArtifactProvider.js";
|
|
import {
|
|
CPU,
|
|
machoImage,
|
|
} from "../../../../src/artifacts/apple/MachoImage.fixture.js";
|
|
import { cArchiveExecutable } from "../../../../src/artifacts/pyinstaller/CArchive.fixture.js";
|
|
import { artifactExtractionExecutionSchema } from "../../../../src/contracts/artifactToolContracts.js";
|
|
import { artifactExtractionResultSchema } from "../../../../src/domain/artifactGraph.js";
|
|
import type { BinaryTarget } from "../../../../src/domain/binaryTargetTypes.js";
|
|
|
|
describe("artifact extraction format support", () => {
|
|
it("refuses unsupported formats before inventory or output", async () => {
|
|
const root = await createTestTempDirectory("rea-extract-format-");
|
|
const image = join(root, "Image.dmg");
|
|
await writeFile(image, "not mounted");
|
|
const alias = join(root, "Alias.dmg");
|
|
await symlink(image, alias);
|
|
const output = join(root, "output");
|
|
const extract = (signal?: AbortSignal) =>
|
|
new ArtifactProvider(process.env)
|
|
.createClient(archiveTarget(alias, "dmg"))
|
|
.execute(
|
|
"extract_artifact",
|
|
artifactExtractionExecutionSchema.parse({ output_root: output }),
|
|
signal === undefined ? undefined : { signal },
|
|
);
|
|
expect(await extract()).toMatchObject({
|
|
ok: false,
|
|
error: {
|
|
_tag: "AnalysisUnsupportedTargetError",
|
|
operation: "extract_artifact",
|
|
path: alias,
|
|
reason: "Artifact format has no extraction reader: dmg",
|
|
},
|
|
});
|
|
const controller = new AbortController();
|
|
controller.abort();
|
|
expect(await extract(controller.signal)).toMatchObject({
|
|
ok: false,
|
|
error: { _tag: "ArtifactOperationError", reason: "cancelled" },
|
|
});
|
|
await expect(access(output)).rejects.toThrow();
|
|
});
|
|
|
|
it("refuses a thin Mach-O that inventory lists as root-only", async () => {
|
|
const root = await createTestTempDirectory("rea-extract-thin-macho-");
|
|
const binary = join(root, "thin");
|
|
await writeFile(binary, machoImage({ cpu: CPU.arm64e }));
|
|
const output = join(root, "output");
|
|
expect(
|
|
await new ArtifactProvider(process.env)
|
|
.createClient(thinMachOTarget(binary))
|
|
.execute(
|
|
"extract_artifact",
|
|
artifactExtractionExecutionSchema.parse({ output_root: output }),
|
|
),
|
|
).toMatchObject({
|
|
ok: false,
|
|
error: {
|
|
_tag: "AnalysisUnsupportedTargetError",
|
|
operation: "extract_artifact",
|
|
path: binary,
|
|
reason: "Artifact format has no extraction reader: mach-o",
|
|
},
|
|
});
|
|
await expect(access(output)).rejects.toThrow();
|
|
});
|
|
|
|
it("keeps a thin Mach-O PyInstaller onefile extractable", async () => {
|
|
const root = await createTestTempDirectory("rea-extract-thin-macho-pyi-");
|
|
const binary = join(root, "hello");
|
|
await writeFile(
|
|
binary,
|
|
Buffer.concat([
|
|
machoImage({ cpu: CPU.arm64 }),
|
|
cArchiveExecutable({
|
|
layout: "2.1",
|
|
pythonVersion: 314,
|
|
pythonLibrary: "libpython3.14.dylib",
|
|
members: [
|
|
{
|
|
name: "hello",
|
|
typeCode: "s",
|
|
payload: Buffer.from("print('hi')"),
|
|
compress: true,
|
|
},
|
|
],
|
|
}),
|
|
]),
|
|
);
|
|
const result = await new ArtifactProvider(process.env)
|
|
.createClient(thinMachOTarget(binary))
|
|
.execute(
|
|
"extract_artifact",
|
|
artifactExtractionExecutionSchema.parse({
|
|
output_root: join(root, "output"),
|
|
}),
|
|
);
|
|
if (!result.ok) throw result.error;
|
|
const extracted = artifactExtractionResultSchema.parse(result.value.result);
|
|
expect(
|
|
extracted.artifacts.map(({ relative_path }) => relative_path),
|
|
).toContain("hello");
|
|
});
|
|
|
|
it.each(["zip", "hap", "hsp", "app-pack"] as const)(
|
|
"extracts the ZIP-backed %s package family that inventory already supports",
|
|
async (format) => {
|
|
const root = await createTestTempDirectory("rea-extract-zip-family-");
|
|
const archive = join(
|
|
root,
|
|
`Payload.${format === "app-pack" ? "app" : format}`,
|
|
);
|
|
await writeOrderedZip(archive, ["payload.txt"]);
|
|
const result = await new ArtifactProvider(process.env)
|
|
.createClient(archiveTarget(archive, format))
|
|
.execute(
|
|
"extract_artifact",
|
|
artifactExtractionExecutionSchema.parse({
|
|
output_root: join(root, "output"),
|
|
}),
|
|
);
|
|
if (!result.ok) throw result.error;
|
|
const extracted = artifactExtractionResultSchema.parse(
|
|
result.value.result,
|
|
);
|
|
expect(
|
|
extracted.artifacts.map(({ relative_path }) => relative_path),
|
|
).toEqual(["payload.txt"]);
|
|
},
|
|
);
|
|
});
|
|
|
|
const archiveTarget = (
|
|
path: string,
|
|
format: Extract<BinaryTarget, { kind: "archive" }>["format"],
|
|
): BinaryTarget => ({
|
|
path,
|
|
sourcePath: path,
|
|
sha256: "0".repeat(64),
|
|
kind: "archive",
|
|
format,
|
|
});
|
|
|
|
const thinMachOTarget = (path: string): BinaryTarget => ({
|
|
path,
|
|
sourcePath: path,
|
|
sha256: "0".repeat(64),
|
|
kind: "executable",
|
|
format: "mach-o",
|
|
architecture: "arm64",
|
|
availableArchitectures: ["arm64"],
|
|
});
|