test(linux): verify setup through CLI and MCP
This commit is contained in:
@@ -121,8 +121,9 @@ export const runDoctor = async (
|
||||
await host.supportedLinuxHopper(hopperPath),
|
||||
hopperPath,
|
||||
{
|
||||
remediation:
|
||||
"Install the Hopper build supported by this REA release, or update REA for a newer Hopper build.",
|
||||
remediation: unsupportedHopperRemediation(
|
||||
host.configuredHopperPath === hopperPath,
|
||||
),
|
||||
classification: "config_drift",
|
||||
},
|
||||
),
|
||||
@@ -135,7 +136,7 @@ export const runDoctor = async (
|
||||
undefined,
|
||||
{
|
||||
remediation:
|
||||
"Rerun rea setup to install the Xvfb, Python, X11, and XTEST packages required for Linux demo sessions.",
|
||||
"Rerun rea setup to install the Xvfb, xauth, Python, X11, and XTEST packages required for Linux demo sessions.",
|
||||
classification: "missing_dependency",
|
||||
},
|
||||
),
|
||||
@@ -154,6 +155,11 @@ export const runDoctor = async (
|
||||
};
|
||||
};
|
||||
|
||||
const unsupportedHopperRemediation = (configured: boolean): string =>
|
||||
configured
|
||||
? "Unset or update HOPPER_LAUNCHER_PATH, install the Hopper build supported by this REA release, or update REA."
|
||||
: "Install the Hopper build supported by this REA release, or update REA for a newer Hopper build.";
|
||||
|
||||
/** Create diagnostics backed by the current process and host commands. */
|
||||
export const systemDoctorHost = (): DoctorHost => ({
|
||||
platform: process.platform,
|
||||
|
||||
@@ -62,7 +62,7 @@ export interface LinuxHopperInstallHost {
|
||||
createTemporaryDirectory(): Promise<string>;
|
||||
writeArchive(path: string, bytes: Uint8Array): Promise<void>;
|
||||
installPackage(family: LinuxPackageFamily, archive: string): Promise<boolean>;
|
||||
launcherReady(path: string): Promise<boolean>;
|
||||
launcherStatus(path: string): Promise<LinuxHopperLauncherStatus>;
|
||||
cleanup(path: string): Promise<void>;
|
||||
}
|
||||
|
||||
@@ -78,9 +78,17 @@ export type LinuxHopperInstallResult =
|
||||
| "integrity"
|
||||
| "authorization_or_package_manager"
|
||||
| "launcher_missing"
|
||||
| "runtime_dependencies"
|
||||
| "unsupported_hopper_build"
|
||||
| "cancelled";
|
||||
};
|
||||
|
||||
export type LinuxHopperLauncherStatus =
|
||||
| "ready"
|
||||
| "missing"
|
||||
| "runtime_dependencies"
|
||||
| "unsupported_hopper_build";
|
||||
|
||||
/** Parse an os-release document without executing its shell syntax. */
|
||||
export const parseLinuxDistribution = (text: string): LinuxDistribution => {
|
||||
const fields = new Map<string, string>();
|
||||
@@ -155,8 +163,13 @@ export const installLinuxHopper = async (
|
||||
if (!(await host.installPackage(distribution.packageFamily, archive)))
|
||||
return { status: "failed", reason: "authorization_or_package_manager" };
|
||||
const launcherPath = "/opt/hopper/bin/Hopper";
|
||||
if (!(await host.launcherReady(launcherPath)))
|
||||
return { status: "failed", reason: "launcher_missing" };
|
||||
const launcherStatus = await host.launcherStatus(launcherPath);
|
||||
if (launcherStatus !== "ready")
|
||||
return {
|
||||
status: "failed",
|
||||
reason:
|
||||
launcherStatus === "missing" ? "launcher_missing" : launcherStatus,
|
||||
};
|
||||
return { status: "installed", launcherPath };
|
||||
} catch (cause: unknown) {
|
||||
if (isAbortCause(cause)) return { status: "failed", reason: "cancelled" };
|
||||
@@ -185,16 +198,17 @@ const systemLinuxHopperInstallHost = (): LinuxHopperInstallHost => ({
|
||||
createTemporaryDirectory: () => mkdtemp(join(tmpdir(), "rea-hopper-")),
|
||||
writeArchive: (path, bytes) => writeFile(path, bytes, { mode: 0o600 }),
|
||||
installPackage: installSystemPackage,
|
||||
async launcherReady(path) {
|
||||
async launcherStatus(path) {
|
||||
try {
|
||||
await access(path);
|
||||
const linked = await execFileAsync("ldd", [path]);
|
||||
return (
|
||||
linuxSharedLibrariesAvailable(`${linked.stdout}\n${linked.stderr}`) &&
|
||||
(await linuxHopperBinarySupported(path))
|
||||
);
|
||||
if (!linuxSharedLibrariesAvailable(`${linked.stdout}\n${linked.stderr}`))
|
||||
return "runtime_dependencies";
|
||||
return (await linuxHopperBinarySupported(path))
|
||||
? "ready"
|
||||
: "unsupported_hopper_build";
|
||||
} catch {
|
||||
return false;
|
||||
return "missing";
|
||||
}
|
||||
},
|
||||
cleanup: (path) => rm(path, { recursive: true, force: true }),
|
||||
|
||||
+19
-45
@@ -24,6 +24,16 @@ import {
|
||||
import { installMacHopper } from "./MacHopper.js";
|
||||
import { configureDetectedClients } from "./SetupClients.js";
|
||||
import { installCanonicalSkill } from "./SetupSkill.js";
|
||||
import { setupPlan } from "./SetupPlan.js";
|
||||
import {
|
||||
setupInstallFailure,
|
||||
type SetupFailureCode,
|
||||
type SetupHopperInstallResult,
|
||||
} from "./SetupInstallFailure.js";
|
||||
export type {
|
||||
SetupFailureCode,
|
||||
SetupHopperInstallResult,
|
||||
} from "./SetupInstallFailure.js";
|
||||
|
||||
export { installCanonicalSkill } from "./SetupSkill.js";
|
||||
|
||||
@@ -60,7 +70,7 @@ export interface SetupHost {
|
||||
macosVersion(): Promise<string | undefined>;
|
||||
linuxDistribution(): Promise<LinuxDistribution | undefined>;
|
||||
hopperPath(): Promise<string | undefined>;
|
||||
installHopper(): Promise<string | undefined>;
|
||||
installHopper(): Promise<SetupHopperInstallResult>;
|
||||
detectedClients(): Promise<readonly SetupClient[]>;
|
||||
configureClient(
|
||||
client: SetupClient,
|
||||
@@ -82,6 +92,7 @@ export interface SetupResult {
|
||||
readonly clients: Readonly<Record<string, ClientConfigurationResult>>;
|
||||
readonly doctor: Awaited<ReturnType<typeof runDoctor>>;
|
||||
readonly remediation?: string;
|
||||
readonly code?: SetupFailureCode;
|
||||
}
|
||||
|
||||
/** One concrete setup mutation disclosed before approval. */
|
||||
@@ -104,45 +115,6 @@ export type SetupConfirmation = (
|
||||
actions: readonly SetupAction[],
|
||||
) => Promise<boolean>;
|
||||
|
||||
const setupPlan = (
|
||||
platform: NodeJS.Platform,
|
||||
installHopper: boolean,
|
||||
clients: readonly SetupClient[],
|
||||
): readonly SetupAction[] => [
|
||||
...(installHopper
|
||||
? [
|
||||
{
|
||||
kind: "install_hopper" as const,
|
||||
target:
|
||||
platform === "darwin"
|
||||
? "~/Applications/Hopper Disassembler.app"
|
||||
: "system package manager",
|
||||
detail:
|
||||
platform === "linux"
|
||||
? "Download, verify, and install Hopper plus its Xvfb demo-session dependencies. For the supported demo build, REA uses a private display and selects Hopper's offered demo mode for each analysis session."
|
||||
: "Download the official Hopper package, verify it, and install it. Hopper may show its demo or license prompt when first opened.",
|
||||
external: true,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
...clients
|
||||
.filter(({ format }) => format !== "unsupported")
|
||||
.map(
|
||||
(client): SetupAction => ({
|
||||
kind: "configure_client",
|
||||
target: client.configPath,
|
||||
detail: `Add the REA MCP registration for ${client.name}; preserve unrelated configuration.`,
|
||||
external: false,
|
||||
}),
|
||||
),
|
||||
{
|
||||
kind: "install_skill",
|
||||
target: "~/.agents/skills/rea-analysis/SKILL.md",
|
||||
detail: "Install or update the bundled REA analysis skill.",
|
||||
external: false,
|
||||
},
|
||||
];
|
||||
|
||||
/**
|
||||
* Install prerequisites and configure detected clients idempotently.
|
||||
* Discovery always precedes mutation. Interactive confirmation or explicit
|
||||
@@ -195,17 +167,18 @@ export const runSetup = async (
|
||||
};
|
||||
|
||||
if (installHopper && (interactiveApproval || options.installHopper)) {
|
||||
hopperPath = await host.installHopper();
|
||||
if (hopperPath === undefined)
|
||||
const installed = await host.installHopper();
|
||||
if (installed.status === "failed")
|
||||
return {
|
||||
status: "needs_human",
|
||||
plannedActions,
|
||||
appliedActions,
|
||||
clients,
|
||||
doctor: await host.doctor(),
|
||||
remediation:
|
||||
"Hopper installation failed; install Hopper manually or rerun setup after resolving the reported system error.",
|
||||
code: installed.code,
|
||||
remediation: installed.remediation,
|
||||
};
|
||||
hopperPath = installed.launcherPath;
|
||||
appliedActions.push("installed_hopper");
|
||||
}
|
||||
const clientFailure = await configureDetectedClients({
|
||||
@@ -286,7 +259,8 @@ const systemSetupHost = (): SetupHost => {
|
||||
process.platform === "linux"
|
||||
? await installLinuxHopper()
|
||||
: await installMacHopper();
|
||||
return result.status === "installed" ? result.launcherPath : undefined;
|
||||
if (result.status === "installed") return result;
|
||||
return setupInstallFailure(result.reason);
|
||||
},
|
||||
detectedClients: () => detectClients(homedir()),
|
||||
configureClient: (client, hopperPath, command) =>
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
export type SetupFailureCode =
|
||||
| "unsupported_host"
|
||||
| "download_failed"
|
||||
| "integrity_mismatch"
|
||||
| "authorization_or_package_manager_failed"
|
||||
| "launcher_missing"
|
||||
| "runtime_dependency_unavailable"
|
||||
| "unsupported_hopper_build"
|
||||
| "setup_cancelled";
|
||||
|
||||
export type SetupHopperInstallResult =
|
||||
| { readonly status: "installed"; readonly launcherPath: string }
|
||||
| {
|
||||
readonly status: "failed";
|
||||
readonly code: SetupFailureCode;
|
||||
readonly remediation: string;
|
||||
};
|
||||
|
||||
export type HopperInstallFailureReason =
|
||||
| "unsupported_host"
|
||||
| "release_metadata"
|
||||
| "download"
|
||||
| "integrity"
|
||||
| "authorization_or_package_manager"
|
||||
| "launcher_missing"
|
||||
| "runtime_dependencies"
|
||||
| "unsupported_hopper_build"
|
||||
| "cancelled"
|
||||
| "destination_exists"
|
||||
| "mount"
|
||||
| "bundle"
|
||||
| "copy";
|
||||
|
||||
/** Map provider installer failures to stable setup codes and safe recovery. */
|
||||
export const setupInstallFailure = (
|
||||
reason: HopperInstallFailureReason,
|
||||
): SetupHopperInstallResult => {
|
||||
switch (reason) {
|
||||
case "unsupported_host":
|
||||
return {
|
||||
status: "failed",
|
||||
code: "unsupported_host",
|
||||
remediation: "Use a supported host, then rerun rea setup.",
|
||||
};
|
||||
case "integrity":
|
||||
return {
|
||||
status: "failed",
|
||||
code: "integrity_mismatch",
|
||||
remediation:
|
||||
"The Hopper download failed integrity verification. Retry setup; if it repeats, update REA before installing.",
|
||||
};
|
||||
case "authorization_or_package_manager":
|
||||
return {
|
||||
status: "failed",
|
||||
code: "authorization_or_package_manager_failed",
|
||||
remediation:
|
||||
"Allow the system package-manager operation or install the planned Hopper package and Linux runtime dependencies, then rerun rea setup.",
|
||||
};
|
||||
case "launcher_missing":
|
||||
return {
|
||||
status: "failed",
|
||||
code: "launcher_missing",
|
||||
remediation:
|
||||
"The package operation completed but Hopper is not runnable. Run rea doctor and repair the reported launcher issue.",
|
||||
};
|
||||
case "runtime_dependencies":
|
||||
return {
|
||||
status: "failed",
|
||||
code: "runtime_dependency_unavailable",
|
||||
remediation:
|
||||
"Hopper was installed but required shared libraries are missing. Rerun rea setup, then apply the hopper-demo-runtime remediation from rea doctor.",
|
||||
};
|
||||
case "unsupported_hopper_build":
|
||||
return {
|
||||
status: "failed",
|
||||
code: "unsupported_hopper_build",
|
||||
remediation:
|
||||
"The installed Hopper launcher does not match the build supported by this REA release. Unset HOPPER_LAUNCHER_PATH, reinstall through rea setup, or update REA.",
|
||||
};
|
||||
case "cancelled":
|
||||
return {
|
||||
status: "failed",
|
||||
code: "setup_cancelled",
|
||||
remediation:
|
||||
"Setup was cancelled before Hopper was installed. Rerun rea setup when ready.",
|
||||
};
|
||||
default:
|
||||
return {
|
||||
status: "failed",
|
||||
code: "download_failed",
|
||||
remediation:
|
||||
"REA could not download or unpack the official Hopper package. Check network and filesystem access, then retry setup.",
|
||||
};
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,41 @@
|
||||
import type { SetupAction, SetupClient } from "./Setup.js";
|
||||
|
||||
/** Build the complete setup mutation plan before approval. */
|
||||
export const setupPlan = (
|
||||
platform: NodeJS.Platform,
|
||||
installHopper: boolean,
|
||||
clients: readonly SetupClient[],
|
||||
): readonly SetupAction[] => [
|
||||
...(installHopper
|
||||
? [
|
||||
{
|
||||
kind: "install_hopper" as const,
|
||||
target:
|
||||
platform === "darwin"
|
||||
? "~/Applications/Hopper Disassembler.app"
|
||||
: "system package manager",
|
||||
detail:
|
||||
platform === "linux"
|
||||
? "Download, verify, and install Hopper plus its Xvfb demo-session dependencies. For the supported demo build, REA uses a private display and selects Hopper's offered demo mode for each analysis session."
|
||||
: "Download the official Hopper package, verify it, and install it. Hopper may show its demo or license prompt when first opened.",
|
||||
external: true,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
...clients
|
||||
.filter(({ format }) => format !== "unsupported")
|
||||
.map(
|
||||
(client): SetupAction => ({
|
||||
kind: "configure_client",
|
||||
target: client.configPath,
|
||||
detail: `Add the REA MCP registration for ${client.name}; preserve unrelated configuration.`,
|
||||
external: false,
|
||||
}),
|
||||
),
|
||||
{
|
||||
kind: "install_skill",
|
||||
target: "~/.agents/skills/rea-analysis/SKILL.md",
|
||||
detail: "Install or update the bundled REA analysis skill.",
|
||||
external: false,
|
||||
},
|
||||
];
|
||||
@@ -191,6 +191,20 @@ const analysisErrorProjectionSchema = z
|
||||
"execution_failure",
|
||||
]),
|
||||
message: z.string(),
|
||||
code: z
|
||||
.enum([
|
||||
"private_display_unavailable",
|
||||
"x11_authorization_failed",
|
||||
"unsupported_hopper_build",
|
||||
"invalid_launch_command",
|
||||
"process_ownership_mismatch",
|
||||
"hopper_exited_during_startup",
|
||||
"unsupported_demo_dialog",
|
||||
"unexpected_display_geometry",
|
||||
"x11_input_failed",
|
||||
"runtime_dependency_unavailable",
|
||||
])
|
||||
.optional(),
|
||||
})
|
||||
.strict();
|
||||
const graphNode = z.discriminatedUnion("status", [
|
||||
|
||||
+14
-4
@@ -1,4 +1,10 @@
|
||||
import type { JsonValue } from "./jsonValue.js";
|
||||
import {
|
||||
hopperStartupFailure,
|
||||
type HopperStartupFailureCode,
|
||||
} from "./hopperStartupFailure.js";
|
||||
export { hopperStartupFailure } from "./hopperStartupFailure.js";
|
||||
export type { HopperStartupFailureCode } from "./hopperStartupFailure.js";
|
||||
|
||||
/** Stable tags exposed by safe analysis-error projections. */
|
||||
const ANALYSIS_ERROR_TAGS = [
|
||||
@@ -282,14 +288,14 @@ export class HopperRemoteError extends HopperError {
|
||||
/** The owned Hopper bridge stopped before its client was closed. */
|
||||
export class HopperProcessError extends HopperError {
|
||||
readonly _tag = "HopperProcessError";
|
||||
readonly failureCode: HopperStartupFailureCode | undefined;
|
||||
override readonly userMessage: string | undefined;
|
||||
|
||||
constructor(readonly exitCode: number | null) {
|
||||
super(`Hopper bridge stopped unexpectedly with code ${String(exitCode)}`);
|
||||
this.userMessage =
|
||||
exitCode === 78
|
||||
? "This Hopper demo build or dialog is not supported for unattended Linux analysis. Update REA or use a supported Hopper build."
|
||||
: undefined;
|
||||
const failure = hopperStartupFailure(exitCode);
|
||||
this.failureCode = failure?.code;
|
||||
this.userMessage = failure?.message;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -342,6 +348,7 @@ export interface AnalysisErrorProjection
|
||||
| "unavailable"
|
||||
| "execution_failure";
|
||||
readonly message: string;
|
||||
readonly code?: HopperStartupFailureCode;
|
||||
}
|
||||
|
||||
/** Project expected failures into exhaustive, secret-safe caller fields. */
|
||||
@@ -349,9 +356,12 @@ export const projectAnalysisError = (
|
||||
error: AnalysisError,
|
||||
): AnalysisErrorProjection => {
|
||||
assertKnownTag(error._tag);
|
||||
const code =
|
||||
error instanceof HopperProcessError ? error.failureCode : undefined;
|
||||
return {
|
||||
category: errorCategory(error),
|
||||
message: userMessage(error),
|
||||
...(code === undefined ? {} : { code }),
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
export type HopperStartupFailureCode =
|
||||
| "private_display_unavailable"
|
||||
| "x11_authorization_failed"
|
||||
| "unsupported_hopper_build"
|
||||
| "invalid_launch_command"
|
||||
| "process_ownership_mismatch"
|
||||
| "hopper_exited_during_startup"
|
||||
| "unsupported_demo_dialog"
|
||||
| "unexpected_display_geometry"
|
||||
| "x11_input_failed"
|
||||
| "runtime_dependency_unavailable";
|
||||
|
||||
const failures = [
|
||||
[
|
||||
70,
|
||||
"private_display_unavailable",
|
||||
"REA could not start its private Linux display. Install Xvfb, then rerun rea doctor.",
|
||||
],
|
||||
[
|
||||
71,
|
||||
"x11_authorization_failed",
|
||||
"REA could not authorize its private Linux display. Install xauth, then rerun rea doctor.",
|
||||
],
|
||||
[
|
||||
72,
|
||||
"unsupported_hopper_build",
|
||||
"This Hopper build is not supported for unattended Linux analysis. Unset HOPPER_LAUNCHER_PATH and rerun rea setup --yes --install-hopper, or update REA.",
|
||||
],
|
||||
[
|
||||
73,
|
||||
"invalid_launch_command",
|
||||
"REA refused an unexpected Hopper launch command. Check HOPPER_LAUNCHER_PATH and rerun rea doctor.",
|
||||
],
|
||||
[
|
||||
74,
|
||||
"process_ownership_mismatch",
|
||||
"REA could not verify ownership of the launched Hopper process and stopped safely. Close other Hopper sessions and retry.",
|
||||
],
|
||||
[
|
||||
75,
|
||||
"hopper_exited_during_startup",
|
||||
"Hopper exited before the REA bridge was ready. Run rea doctor and retry the analysis.",
|
||||
],
|
||||
[
|
||||
76,
|
||||
"unsupported_demo_dialog",
|
||||
"This Hopper demo dialog is not supported for unattended Linux analysis. Update REA or use a supported Hopper build.",
|
||||
],
|
||||
[
|
||||
77,
|
||||
"unexpected_display_geometry",
|
||||
"REA's private Linux display did not match the validated layout. Close custom display overrides and retry.",
|
||||
],
|
||||
[
|
||||
78,
|
||||
"x11_input_failed",
|
||||
"REA could not activate Hopper's validated demo control. Install the XTEST runtime, then rerun rea doctor.",
|
||||
],
|
||||
[
|
||||
79,
|
||||
"runtime_dependency_unavailable",
|
||||
"A Linux demo-session dependency is unavailable. Rerun rea setup --yes --install-hopper, then rea doctor.",
|
||||
],
|
||||
] as const;
|
||||
|
||||
const HOPPER_STARTUP_FAILURES = new Map<
|
||||
number,
|
||||
{ readonly code: HopperStartupFailureCode; readonly message: string }
|
||||
>(failures.map(([exitCode, code, message]) => [exitCode, { code, message }]));
|
||||
|
||||
/** Return the stable public failure associated with a Linux demo adapter exit. */
|
||||
export const hopperStartupFailure = (exitCode: number | null) =>
|
||||
exitCode === null ? undefined : HOPPER_STARTUP_FAILURES.get(exitCode);
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
HopperProcessError,
|
||||
HopperProtocolError,
|
||||
HopperStartError,
|
||||
hopperStartupFailure,
|
||||
HopperTimeoutError,
|
||||
} from "../domain/errors.js";
|
||||
import { err, ok, type Result } from "../domain/result.js";
|
||||
@@ -212,7 +213,10 @@ export class HopperClient {
|
||||
while (Date.now() < deadline) {
|
||||
if (signal?.aborted === true) return err(new HopperCancelledError());
|
||||
if (this.#closing) return err(new HopperProcessError(null));
|
||||
if (this.#launcherExitCode === 78)
|
||||
if (
|
||||
this.#launcherExitCode !== undefined &&
|
||||
hopperStartupFailure(this.#launcherExitCode) !== undefined
|
||||
)
|
||||
return err(new HopperProcessError(this.#launcherExitCode));
|
||||
try {
|
||||
await access(socketPath);
|
||||
|
||||
Reference in New Issue
Block a user