Files
rea/tests/acceptance/nativeElfFrameAllowanceMcp.test.ts
T
morluto 5c3ed5d028 test: prune redundant and superseded tests (#14271)
* test: prune redundant and superseded tests

Remove two boundary copies of the zstd.max_frames section-name refusal for
binary hardening and ELF unwind ranges. The public MCP frame-allowance test
already checks both operations; it now also asserts the setting's minimum
and maximum, which the copies carried.

Drop the trailing inspect-managed-members malformed-bytes check from the
managed comparison CLI test. The shared parser-failure CLI table covers that
projection for every managed reader.

Index the GPU ELF fixture's section-name offsets once instead of searching
the string table per section. The SHN_XINDEX fixture has 65,539 sections, so
the per-row search was quadratic. The generated bytes are identical.

* test: bound the GPU fixture's section-name suffix index

Indexing every suffix of every section name made a 65,536-byte name cost
quadratic work. Index only suffixes up to 256 bytes and search the table
directly for longer names; both give the first occurrence the per-row
search used, so the generated bytes are unchanged.
2026-11-23 23:06:36 -05:00

110 lines
3.7 KiB
TypeScript

import { createHash } from "node:crypto";
import { writeFile } from "node:fs/promises";
import { join } from "node:path";
import { expect, it } from "vitest";
import {
MAXIMUM_ZSTD_MAX_FRAMES,
MINIMUM_ZSTD_MAX_FRAMES,
} from "../../src/domain/analysisResourceLimits.js";
import { elfNoteFixture } from "../../src/native/elf/ElfNotes.fixture.js";
import { INLINE_EVIDENCE_MCP_ENVIRONMENT } from "../../scripts/lib/mcp-verification-environment.mjs";
import { elfFrameAllowanceFixture } from "../fixtures/binaryDiagnostics/elfFrameAllowance.js";
import { createIl2cppMetadataFixture } from "../fixtures/il2cpp/metadata.js";
import { connectLocalToolsMcp } from "../fixtures/localToolsMcp.js";
import { parseMcpToolError } from "../fixtures/mcpToolError.js";
import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js";
it("reports an ELF section-name frame refusal through each native diagnostic", async () => {
const root = await createTestTempDirectory("rea-native-elf-frame-cap-");
const path = join(root, "image.elf");
const primary = join(root, "primary.elf");
const metadata = join(root, "global-metadata.dat");
const bytes = elfFrameAllowanceFixture();
await writeFile(path, bytes);
await writeFile(primary, elfNoteFixture());
await writeFile(metadata, createIl2cppMetadataFixture().bytes);
const { call } = await connectLocalToolsMcp(INLINE_EVIDENCE_MCP_ENVIRONMENT);
const operations = [
"inspect_binary_hardening",
"inspect_elf_debug_link",
"inspect_elf_unwind_ranges",
"inspect_kernel_module",
"inspect_native_exports",
"inspect_native_initializers",
"inspect_go_binary",
"inspect_rust_binary",
] as const;
const setAllowance = async (value: number) => {
const result = await call("update_analysis_settings", {
changes: [{ setting: "zstd.max_frames", action: "set", value }],
});
expect(result.isError).not.toBe(true);
};
await setAllowance(1);
for (const operation of [...operations, "inspect_il2cpp_metadata"]) {
const settings = await call("inspect_analysis_settings", { operation });
expect(settings.structuredContent, operation).toMatchObject({
settings: expect.arrayContaining([
expect.objectContaining({ setting: "zstd.max_frames" }),
]),
});
const result = await call(
operation,
operation === "inspect_il2cpp_metadata"
? { path: metadata, binary_path: path }
: { path },
);
expect(parseMcpToolError(result).error, operation).toMatchObject({
code: "resource_constraint",
details: {
operation,
resource: "cpu",
reported_limits: {
boundary: "zstd.max_frames",
maximum: 1,
required: 2,
},
limit: {
setting: "zstd.max_frames",
effective_value: 1,
source: "runtime",
minimum: MINIMUM_ZSTD_MAX_FRAMES,
maximum: MAXIMUM_ZSTD_MAX_FRAMES,
unit: "count",
},
},
});
}
const candidate = await call("inspect_elf_debug_link", {
path: primary,
candidate_path: path,
});
expect(candidate.isError).not.toBe(true);
expect(candidate.structuredContent).toMatchObject({
normalized_result: {
candidate: {
path,
bytes: bytes.length,
sha256: createHash("sha256").update(bytes).digest("hex"),
format: "elf64",
debug_info: "unknown",
symtab: "unknown",
},
limitations: expect.arrayContaining([
expect.stringContaining("zstd.max_frames"),
]),
},
});
await setAllowance(2);
for (const operation of operations) {
const result = await call(operation, { path });
expect(
result.isError,
`${operation}: ${JSON.stringify(result.content)}`,
).not.toBe(true);
}
});