Files
rea/tests/acceptance/elfNotesCli.test.ts
T
morluto bd4f5e9c19 fix(parsers): preserve format evidence and caller input identity
Retain bounded FAT and offset-tagged PE observations through archive hashing,
classification, and content nodes. Preserve PyInstaller member paths according
to the observed carrier dialect and share APK v1 signing-name semantics.

Read SQLite's implicit sqlite_schema table without inventing a stored schema
declaration. Distinguish unsupported ELF numbering and decoded-name admission
from malformed data and fixed scan allowances. Preserve Sigrok basenames and
classify matching explicit input-format refusals at their owning boundary.

Validation: 554 distinct tests passed, 3 skipped across serial focused runs;
build, typecheck/lint, docs, formatting, and discovery (2141 files) passed.
Sigrok command-boundary simulators do not establish real-tool decoding.
Small repeated public PyInstaller CLI runs had equivalent inventory facts;
warm median elapsed 0.5431s before / 0.5426s after, with no speed claim.

Fixes #6733
Fixes #6741
Fixes #6722
Fixes #6732
Fixes #6736
Fixes #6734
Fixes #6764
Fixes #6766
Refs #6739
2026-10-23 22:54:28 +08:00

106 lines
3.7 KiB
TypeScript

import { readFile, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { expect } from "vitest";
import { toolContract } from "../../src/contracts/toolContracts.js";
import {
compressedElfNoteFixture,
elfExtendedSectionCountFixture,
elfNoteFixture,
} from "../../src/native/elf/ElfNotes.fixture.js";
import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js";
import { cliTest } from "../support/cli/cliFixture.js";
cliTest("reports a GNU build-id through the public CLI", async ({ cli }) => {
const root = await createTestTempDirectory("rea-elf-notes-cli-");
const path = join(root, "program");
await writeFile(path, elfNoteFixture({ ownership: "program" }));
const result = await cli.run({
arguments: ["inspect-elf-notes", path, "--json"],
});
expect(result.exitCode, result.stderr).toBe(0);
const evidence = toolContract("inspect_elf_notes").outputSchema.parse(
result.json,
);
expect(
evidence.normalized_result.entries.find(
(entry) => entry.type_name === "gnu_build_id",
)?.gnu?.build_id_hex,
).toBe("0123456789abcdef0123456789abcdef01234567");
});
cliTest(
"resolves section note names from a compressed string table through the CLI",
async ({ cli }) => {
const root = await createTestTempDirectory("rea-elf-notes-compressed-cli-");
const path = join(root, "program");
await writeFile(path, compressedElfNoteFixture());
const result = await cli.run({
arguments: ["inspect-elf-notes", path, "--json"],
});
expect(result.exitCode, result.stderr).toBe(0);
const evidence = toolContract("inspect_elf_notes").outputSchema.parse(
result.json,
);
expect(evidence.normalized_result.tables[0]?.name).toBe(
".note.gnu.build-id",
);
expect(evidence.normalized_result.entries[0]?.gnu?.build_id_hex).toBe(
"0123456789abcdef0123456789abcdef01234567",
);
},
);
cliTest(
"resolves a relative ELF path against the working directory",
async ({ cli }) => {
const root = await createTestTempDirectory("rea-elf-notes-cli-rel-");
await writeFile(
join(root, "unsigned"),
elfNoteFixture({ ownership: "none" }),
);
const result = await cli.run({
arguments: ["inspect-elf-notes", "unsigned", "--json"],
cwd: root,
});
expect(result.exitCode, result.stderr).toBe(0);
const evidence = toolContract("inspect_elf_notes").outputSchema.parse(
result.json,
);
expect(evidence.normalized_result.tables).toEqual([]);
expect(evidence.subject?.local_path).toBe(join(root, "unsigned"));
},
);
cliTest("reports a truncated ELF as invalid input", async ({ cli }) => {
const root = await createTestTempDirectory("rea-elf-notes-cli-bad-");
const path = join(root, "broken");
await writeFile(path, Buffer.from("\x7fELF"));
const result = await cli.run({
arguments: ["inspect-elf-notes", path, "--json"],
});
expect(result.exitCode).toBe(1);
expect(result.json).toMatchObject({
code: "invalid_request",
details: { operation: "inspect_elf_notes" },
});
});
cliTest(
"reports valid extended numbering as unsupported without mutation",
async ({ cli }) => {
const root = await createTestTempDirectory("rea-elf-notes-extended-cli-");
const path = join(root, "extended-count.elf");
await writeFile(path, elfExtendedSectionCountFixture());
const before = await readFile(path);
const result = await cli.run({
arguments: ["inspect-elf-notes", path, "--json"],
});
expect(result.exitCode).toBe(1);
expect(result.json).toMatchObject({
code: "unsupported_target",
message: expect.stringContaining("ELF extended numbering is unsupported"),
});
expect(await readFile(path)).toEqual(before);
},
);