Skip to content

armgit / rea

Public Imported from GitHub
0

Reverse engineer anything with agents, from app behavior down to native binaries.

fix(doctor): validate Hopper startup timeout in readiness checks (#3755)

xjh052956af3416
diff --git a/src/application/Doctor.test.ts b/src/application/Doctor.test.ts
index 2a2013c91..b8aad4985 100644
--- a/src/application/Doctor.test.ts
+++ b/src/application/Doctor.test.ts
@@ -3,10 +3,105 @@ import { describe, expect, it } from "vitest";
import { SUPPORTED_NODE_VERSION_PROSE } from "../domain/runtimeVersion.js";
import type { ClientRegistrationStatus } from "./ClientRegistrationStatus.js";
import { createDoctorHostFixture as host } from "./Doctor.fixture.js";
-import { runDoctor } from "./Doctor.js";
+import { runDoctor, systemDoctorHost, type DoctorHost } from "./Doctor.js";
import { err } from "../domain/result.js";
import { HopperReleaseError } from "./HopperReleaseFeed.js";
+describe("doctor Hopper startup timeout", () => {
+ const timeoutHost = (
+ value: string | undefined,
+ overrides: Partial<DoctorHost> = {},
+ ): DoctorHost => ({
+ ...systemDoctorHost({
+ environment:
+ value === undefined ? {} : { REA_HOPPER_STARTUP_TIMEOUT_MS: value },
+ }),
+ ...host({
+ installationPaths: () => Promise.resolve([]),
+ clientRegistrations: () => Promise.resolve([]),
+ ...overrides,
+ }),
+ });
+
+ it.each([
+ ["0", true, false],
+ ["120000", true, true],
+ ["0", false, false],
+ ["120000", false, true],
+ [undefined, false, true],
+ ] as const)(
+ "checks timeout %s with Hopper present=%s and an available peer",
+ async (value, hopperPresent, healthy) => {
+ const selectedHost = timeoutHost(value, {
+ executable: () => Promise.resolve(hopperPresent),
+ providerInspections: () =>
+ Promise.resolve([
+ {
+ id: "ghidra",
+ configured: true,
+ available: true,
+ providerVersion: null,
+ registrationEnvironment: {},
+ checks: [],
+ },
+ ]),
+ });
+ const result = await runDoctor(undefined, selectedHost);
+ expect(result.healthy).toBe(healthy);
+ expect(result.environment_healthy).toBe(healthy);
+ const timeoutCheck = result.checks.find(
+ ({ name }) => name === "hopper-startup-timeout",
+ );
+ if (value === undefined) expect(timeoutCheck).toBeUndefined();
+ else expect(timeoutCheck).toMatchObject({ ok: value !== "0" });
+ },
+ );
+
+ it.each(["", "0", "-1", "1.5", "1e3", "invalid", "2147483648"])(
+ "rejects invalid Hopper startup timeout %j in the selected provider scope",
+ async (value) => {
+ const selectedHost = timeoutHost(value);
+ const result = await runDoctor(undefined, selectedHost, {
+ providers: ["hopper"],
+ });
+
+ expect(result.healthy).toBe(false);
+ expect(result.scope_checks).toContainEqual(
+ expect.objectContaining({
+ name: "hopper-startup-timeout",
+ ok: false,
+ classification: "config_drift",
+ detail: expect.stringContaining("REA_HOPPER_STARTUP_TIMEOUT_MS"),
+ remediation: expect.stringContaining("REA_HOPPER_STARTUP_TIMEOUT_MS"),
+ }),
+ );
+ },
+ );
+
+ it.each([undefined, "1", "120000", "2147483647"])(
+ "keeps Hopper ready with the valid startup timeout %j",
+ async (value) => {
+ const selectedHost = timeoutHost(value);
+ expect(
+ (await runDoctor(undefined, selectedHost, { providers: ["hopper"] }))
+ .healthy,
+ ).toBe(true);
+ },
+ );
+
+ it("keeps an invalid Hopper timeout informational outside the Hopper scope", async () => {
+ const selectedHost = timeoutHost("0");
+ const result = await runDoctor(undefined, selectedHost, { providers: [] });
+ expect(result.healthy).toBe(true);
+ expect(result.informational_checks).toContainEqual(
+ expect.objectContaining({
+ name: "hopper-startup-timeout",
+ ok: false,
+ }),
+ );
+ });
+});
+
describe("doctor runtime check", () => {
it("reports Node 25 as unsupported", async () => {
const result = await runDoctor(
diff --git a/src/application/Doctor.ts b/src/application/Doctor.ts
index 1204391e1..face3e03d 100644
--- a/src/application/Doctor.ts
+++ b/src/application/Doctor.ts
@@ -108,6 +108,7 @@ export interface DoctorHost {
readonly runtime: JavaScriptRuntime;
readonly homeDirectory: string;
readonly configuredHopperPath?: string;
+ readonly configuredHopperStartupTimeout?: string;
readonly configuredIlspyCmdPath?: string;
macosVersion(): Promise<string | undefined>;
linuxDistribution(): Promise<LinuxDistribution | undefined>;
@@ -523,6 +524,12 @@ export const systemDoctorHost = (
...(environment.HOPPER_LAUNCHER_PATH === undefined
? {}
: { configuredHopperPath: environment.HOPPER_LAUNCHER_PATH }),
+ ...(environment.REA_HOPPER_STARTUP_TIMEOUT_MS === undefined
+ ? {}
+ : {
+ configuredHopperStartupTimeout:
+ environment.REA_HOPPER_STARTUP_TIMEOUT_MS,
+ }),
...(environment.REA_ILSPY_CMD_PATH === undefined
? {}
: { configuredIlspyCmdPath: environment.REA_ILSPY_CMD_PATH }),
diff --git a/src/application/DoctorDiagnostics.ts b/src/application/DoctorDiagnostics.ts
index a2e34d975..9f9526ad8 100644
--- a/src/application/DoctorDiagnostics.ts
+++ b/src/application/DoctorDiagnostics.ts
@@ -2,6 +2,7 @@ import {
SUPPORTED_NODE_VERSION_PROSE,
supportsNodeVersion,
} from "../domain/runtimeVersion.js";
+import { providerStartupTimeoutSchema } from "../config/providerStartupTimeout.js";
import {
linuxHopperLauncherCandidates,
systemLinuxHopperLauncherCandidates,
@@ -34,6 +35,8 @@ export const collectDoctorDiagnostics = async (
const hopperPath = await findHopper(host);
checks.push(hopperCheck(host, hopperPath));
+ const hopperTimeoutCheck = optionalHopperStartupTimeoutCheck(host);
+ if (hopperTimeoutCheck !== undefined) checks.push(hopperTimeoutCheck);
const hopperVersionCheck = await optionalHopperVersionCheck(host, hopperPath);
if (hopperVersionCheck !== undefined) checks.push(hopperVersionCheck);
@@ -80,6 +83,8 @@ export const doctorHealthy = (
.every(({ ok }) => ok);
const configuredProvidersHealthy = providerChecks
.filter(({ name }) => {
+ // Validate the supplied setting independently of provider discovery.
+ if (name === "hopper-startup-timeout") return true;
if (name.startsWith("hopper")) return providers.hopperConfigured;
return providers.providerInspections?.some(
(inspection) =>
@@ -204,6 +209,27 @@ const hopperCheck = (
},
);
+const optionalHopperStartupTimeoutCheck = (
+ host: DoctorHost,
+): DoctorCheck | undefined => {
+ if (host.configuredHopperStartupTimeout === undefined) return undefined;
+ const parsed = providerStartupTimeoutSchema.safeParse(
+ host.configuredHopperStartupTimeout,
+ );
+ return check(
+ "hopper-startup-timeout",
+ parsed.success,
+ parsed.success
+ ? `REA_HOPPER_STARTUP_TIMEOUT_MS=${String(parsed.data)}`
+ : `REA_HOPPER_STARTUP_TIMEOUT_MS: ${parsed.error.issues.map(({ message }) => message).join("; ")}`,
+ {
+ classification: "config_drift",
+ remediation:
+ "Unset REA_HOPPER_STARTUP_TIMEOUT_MS to use the default, or set it to a positive decimal integer from 1 to 2147483647 milliseconds.",
+ },
+ );
+};
+
const optionalHopperVersionCheck = async (
host: DoctorHost,
hopperPath: string | undefined,
diff --git a/src/setupEnvironment.test.ts b/src/setupEnvironment.test.ts
index 15d57a131..278a03f04 100644
--- a/src/setupEnvironment.test.ts
+++ b/src/setupEnvironment.test.ts
@@ -183,6 +183,7 @@ it.each([
environment: {
REA_ANALYSIS_PROVIDER: "auto",
REA_GHIDRA_STARTUP_TIMEOUT_MS: "2700000",
+ REA_HOPPER_STARTUP_TIMEOUT_MS: "120000",
REA_MCP_INPUT_SCHEMA_PROFILE: "full",
},
providerConfigured: false,
@@ -214,6 +215,7 @@ it.each([
expect(initial.providerEnvironment).toMatchObject({
REA_ANALYSIS_PROVIDER: "auto",
REA_GHIDRA_STARTUP_TIMEOUT_MS: "2700000",
+ REA_HOPPER_STARTUP_TIMEOUT_MS: "120000",
REA_MCP_INPUT_SCHEMA_PROFILE: "full",
});
}
diff --git a/tests/boundary/cli/doctorHopperDiscovery.test.ts b/tests/boundary/cli/doctorHopperDiscovery.test.ts
index db4e44260..1a33db49c 100644
--- a/tests/boundary/cli/doctorHopperDiscovery.test.ts
+++ b/tests/boundary/cli/doctorHopperDiscovery.test.ts
@@ -6,6 +6,60 @@ import { expect } from "vitest";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
import { cliTest } from "../../support/cli/cliFixture.js";
+cliTest.skipIf(!["darwin", "linux"].includes(process.platform))(
+ "reports invalid Hopper startup timeouts without launching the discovered engine",
+ async ({ cli }) => {
+ const home = await createTestTempDirectory("rea-doctor-hopper-timeout-");
+ const launcher = join(home, "hopper");
+ const marker = join(home, "launched");
+ await writeFile(launcher, `#!/bin/sh\nprintf launched > '${marker}'\n`);
+ await chmod(launcher, 0o700);
+
+ for (const [timeout, expectedExit] of [
+ ["0", 1],
+ ["120000", 0],
+ ] as const) {
+ const environment = {
+ ...(process.platform === "linux"
+ ? {
+ // Keep the foreign launcher unsupported without reaching the
+ // release network. This qualifies timeout diagnostics only.
+ NODE_OPTIONS: `--import=${new URL("../../fixtures/hopperRejectionFeed.mjs", import.meta.url).href}`,
+ }
+ : {}),
+ HOME: home,
+ HOPPER_LAUNCHER_PATH: launcher,
+ REA_HOPPER_STARTUP_TIMEOUT_MS: timeout,
+ GHIDRA_INSTALL_DIR: join(home, "missing-ghidra"),
+ };
+ const providers = await cli.run({
+ arguments: ["providers", "--json"],
+ environment,
+ });
+ expect(providers.exitCode).toBe(expectedExit);
+ const doctor = await cli.run({
+ arguments: ["doctor", "--provider", "hopper", "--json"],
+ environment,
+ });
+ // Linux independently rejects this shell fixture as a Hopper build.
+ const healthy = process.platform === "darwin" && expectedExit === 0;
+ expect(doctor.exitCode).toBe(healthy ? 0 : 1);
+ expect(doctor.json).toMatchObject({
+ healthy,
+ scope_checks: expect.arrayContaining([
+ expect.objectContaining({
+ name: "hopper-startup-timeout",
+ ok: expectedExit === 0,
+ classification: expectedExit === 0 ? "healthy" : "config_drift",
+ detail: expect.stringContaining("REA_HOPPER_STARTUP_TIMEOUT_MS"),
+ }),
+ ]),
+ });
+ }
+ await expect(access(marker)).rejects.toMatchObject({ code: "ENOENT" });
+ },
+);
+
cliTest.skipIf(!["darwin", "linux"].includes(process.platform))(
"retains a configured Hopper path in host diagnostics without launching it",
async ({ cli }) => {