mirror of
https://github.com/morluto/rea
synced 2026-10-25 22:08:11 -04:00
99d2d7ad22
Share bounded ELF section-name decoding across native and note readers; retain read-only ranges and coverage reasons when names are unknown. Preserve ELF symbol-version bytes, dyld-bound method uncertainty, partial gRPC-Web trailers, and per-parent model identity checks. Compare GPU signatures as bytes and require a PTX module header. Share selected-path errno classification across EVM and BEAM. Validation: 397 shared-parser tests passed (one existing skip), 5 MCP schema tests passed, 14 EVM error-mapping tests passed, and 23 protobuf CLI/MCP matrix cases passed across focused runs. Build, typecheck/lint, docs, formatting, and 2134-file discovery passed. Full EVM provider workflow remains locally unverified on Darwin arm64; format controls are synthetic. Fixes #6738 Fixes #6737 Fixes #6745 Fixes #6740 Fixes #6749 Fixes #6747 Fixes #6739
171 lines
6.0 KiB
TypeScript
171 lines
6.0 KiB
TypeScript
import { createHash } from "node:crypto";
|
|
import { symlink, writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { describe, expect, it } from "vitest";
|
|
import { createNativeExportsService } from "../../../src/composition/binaryDiagnostics.js";
|
|
import { parseEvidence } from "../../../src/domain/evidence.js";
|
|
import { nativeExportsSchema } from "../../../src/domain/native/nativeExports.js";
|
|
import {
|
|
elfExportImage,
|
|
peExportImage,
|
|
} from "../../fixtures/binaryDiagnostics/nativeExports.js";
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
|
|
describe("native export stable filesystem boundary", () => {
|
|
it("binds PE and ELF export inventories to the selected file", async () => {
|
|
const root = await createTestTempDirectory("rea-native-exports-");
|
|
const service = createNativeExportsService();
|
|
for (const [name, bytes, format] of [
|
|
[
|
|
"fixture.dll",
|
|
peExportImage({
|
|
functions: [{ rva: 0x2000 }],
|
|
names: [{ name: "Exported", index: 0 }],
|
|
}),
|
|
"pe",
|
|
],
|
|
[
|
|
"libfixture.so",
|
|
elfExportImage({ symbols: [{ name: "exported" }] }),
|
|
"elf",
|
|
],
|
|
] as const) {
|
|
const path = join(root, name);
|
|
await writeFile(path, bytes);
|
|
const result = await service.inspect({ path });
|
|
if (!result.ok) throw new Error(JSON.stringify(result.error));
|
|
const evidence = parseEvidence(result.value);
|
|
const sha256 = createHash("sha256").update(bytes).digest("hex");
|
|
|
|
expect(evidence).toMatchObject({
|
|
operation: "inspect_native_exports",
|
|
provider: { id: "rea-native-exports" },
|
|
confidence: "observed",
|
|
subject: { local_path: path, format, digest: { sha256 } },
|
|
});
|
|
expect(
|
|
nativeExportsSchema.parse(evidence.normalized_result),
|
|
).toMatchObject({
|
|
artifact: { path, sha256, bytes: bytes.length },
|
|
format,
|
|
coverage: { status: "complete", exports: 1 },
|
|
});
|
|
}
|
|
await service.close();
|
|
});
|
|
});
|
|
|
|
describe("native export encoding and failures", () => {
|
|
it("keeps ELF symbol bytes while exposing valid UTF-8 text", async () => {
|
|
const root = await createTestTempDirectory("rea-native-export-unicode-");
|
|
const path = join(root, "libfixture.so");
|
|
const bytes = elfExportImage({
|
|
symbols: [{ name: "café", version: 2 }, { name: "\u00ff" }],
|
|
versionDefinitions: ["libfixture.so", "libcafé.so"],
|
|
});
|
|
await writeFile(path, bytes);
|
|
const service = createNativeExportsService();
|
|
const result = await service.inspect({ path });
|
|
if (!result.ok) throw new Error(JSON.stringify(result.error));
|
|
expect(result.value.normalized_result).toMatchObject({
|
|
format: "elf",
|
|
exports: [
|
|
{
|
|
name: "café",
|
|
name_bytes_base64: "Y2Fmw6k=",
|
|
name_utf8_decodable: true,
|
|
version: {
|
|
index: 2,
|
|
name: "libcafé.so",
|
|
name_bytes_base64: "bGliY2Fmw6kuc28=",
|
|
name_utf8_decodable: true,
|
|
},
|
|
},
|
|
{
|
|
name: "ÿ",
|
|
name_bytes_base64: "/w==",
|
|
name_utf8_decodable: false,
|
|
},
|
|
],
|
|
});
|
|
const olderRows = JSON.parse(
|
|
JSON.stringify(result.value.normalized_result),
|
|
) as { exports: Record<string, unknown>[] };
|
|
for (const row of olderRows.exports) {
|
|
delete row.name_bytes_base64;
|
|
delete row.name_utf8_decodable;
|
|
const version = row.version;
|
|
if (version !== null && typeof version === "object") {
|
|
Reflect.deleteProperty(version, "name_bytes_base64");
|
|
Reflect.deleteProperty(version, "name_utf8_decodable");
|
|
}
|
|
}
|
|
expect(nativeExportsSchema.parse(olderRows)).toMatchObject({
|
|
exports: [
|
|
{
|
|
name: "café",
|
|
name_bytes_base64: null,
|
|
name_utf8_decodable: null,
|
|
version: {
|
|
index: 2,
|
|
name: "libcafé.so",
|
|
name_bytes_base64: null,
|
|
name_utf8_decodable: null,
|
|
hidden: false,
|
|
},
|
|
},
|
|
{ name: "ÿ", name_bytes_base64: null, name_utf8_decodable: null },
|
|
],
|
|
});
|
|
await service.close();
|
|
});
|
|
|
|
it("returns typed input, unsupported, budget and cancellation failures", async () => {
|
|
const root = await createTestTempDirectory("rea-native-export-failures-");
|
|
const path = join(root, "fixture.dll");
|
|
const alias = join(root, "alias.dll");
|
|
const macho = join(root, "fixture.dylib");
|
|
const malformed = join(root, "malformed.dll");
|
|
await writeFile(path, peExportImage({ functions: [] }));
|
|
const machoBytes = Buffer.alloc(64);
|
|
machoBytes.writeUInt32LE(0xfeedfacf, 0);
|
|
await writeFile(macho, machoBytes);
|
|
await writeFile(malformed, Buffer.from("MZ not a PE image"));
|
|
await symlink(path, alias);
|
|
const service = createNativeExportsService();
|
|
const failure = async (
|
|
input: Record<string, unknown>,
|
|
signal?: AbortSignal,
|
|
) => {
|
|
const result = await service.inspect(
|
|
input,
|
|
signal === undefined ? undefined : { signal },
|
|
);
|
|
if (result.ok) throw new Error("Expected a failure");
|
|
return result.error;
|
|
};
|
|
|
|
for (const [candidate, reason] of [
|
|
[alias, "invalid_format"],
|
|
[malformed, "invalid_format"],
|
|
[join(root, "missing.dll"), "invalid_value"],
|
|
] as const)
|
|
expect(await failure({ path: candidate })).toMatchObject({
|
|
_tag: "AnalysisInputError",
|
|
operation: "inspect_native_exports",
|
|
issues: [{ path: ["path"], reason }],
|
|
});
|
|
expect(await failure({ path: macho })).toMatchObject({
|
|
_tag: "AnalysisUnsupportedTargetError",
|
|
reason: expect.stringContaining("inspect_macho"),
|
|
});
|
|
expect(await failure({ path, max_file_bytes: 64 })).toMatchObject({
|
|
_tag: "AnalysisResourceConstraintError",
|
|
});
|
|
expect(
|
|
await failure({ path }, AbortSignal.abort("caller stop")),
|
|
).toMatchObject({ _tag: "AnalysisCancelledError" });
|
|
await service.close();
|
|
});
|
|
});
|