Files
reverse-engineering-anything/tests/acceptance/uImageCli.test.ts
T
morluto 60149282fc test: strengthen integration oracles and verification (#8295)
* test: strengthen integration oracles and verification

* test: bound lifecycle gates and strengthen workflow checks

* test: verify complete paged and extracted results

* test: preserve bytecode and cancellation evidence

* test: strengthen retained evidence and fixture cleanup

* test: require cross-projection bridge identities

* test: retain fixture owners through cleanup failures

* test: verify graph examples and project selectors

* test: tighten provider and lifecycle regressions

* test: consolidate hex coverage and bound cutter cleanup

* test: bound subprocess output waits and strengthen graph checks

* test: check mcp recovery and preserve cleanup owners

* test: verify structured mcp argument failures

* test: preserve artifact cleanup and gdb limit evidence

* test: preserve evidence identities and bound provider gates

* test: retain browser and comparison cleanup owners

* test: bound startup and strengthen fixture oracles

* test: bound lifecycle gates and verify recovered evidence

* test: verify public outcomes and lifecycle ownership

* test: assert precise evidence and release lifecycle gates

* test: verify selected facts and bound cleanup waits

* test: check retained evidence and decoded records

* test: verify final reports and retain cleanup ownership

* test: bound reviewed startup gates and retain cleanup

* test: verify PE errors and preserve MCP cleanup

* test: preserve MCP fixture cleanup ownership

* test: release provider gates before late startup
2026-11-01 00:15:28 +08:00

107 lines
3.5 KiB
TypeScript

import { createHash } from "node:crypto";
import { readFile, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { expect } from "vitest";
import { cliTest } from "../support/cli/cliFixture.js";
import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js";
import { buildMultiPayload, buildUImage } from "../fixtures/uimage.js";
import { parseEvidence } from "../../src/domain/evidence.js";
import { artifactInspectionResultSchema } from "../../src/domain/artifactInspection.js";
import {
artifactExtractionResultSchema,
artifactInventoryResultSchema,
} from "../../src/domain/artifactGraph.js";
cliTest(
"inspects and extracts a uImage through the compiled CLI",
async ({ cli }) => {
const root = await createTestTempDirectory("rea-uimage-cli-");
const partA = Buffer.from("first-part");
const partB = Buffer.from("second-part");
const payload = buildMultiPayload([partA, partB]);
const source = join(root, "firmware.bin");
await writeFile(
source,
buildUImage({
arch: 22,
os: 14,
type: 4,
compression: 0,
loadAddress: 0x8000,
entryPoint: 0x8000,
name: "multi-test",
payload,
}),
);
const inspected = await cli.run({
arguments: ["inspect-artifact", source, "--json"],
});
expect(inspected.exitCode, inspected.stdout + inspected.stderr).toBe(0);
const inspection = artifactInspectionResultSchema.parse(
parseEvidence(inspected.json).normalized_result,
);
const graph = artifactInventoryResultSchema.parse(
inspection.substeps[0]?.evidence.normalized_result,
);
expect(graph.manifest.root_format).toBe("uimage");
expect(graph.coverage.status).toBe("complete");
expect(
graph.occurrences.find((row) => row.logical_path === ".")
?.format_metadata,
).toMatchObject({
kind: "uimage",
arch: 22,
arch_name: "arm64",
os: 14,
os_name: "vxworks",
type_name: "multi",
compression_name: "none",
name: "multi-test",
crc_verified: true,
sub_image_count: 2,
});
const extracted = await cli.run({
arguments: ["extract-artifact", source, "--json"],
environment: { TMPDIR: root, TMP: root, TEMP: root },
});
expect(extracted.exitCode, extracted.stdout + extracted.stderr).toBe(0);
const result = artifactExtractionResultSchema.parse(
parseEvidence(extracted.json).normalized_result,
);
expect(result.containment_verified).toBe(true);
const expectedArtifacts = [
["image-0.bin", partA],
["image-1.bin", partB],
["payload.bin", payload],
] as const;
expect(
result.artifacts
.map(({ relative_path, bytes_written, sha256 }) => ({
relative_path,
bytes_written,
sha256,
}))
.sort((left, right) =>
left.relative_path.localeCompare(right.relative_path),
),
).toEqual(
expectedArtifacts.map(([relative_path, bytes]) => ({
relative_path,
bytes_written: bytes.length,
sha256: createHash("sha256").update(bytes).digest("hex"),
})),
);
expect(
(await readFile(join(result.output_root, "payload.bin"))).equals(payload),
).toBe(true);
expect(
(await readFile(join(result.output_root, "image-0.bin"))).equals(partA),
).toBe(true);
expect(
(await readFile(join(result.output_root, "image-1.bin"))).equals(partB),
).toBe(true);
},
);