mirror of
https://github.com/morluto/rea.git
synced 2026-11-24 13:18:39 +00:00
ArtifactReaderFailure("format") covered two different facts: target
bytes that violate their format, and a selected path that is not a
regular file. The shared selected-file projections
(projectOwnedArtifactInputFailure and classifyProviderFailure's file
step) mapped both to invalid_request with an invalid_format path
issue, so corrupt BEAM files and PE certificate table bodies were
reported as caller argument errors.
Split the reason at its producers:
- Path-kind refusals now use the existing "path" selection reason:
regular-file admission, the stable root, directory, ZIP, ASAR and
PyInstaller entries, dyld inputs, the UEFI flash source and extract
occurrence selection. They stay invalid_request.
- The BEAM parser and the PE certificate table parser raise the format
owner's ParseFailureError (malformed or truncated, format "beam" or
"pe-certificate-table"). A short file that does not start with FOR1
is malformed, not truncated. A PKCS#7 name encoding the decoder does
not implement is unsupported, not malformed.
- Short reads inside an admitted range (kernel module, kernel build
config, ELF unwind ranges) are integrity read-coverage failures,
because the file changed during the read.
- Internal contract breaks (stream chunk size, a non-Buffer keyed
archive chunk) are invariant violations; an impossible descriptor
byte count is an I/O failure.
The shared projections now treat only "path" as a selection error.
They take the malformed-target facts from the reader failure's own
parseFailure, which artifactParseFailure sets once from the owner's
ParseFailureError and rebuilt failures keep through primaryFacts.
ArtifactOperationError carries the same facts, so inspect_artifact
refusals (for example Android boot images) now include
details.format_failure, format, offset and field. Android boot entry
planning raises the format owner's malformed failure, and the
redundant shortcut and API-contract format branches are removed.
BREAKING CHANGE: callers that parse `code` see unsupported_target
instead of invalid_request for malformed or truncated bytes from
inspect_erlang_beam and from the inspect_pe_certificates certificate
table body. Truncated reads of a file that changed during
inspect_kernel_module, inspect_kernel_build_config and
inspect_elf_unwind_ranges now report artifact_changed. inspect_artifact
malformed and truncated refusals gain details.format_failure and
details.format. Existing fields are unchanged.
130 lines
4.4 KiB
TypeScript
130 lines
4.4 KiB
TypeScript
import { readFile, writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
|
|
import { expect } from "vitest";
|
|
|
|
import { parseEvidence } from "../../src/domain/evidence.js";
|
|
import { artifactInspectionResultSchema } from "../../src/domain/artifactInspection.js";
|
|
import {
|
|
artifactExtractionResultSchema,
|
|
artifactInventoryResultSchema,
|
|
} from "../../src/domain/artifactGraph.js";
|
|
import {
|
|
androidBootImageRefusals,
|
|
buildVendorBootImage,
|
|
} from "../fixtures/androidBootImage.js";
|
|
import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js";
|
|
import { cliTest } from "../support/cli/cliFixture.js";
|
|
|
|
cliTest(
|
|
"inspects and extracts a vendor_boot image through the compiled CLI",
|
|
async ({ cli }) => {
|
|
const root = await createTestTempDirectory("rea-android-boot-cli-");
|
|
const platform = Buffer.from("platform-bytes");
|
|
const recovery = Buffer.from("recovery-bytes");
|
|
const dtb = Buffer.from("vendor-dtb");
|
|
const bootconfig = Buffer.from("androidboot.hardware=test\n");
|
|
const source = join(root, "vendor_boot.img");
|
|
const callerPath = `${root}/./vendor_boot.img`;
|
|
await writeFile(
|
|
source,
|
|
buildVendorBootImage({
|
|
version: 4,
|
|
name: "board",
|
|
cmdline: "console=tty0",
|
|
ramdisks: [
|
|
{ name: "platform", type: 1, bytes: platform },
|
|
{ name: "recovery", type: 2, bytes: recovery },
|
|
],
|
|
dtb,
|
|
bootconfig,
|
|
}),
|
|
);
|
|
const inspected = await cli.run({
|
|
arguments: ["inspect-artifact", callerPath, "--json"],
|
|
});
|
|
expect(inspected.exitCode, inspected.stdout + inspected.stderr).toBe(0);
|
|
const evidence = parseEvidence(inspected.json);
|
|
expect(evidence.caller_input_path).toBe(callerPath);
|
|
const inspection = artifactInspectionResultSchema.parse(
|
|
evidence.normalized_result,
|
|
);
|
|
const graph = artifactInventoryResultSchema.parse(
|
|
inspection.substeps[0]?.evidence.normalized_result,
|
|
);
|
|
expect(graph.manifest.root_format).toBe("android-boot-image");
|
|
expect(graph.coverage.status).toBe("complete");
|
|
expect(
|
|
graph.occurrences.find((row) => row.logical_path === ".")
|
|
?.format_metadata,
|
|
).toMatchObject({
|
|
kind: "android-boot-image",
|
|
image_kind: "vendor-boot",
|
|
magic: "VNDRBOOT",
|
|
header_version: 4,
|
|
name: "board",
|
|
command_line: "console=tty0",
|
|
vendor_ramdisk_table_entry_count: 2,
|
|
component_count: 4,
|
|
});
|
|
const extracted = await cli.run({
|
|
arguments: ["extract-artifact", callerPath, "--json"],
|
|
environment: { TMPDIR: root, TMP: root, TEMP: root },
|
|
});
|
|
expect(extracted.exitCode, extracted.stdout + extracted.stderr).toBe(0);
|
|
const extractedEvidence = parseEvidence(extracted.json);
|
|
expect(extractedEvidence.caller_input_path).toBe(callerPath);
|
|
const result = artifactExtractionResultSchema.parse(
|
|
extractedEvidence.normalized_result,
|
|
);
|
|
expect(result.containment_verified).toBe(true);
|
|
expect(
|
|
(
|
|
await readFile(join(result.output_root, "vendor_ramdisk/platform"))
|
|
).equals(platform),
|
|
).toBe(true);
|
|
expect(
|
|
(
|
|
await readFile(join(result.output_root, "vendor_ramdisk/recovery"))
|
|
).equals(recovery),
|
|
).toBe(true);
|
|
expect((await readFile(join(result.output_root, "dtb"))).equals(dtb)).toBe(
|
|
true,
|
|
);
|
|
expect(
|
|
(await readFile(join(result.output_root, "bootconfig"))).equals(
|
|
bootconfig,
|
|
),
|
|
).toBe(true);
|
|
},
|
|
);
|
|
|
|
cliTest(
|
|
"keeps Android parser refusal kinds through the compiled CLI",
|
|
async ({ cli }) => {
|
|
const root = await createTestTempDirectory(
|
|
"rea-android-boot-cli-refusals-",
|
|
);
|
|
for (const fixture of androidBootImageRefusals()) {
|
|
const path = join(root, `${fixture.name}.img`);
|
|
await writeFile(path, fixture.bytes);
|
|
const result = await cli.run({
|
|
arguments: ["inspect-artifact", path, "--json"],
|
|
});
|
|
expect(result.exitCode, result.stdout + result.stderr).toBe(1);
|
|
expect(result.json).toMatchObject({
|
|
code: fixture.code,
|
|
category: fixture.category,
|
|
details: {
|
|
operation: "inspect_artifact",
|
|
reason: fixture.kind,
|
|
...("format" in fixture
|
|
? { format_failure: fixture.kind, format: fixture.format }
|
|
: {}),
|
|
},
|
|
});
|
|
expect((await readFile(path)).equals(fixture.bytes)).toBe(true);
|
|
}
|
|
},
|
|
);
|