test(linux): verify setup through CLI and MCP

This commit is contained in:
morluto
2026-07-13 21:20:51 +00:00
parent 75818d119e
commit 67504d2d51
20 changed files with 632 additions and 123 deletions
+9 -3
View File
@@ -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,
+23 -9
View File
@@ -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
View File
@@ -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) =>
+95
View File
@@ -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.",
};
}
};
+41
View File
@@ -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,
},
];