Files
reverse-engineering-anything/tests/acceptance/devicetreeCli.test.ts
T
b4ba96a9a5 feat(firmware): inspect flattened devicetree blobs (#7009)
* feat(firmware): inspect flattened devicetree blobs

Adds inspect-devicetree and inspect_devicetree for FDT v16/v17 blobs
without target execution or external dependencies. Results include
validated headers, reservations, a node/property tree with bounded raw
previews, and derived standard values and selected phandle references.
Parsing enforces file, tree, and decoded representation budgets and
rejects malformed input without partial success. Summary delivery
supports retained Evidence pagination, with tests covering parsing,
service validation, CLI delivery, and MCP access after the input is
removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016y53PdpyMAp9RSW65fatHe

* fix(firmware): reject conflicting devicetree phandles and bound page summaries

A node whose phandle and linux,phandle disagree no longer resolves under
either value; the conflict is reported as a limitation. Finalization
failures after a completed read retain the file-snapshot-hash partial
observation, matching the Go provider. Devicetree view pages carry
fixed-size context and counts instead of repeating summary strings, so a
large bootargs no longer pushes every page over the MCP response budget.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016y53PdpyMAp9RSW65fatHe

---------

Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
2026-10-24 22:45:22 +08:00

101 lines
2.9 KiB
TypeScript

import { readFile, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { expect } from "vitest";
import { z } from "zod";
import { toolContract } from "../../src/contracts/toolContracts.js";
import { devicetreeFixture } from "../../src/firmware/devicetree/Devicetree.fixture.js";
import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js";
import { cliTest } from "../support/cli/cliFixture.js";
cliTest("inspects a relative DTB and preserves the source", async ({ cli }) => {
const root = await createTestTempDirectory("rea-dtb-cli-");
const path = join(root, "board.dtb"),
bytes = devicetreeFixture();
await writeFile(path, bytes);
const result = await cli.run({
arguments: [
"inspect-devicetree",
"board.dtb",
"--max-file-bytes",
"4096",
"--max-depth",
"8",
"--max-properties",
"64",
"--json",
],
cwd: root,
});
expect(result.exitCode, result.stderr).toBe(0);
const report = toolContract("inspect_devicetree").outputSchema.parse(
result.json,
).normalized_result;
expect(report).toMatchObject({
artifact: { path },
summary: { model: "Test board" },
coverage: { examined_nodes: 5 },
});
expect(await readFile(path)).toEqual(bytes);
});
cliTest(
"retains complete DTB Evidence when delivering a summary",
async ({ cli }) => {
const root = await createTestTempDirectory("rea-dtb-cli-summary-");
const path = join(root, "board.dtb"),
output = join(root, "evidence.json");
await writeFile(path, devicetreeFixture());
const result = await cli.run({
arguments: [
"inspect-devicetree",
path,
"--detail",
"summary",
"--evidence_output",
output,
"--json",
],
});
expect(result.exitCode, result.stderr).toBe(0);
expect(
toolContract("inspect_devicetree").outputSchema.parse(
z.object({ summary: z.unknown() }).parse(result.json).summary,
).normalized_result,
).toMatchObject({
kind: "summary",
summary: { unresolved_reference_count: 1 },
});
expect(await readFile(output, "utf8")).toContain('"nodes"');
},
);
for (const [name, build, flags, code] of [
[
"malformed",
() => devicetreeFixture().subarray(0, 30),
[],
"invalid_request",
],
[
"unsupported",
() => devicetreeFixture(undefined, 18),
[],
"unsupported_target",
],
[
"exhausted",
() => devicetreeFixture(),
["--max-nodes", "1"],
"resource_constraint",
],
] as const) {
cliTest(`reports ${name} DTB input`, async ({ cli }) => {
const root = await createTestTempDirectory("rea-dtb-cli-errors-");
const path = join(root, "board.dtb");
await writeFile(path, build());
const result = await cli.run({
arguments: ["inspect-devicetree", path, ...flags, "--json"],
});
expect(result.exitCode).toBe(1);
expect(result.json).toMatchObject({ code });
});
}