Files
rea/tests/boundary/cli/ghidraInstallationProperties.test.ts
T
morluto 5112fe07ae fix(ghidra): admit installation metadata through owned bounded reads
Reject special files without blocking, cap the properties payload at 1 MiB before allocation, and verify descriptor extent and the selected name. Preserve Latin-1 data, selected symlinks, physical filesystem facts, completed observations and exact failed-close ownership.

Reuse the stable bounded reader for profile artifacts and consolidate Ghidra file failure projection. Distinguish missing-at-open from disappearance or read failure, and attribute typed prerequisite failures at the consuming operation.

Validation: 384 focused tests across 14 files, 42 seed/extension controls, 32 final metadata/profile/CLI controls, check:fast and docs:check. Controlled macOS file/process fixtures; no real Ghidra/JVM or Windows/Linux lifecycle verification.

Bounded FIFO reproduction: baseline direct and public doctor required external cleanup around 2.2s; candidate returned independently around 0.4/0.57s, all fixture groups verified empty. Warm normal doctor baseline/candidate: elapsed 1.211/1.230s, CPU 1.239/1.247s, sampled family RSS 524/524MB, reply tokens 3116/3116. No performance improvement claimed; true cold and whole-agent costs unmeasured.

Refs #4672
2026-10-17 12:02:26 +08:00

42 lines
1.7 KiB
TypeScript

import { execFile } from "node:child_process";
import { promisify } from "node:util";
import { mkdir, truncate, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { expect } from "vitest";
import { MAX_GHIDRA_INSTALLATION_PROPERTIES_BYTES } from "../../../src/ghidra/GhidraInstallationProperties.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
import { cliTest } from "../../support/cli/cliFixture.js";
cliTest.skipIf(process.platform === "win32").for(["pipe", "capacity"] as const)(
"doctor reports selected properties %s without launching Java",
async (kind, { cli }) => {
const root = await createTestTempDirectory("rea-doctor-properties-");
const install = join(root, "ghidra");
const path = join(install, "Ghidra/application.properties");
await mkdir(join(install, "Ghidra"), { recursive: true });
if (kind === "pipe") await promisify(execFile)("mkfifo", [path]);
else {
await writeFile(path, "application.version=12.1.4\n");
await truncate(path, MAX_GHIDRA_INSTALLATION_PROPERTIES_BYTES + 1);
}
const result = await cli.run({
arguments: ["doctor", "--provider", "ghidra", "--json"],
environment: {
GHIDRA_INSTALL_DIR: install,
JAVA_HOME: join(root, "missing-jdk"),
REA_LOG_LEVEL: "silent",
},
timeoutMs: 5000,
});
expect(result.exitCode, `${result.stdout}\n${result.stderr}`).toBe(1);
expect(result.signal).toBeNull();
expect(result.json).toMatchObject({
code: kind === "pipe" ? "execution_failure" : "resource_constraint",
details: {
operation: "doctor",
diagnostics: { path, stage: "installation_properties" },
},
});
},
);