Files
reverse-engineering-anything/tests/boundary/cli/doctorRegistrationEnvironment.test.ts
T
5c59bdc8a6 feat(ghidra)!: verify the bridge on Ghidra 12.2 (#12081)
* feat(ghidra)!: verify the bridge on Ghidra 12.2

Admit 12.x from minor 2 upward, with 12.2 and JDK 25 as the verified
pair. The bridge now calls the four-argument storage API added in 12.2,
so 12.1.x cannot compile it and is no longer accepted.

BREAKING CHANGE: Ghidra 12.1.x is rejected. Use Ghidra 12.2 or another
12.x build at or above minor 2, and a JDK inside that installation's
declared range (25 or newer for the verified 12.2 build).

* docs(ghidra): point remaining lanes at Ghidra 12.2

The Windows, 6502, and m68k prerequisites still named 12.1.4 and JDK 21,
which the verified-build check now rejects. The bridge compile lane names
the 12.2 jars it actually compiles against.

Co-authored-by: morluto <morluto@users.noreply.github.com>

* test(ghidra): admit the JDK the verified install declares

The Java home framing probe still reported JDK 21 while the verified
installation fixture now declares a minimum of 25, so doctor admission
failed before the path framing was checked.

Co-authored-by: morluto <morluto@users.noreply.github.com>

* test(ghidra): derive admitted install fixtures from the verified release

Boundary hosts and assertions still named Ghidra 12.1.4 after admission
moved to 12.2, so list_procedures evidence and completed property reads
disagreed with the install the provider actually reported.

Co-authored-by: morluto <morluto@users.noreply.github.com>

* fix(ghidra): record the exact 12.2 Clang switch-recovery defect

Ghidra 12.2 stays the verified build. Sessions and decompiler results on
that exact version name upstream issue 9996 and the 12.2.1 fix commit.
Other version strings, including 12.2.1, do not carry the limitation.

Co-authored-by: morluto <morluto@users.noreply.github.com>

* test(ghidra): check switch-defect facts instead of the warning sentence

The policy test keeps the structured defect record and checks that the
owning formatter delivers its id, commit, release, and scope fields.

Co-authored-by: morluto <morluto@users.noreply.github.com>

* test(browser): name the Playwright launch boundary the lifecycle catalog checks

Main retitled that case with a platform placeholder. The coverage catalog
still required the old literal, so the merged full suite reported a missing
title.

Co-authored-by: morluto <morluto@users.noreply.github.com>

* test(browser): point the lifecycle catalog at main's launch title

The merged suite uses main's platform-specific Playwright launch test.
The coverage catalog now names that title, and this branch keeps main's
test body so the merge stays clean.

Co-authored-by: morluto <morluto@users.noreply.github.com>

* test(browser): cover the platform launch title on this branch

The lifecycle catalog names main's platform launch title. This branch
now has that quoted test too, so the check passes before and after the
merge.

Co-authored-by: morluto <morluto@users.noreply.github.com>

* fix(ghidra): record the exact 12.2 masked byte-switch defect

Ghidra 12.2 leaves an AArch64 and-0xff byte-offset switch unrecovered.
Exact 12.2 sessions now cite open upstream issue 10154, and the AArch64
lane expects that jump table to stay unrecovered.

Co-authored-by: morluto <morluto@users.noreply.github.com>

* test(browser): keep one platform launch environment check

The second launch test repeated the selected environment check. The
remaining test is the parameterized title, and the launcher forwards
SYSTEMROOT on win32 so that assertion holds.

Co-authored-by: morluto <morluto@users.noreply.github.com>

* fix(ghidra): keep the open switch defect on admitted builds

The exact-version check cleared ghidra-10154 on every build except 12.2.
That defect stays on admitted releases until one is known to fix it.
ghidra-9996 still clears after the exact 12.2 build.

Co-authored-by: morluto <morluto@users.noreply.github.com>

* style(docs): format the Ghidra testing-lane table

The AArch64 jump-table row wrapped past the formatter width and failed
static checks.

Co-authored-by: morluto <morluto@users.noreply.github.com>

* test(ghidra): give the masked switch its full byte range

The unrecovered oracle now uses 256 readable table bytes, and the same
object must still recover its compare-bounded switch.

Co-authored-by: morluto <morluto@users.noreply.github.com>

* docs(website): point Ghidra setup at 12.2 and JDK 25

The public setup pages still told new users to install Ghidra 12.1.4 and
JDK 21, which this release rejects. Changed setup sentences are extracted
and left untranslated so those editions use the English page.

Co-authored-by: morluto <morluto@users.noreply.github.com>

* docs(website): keep catalog edits to the changed setup strings

The catalog check compares active message ids, not a full rewrite.
Restore the previous catalogs and update only the Ghidra 12.2 setup
strings, leaving their translations empty.

Co-authored-by: morluto <morluto@users.noreply.github.com>

* fix(ghidra): apply the closed switch defect from the parsed patch

12.2, 12.2.0, and 12.2.0 with a suffix all precede 12.2.1, so they keep
ghidra-9996. The masked-switch table lists all 256 byte entries.

Co-authored-by: morluto <morluto@users.noreply.github.com>

* fix(ghidra): share the AArch64 switch fixture compiler invocation

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: morluto <morluto@users.noreply.github.com>
2026-11-18 16:06:51 -05:00

288 lines
9.8 KiB
TypeScript

import { chmod, mkdir, readFile, symlink, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { expect } from "vitest";
import { z } from "zod";
import { elf, thinMach } from "../../../src/domain/binaryTarget.fixture.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
import { cliTest, type TestCli } from "../../support/cli/cliFixture.js";
/** An installation doctor admits; nothing here starts an analysis JVM. */
const writeAdmittedGhidra = async (root: string) => {
const jdk = join(root, "jdk");
const install = join(root, "ghidra");
const native = join(
install,
"Ghidra/Features/Decompiler/os",
`${process.platform === "darwin" ? "mac" : "linux"}_${process.arch === "arm64" ? "arm_64" : "x86_64"}`,
"decompile",
);
for (const path of [
join(jdk, "bin"),
join(install, "support"),
join(native, ".."),
])
await mkdir(path, { recursive: true });
await writeFile(
join(install, "Ghidra/application.properties"),
"application.version=12.2\napplication.java.min=25\n",
);
await writeFile(
join(install, "support/analyzeHeadless"),
"#!/bin/sh\nexit 99\n",
{ mode: 0o700 },
);
await writeFile(
native,
process.platform === "darwin"
? thinMach(0xfeedfacf, process.arch === "arm64" ? 0x0100000c : 0x01000007)
: elf(2, 1, process.arch === "arm64" ? 183 : 62),
);
await chmod(native, 0o700);
const properties = [
"java.version = 25.0.1",
`java.home = ${jdk}`,
"sun.arch.data.model = 64",
`os.arch = ${process.arch === "arm64" ? "aarch64" : "amd64"}`,
`os.name = ${process.platform === "darwin" ? "Mac OS X" : "Linux"}`,
"",
].join("\n");
await writeFile(
join(jdk, "bin/java"),
`#!${process.execPath}\nprocess.stderr.write(${JSON.stringify(properties)});\n`,
{ mode: 0o700 },
);
await writeFile(join(jdk, "bin/javac"), "#!/bin/sh\nexit 0\n", {
mode: 0o700,
});
return { install, jdk };
};
const reportSchema = z.object({
healthy: z.boolean(),
scope_checks: z.array(z.object({ name: z.string() }).loose()),
informational_checks: z.array(z.object({ name: z.string() }).loose()),
identity: z.object({
registrations: z.array(z.object({ client: z.string() }).loose()),
}),
});
const run = async (
cli: TestCli,
arguments_: readonly string[],
environment: NodeJS.ProcessEnv,
) => {
const result = await cli.run({
arguments: [...arguments_, "--json"],
environment,
});
return { result, report: reportSchema.safeParse(result.json) };
};
const doctor = async (
cli: TestCli,
scope: readonly string[],
environment: NodeJS.ProcessEnv,
) => {
const { result, report } = await run(cli, ["doctor", ...scope], environment);
if (!report.success) throw new Error(result.stdout + result.stderr);
return { exitCode: result.exitCode, report: report.data };
};
const names = (checks: readonly { readonly name: string }[]) =>
checks.map(({ name }) => name);
const CHECK = "registration_environment:claude_code";
cliTest.skipIf(!["darwin", "linux"].includes(process.platform))(
"doctor does not let a configured terminal stand in for an unconfigured registration",
async ({ cli }) => {
const root = await createTestTempDirectory("rea-doctor-registration-env-");
const home = join(root, "home");
await mkdir(home);
const { install, jdk } = await writeAdmittedGhidra(root);
const clientEnvironment = {
HOME: home,
USERPROFILE: home,
// The host's own Ghidra or Java must not satisfy this fixture.
PATH: "/usr/bin:/bin",
HOPPER_LAUNCHER_PATH: join(root, "missing-hopper"),
REA_LOG_LEVEL: "silent",
};
const terminal = {
...clientEnvironment,
GHIDRA_INSTALL_DIR: install,
JAVA_HOME: jdk,
};
const configPath = join(home, ".claude.json");
const saved = async () =>
z
.object({
mcpServers: z.object({
rea: z.object({ env: z.record(z.string(), z.string()) }),
}),
})
.parse(JSON.parse(await readFile(configPath, "utf8"))).mcpServers.rea
.env;
// Setup ran where the provider settings were not visible.
const unconfigured = await run(
cli,
["setup", "--client", "claude_code", "--skill=false", "--yes"],
clientEnvironment,
);
expect(unconfigured.result.exitCode, unconfigured.result.stdout).toBe(0);
expect(await saved()).not.toHaveProperty("GHIDRA_INSTALL_DIR");
// The registration's own environment is what a client without these
// settings gives its server; it does not reach the terminal's result.
const served = await doctor(cli, ["--provider", "ghidra"], {
...(await saved()),
HOME: home,
USERPROFILE: home,
PATH: clientEnvironment.PATH,
});
expect(served.exitCode).toBe(1);
expect(served.report.scope_checks).toContainEqual(
expect.objectContaining({
name: "ghidra",
ok: false,
classification: "missing_analysis_engine",
}),
);
expect(names(served.report.scope_checks)).not.toContain(CHECK);
for (const scope of [
["--provider", "ghidra"],
["--client", "claude_code"],
["--provider", "ghidra", "--client", "claude_code"],
]) {
const scoped = await doctor(cli, scope, terminal);
expect(scoped.report.scope_checks, scope.join(" ")).toContainEqual(
expect.objectContaining({
name: CHECK,
ok: true,
classification: "unknown",
detail: expect.stringContaining(
"does not record GHIDRA_INSTALL_DIR, JAVA_HOME",
),
details: {
effective_environment: "unknown",
providers: ["ghidra"],
},
remediation: expect.stringContaining(
"rea setup --client claude_code --skill=false --dry-run",
),
}),
);
// An unobserved environment is neither a failure nor a healthy match.
expect(scoped.report.healthy, scope.join(" ")).toBe(true);
expect(scoped.exitCode, scope.join(" ")).toBe(0);
expect(scoped.report.identity.registrations).toEqual([
expect.objectContaining({
client: "claude_code",
state: "aligned",
provider_settings: {
unrecorded: ["GHIDRA_INSTALL_DIR", "JAVA_HOME"],
differing: [],
unresolved: [],
},
}),
]);
}
const unrelated = await doctor(cli, ["--skill"], terminal);
expect(names(unrelated.report.scope_checks)).not.toContain(CHECK);
expect(names(unrelated.report.informational_checks)).toContain(CHECK);
// Doctor reads; the configuration is unchanged until setup is approved.
const before = await readFile(configPath, "utf8");
await doctor(cli, [], terminal);
expect(await readFile(configPath, "utf8")).toBe(before);
// The named remediation records exactly these settings and then clears it.
const planned = await run(
cli,
["setup", "--client", "claude_code", "--skill=false", "--dry-run"],
terminal,
);
expect(planned.result.stdout).toContain(`GHIDRA_INSTALL_DIR=${install}`);
expect(planned.result.stdout).toContain(`JAVA_HOME=${jdk}`);
expect(await readFile(configPath, "utf8")).toBe(before);
const applied = await run(
cli,
["setup", "--client", "claude_code", "--skill=false", "--yes"],
terminal,
);
expect(applied.result.exitCode, applied.result.stdout).toBe(0);
expect(await saved()).toMatchObject({
GHIDRA_INSTALL_DIR: install,
JAVA_HOME: jdk,
});
expect(await readFile(`${configPath}.rea.backup`, "utf8")).toBe(before);
const recorded = await doctor(cli, ["--provider", "ghidra"], terminal);
expect(recorded.exitCode).toBe(0);
expect(names(recorded.report.scope_checks)).not.toContain(CHECK);
expect(recorded.report.identity.registrations[0]).not.toHaveProperty(
"provider_settings",
);
// Another terminal selecting a different JDK spelling is reported as that.
const alias = join(root, "jdk-alias");
await symlink(jdk, alias);
const otherTerminal = { ...terminal, JAVA_HOME: alias };
const other = await doctor(cli, ["--provider", "ghidra"], otherTerminal);
expect(other.report.identity.registrations[0]).toMatchObject({
provider_settings: {
unrecorded: [],
differing: ["JAVA_HOME"],
unresolved: [],
},
});
// Setup's own spelling of a caller selection compares as recorded.
await run(
cli,
["setup", "--client", "claude_code", "--skill=false", "--yes"],
otherTerminal,
);
expect(await saved()).toMatchObject({ JAVA_HOME: alias });
const aliased = await doctor(cli, ["--provider", "ghidra"], otherTerminal);
expect(names(aliased.report.scope_checks)).not.toContain(CHECK);
},
);
cliTest.skipIf(!["darwin", "linux"].includes(process.platform))(
"doctor adds nothing when the terminal's provider is not available",
async ({ cli }) => {
const root = await createTestTempDirectory("rea-doctor-registration-off-");
const home = join(root, "home");
await mkdir(home);
const environment = {
HOME: home,
USERPROFILE: home,
PATH: "/usr/bin:/bin",
HOPPER_LAUNCHER_PATH: join(root, "missing-hopper"),
REA_LOG_LEVEL: "silent",
};
await run(
cli,
["setup", "--client", "claude_code", "--skill=false", "--yes"],
environment,
);
// A provider setting that fails its own check has no green result to
// misread; that failure is the report.
const { report } = await doctor(cli, ["--provider", "ghidra"], {
...environment,
GHIDRA_INSTALL_DIR: join(root, "missing-ghidra"),
});
expect(report.healthy).toBe(false);
expect(names(report.scope_checks)).not.toContain(CHECK);
expect(names(report.informational_checks)).not.toContain(CHECK);
expect(report.identity.registrations[0]).not.toHaveProperty(
"provider_settings",
);
},
);