fix(linux): start Hopper demo sessions headlessly
This commit is contained in:
@@ -10,6 +10,7 @@ import { parseBinaryTarget } from "../domain/binaryTarget.js";
|
||||
import { supportsNodeVersion } from "../domain/runtimeVersion.js";
|
||||
import { probeHomebrew } from "./homebrew.js";
|
||||
import {
|
||||
linuxHopperBinarySupported,
|
||||
linuxHopperLauncherPath,
|
||||
linuxSharedLibrariesAvailable,
|
||||
readLinuxDistribution,
|
||||
@@ -43,6 +44,8 @@ export interface DoctorHost {
|
||||
linuxDistribution(): Promise<LinuxDistribution | undefined>;
|
||||
validTarget(path: string): Promise<boolean>;
|
||||
executable(path: string): Promise<boolean>;
|
||||
supportedLinuxHopper(path: string): Promise<boolean>;
|
||||
linuxDemoRuntimeReady(): Promise<boolean>;
|
||||
brewHopperPath(): Promise<string | undefined>;
|
||||
manualHopperPaths(): Promise<readonly string[]>;
|
||||
}
|
||||
@@ -111,6 +114,32 @@ export const runDoctor = async (
|
||||
classification: "missing_analysis_engine",
|
||||
}),
|
||||
);
|
||||
if (host.platform === "linux" && hopperPath !== undefined)
|
||||
checks.push(
|
||||
check(
|
||||
"hopper-version",
|
||||
await host.supportedLinuxHopper(hopperPath),
|
||||
hopperPath,
|
||||
{
|
||||
remediation:
|
||||
"Install the Hopper build supported by this REA release, or update REA for a newer Hopper build.",
|
||||
classification: "config_drift",
|
||||
},
|
||||
),
|
||||
);
|
||||
if (host.platform === "linux" && hopperPath !== undefined)
|
||||
checks.push(
|
||||
check(
|
||||
"hopper-demo-runtime",
|
||||
await host.linuxDemoRuntimeReady(),
|
||||
undefined,
|
||||
{
|
||||
remediation:
|
||||
"Rerun rea setup to install the Xvfb, Python, X11, and XTEST packages required for Linux demo sessions.",
|
||||
classification: "missing_dependency",
|
||||
},
|
||||
),
|
||||
);
|
||||
if (target !== undefined)
|
||||
checks.push(
|
||||
check("target", await host.validTarget(target), target, {
|
||||
@@ -160,6 +189,21 @@ export const systemDoctorHost = (): DoctorHost => ({
|
||||
return false;
|
||||
}
|
||||
},
|
||||
async linuxDemoRuntimeReady() {
|
||||
try {
|
||||
await access("/usr/bin/Xvfb", constants.X_OK);
|
||||
await access("/usr/bin/xauth", constants.X_OK);
|
||||
await access("/usr/bin/python3", constants.X_OK);
|
||||
await execFileAsync("/usr/bin/python3", [
|
||||
"-c",
|
||||
"import ctypes; ctypes.CDLL('libX11.so.6'); ctypes.CDLL('libXtst.so.6')",
|
||||
]);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
supportedLinuxHopper: linuxHopperBinarySupported,
|
||||
async brewHopperPath() {
|
||||
return probeHomebrew(async (command) => {
|
||||
try {
|
||||
|
||||
@@ -1,17 +1,40 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { execFile } from "node:child_process";
|
||||
import { createReadStream } from "node:fs";
|
||||
import { access, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
import { z } from "zod";
|
||||
|
||||
const execFileAsync = promisify(execFile);
|
||||
const RELEASES_URL =
|
||||
"https://www.hopperapp.com/include/files-api.php?request=releases&public=true";
|
||||
const DOWNLOAD_PREFIX = "https://www.hopperapp.com:443/downloader/public/";
|
||||
const MAX_PACKAGE_BYTES = 100_000_000;
|
||||
const SUPPORTED_HOPPER_SHA256 =
|
||||
"0294ced141cc373468ee22d8343e7dac41980cb05a937994ca81c9f09afe7ded";
|
||||
interface LinuxHopperRelease {
|
||||
readonly filename: string;
|
||||
readonly file_length: string;
|
||||
readonly file_hash: string;
|
||||
}
|
||||
const SUPPORTED_RELEASES: Readonly<
|
||||
Record<LinuxPackageFamily, LinuxHopperRelease>
|
||||
> = {
|
||||
deb: {
|
||||
filename: `${DOWNLOAD_PREFIX}Hopper-6.4.2-Linux-demo.deb`,
|
||||
file_length: "35755772",
|
||||
file_hash: "e4f79dff602648a8ff4a88b773875b6bfac0dc65",
|
||||
},
|
||||
rpm: {
|
||||
filename: `${DOWNLOAD_PREFIX}Hopper-6.4.2-Linux-demo.rpm`,
|
||||
file_length: "32264475",
|
||||
file_hash: "b9a65f2f583a386d440d4401d9140aef3bf305de",
|
||||
},
|
||||
arch: {
|
||||
filename: `${DOWNLOAD_PREFIX}Hopper-6.4.2-Linux-demo.pkg.tar.xz`,
|
||||
file_length: "29405968",
|
||||
file_hash: "92d780b61cab38eda95dc4112dee4fbeb0920f46",
|
||||
},
|
||||
};
|
||||
|
||||
export type LinuxPackageFamily = "deb" | "rpm" | "arch";
|
||||
|
||||
@@ -102,7 +125,12 @@ export const readLinuxDistribution = async (): Promise<
|
||||
/** Download, verify, install, and read back the official Hopper Linux package. */
|
||||
export const installLinuxHopper = async (
|
||||
host: LinuxHopperInstallHost = systemLinuxHopperInstallHost(),
|
||||
options: { readonly signal?: AbortSignal } = {},
|
||||
options: {
|
||||
readonly signal?: AbortSignal;
|
||||
readonly releases?: Readonly<
|
||||
Record<LinuxPackageFamily, LinuxHopperRelease>
|
||||
>;
|
||||
} = {},
|
||||
): Promise<LinuxHopperInstallResult> => {
|
||||
if (options.signal?.aborted === true)
|
||||
return { status: "failed", reason: "cancelled" };
|
||||
@@ -114,15 +142,9 @@ export const installLinuxHopper = async (
|
||||
return { status: "failed", reason: "unsupported_host" };
|
||||
let temporary: string | undefined;
|
||||
try {
|
||||
const metadataDownload = await host.download(RELEASES_URL, options);
|
||||
if (!metadataDownload.ok)
|
||||
return { status: "failed", reason: "release_metadata" };
|
||||
const releases = parseReleases(metadataDownload.bytes);
|
||||
if (releases === undefined)
|
||||
return { status: "failed", reason: "release_metadata" };
|
||||
const release = releases[releaseKey(distribution.packageFamily)];
|
||||
if (!release.filename.startsWith(DOWNLOAD_PREFIX))
|
||||
return { status: "failed", reason: "release_metadata" };
|
||||
const release = (options.releases ?? SUPPORTED_RELEASES)[
|
||||
distribution.packageFamily
|
||||
];
|
||||
const archiveDownload = await host.download(release.filename, options);
|
||||
if (!archiveDownload.ok) return { status: "failed", reason: "download" };
|
||||
if (!packageIntegrityMatches(archiveDownload.bytes, release))
|
||||
@@ -167,8 +189,9 @@ const systemLinuxHopperInstallHost = (): LinuxHopperInstallHost => ({
|
||||
try {
|
||||
await access(path);
|
||||
const linked = await execFileAsync("ldd", [path]);
|
||||
return linuxSharedLibrariesAvailable(
|
||||
`${linked.stdout}\n${linked.stderr}`,
|
||||
return (
|
||||
linuxSharedLibrariesAvailable(`${linked.stdout}\n${linked.stderr}`) &&
|
||||
(await linuxHopperBinarySupported(path))
|
||||
);
|
||||
} catch {
|
||||
return false;
|
||||
@@ -177,6 +200,19 @@ const systemLinuxHopperInstallHost = (): LinuxHopperInstallHost => ({
|
||||
cleanup: (path) => rm(path, { recursive: true, force: true }),
|
||||
});
|
||||
|
||||
/** Match the Linux Hopper build validated by the packaged demo-dialog adapter. */
|
||||
export const linuxHopperBinarySupported = async (
|
||||
path: string,
|
||||
): Promise<boolean> => {
|
||||
try {
|
||||
const hash = createHash("sha256");
|
||||
for await (const chunk of createReadStream(path)) hash.update(chunk);
|
||||
return hash.digest("hex") === SUPPORTED_HOPPER_SHA256;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
/** Interpret ldd output conservatively so a present but broken launcher is unhealthy. */
|
||||
export const linuxSharedLibrariesAvailable = (output: string): boolean =>
|
||||
!/(?:=>\s+not found|error while loading shared libraries)/iu.test(output);
|
||||
@@ -186,12 +222,12 @@ const installSystemPackage = async (
|
||||
archive: string,
|
||||
): Promise<boolean> => {
|
||||
try {
|
||||
const command = linuxPackageManagerCommand(
|
||||
for (const command of linuxPackageManagerCommands(
|
||||
family,
|
||||
archive,
|
||||
process.getuid?.() === 0,
|
||||
);
|
||||
await execFileAsync(command.executable, command.args);
|
||||
))
|
||||
await execFileAsync(command.executable, command.args);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
@@ -199,37 +235,45 @@ const installSystemPackage = async (
|
||||
};
|
||||
|
||||
/** Select the native package manager and authorization boundary without shell evaluation. */
|
||||
export const linuxPackageManagerCommand = (
|
||||
export const linuxPackageManagerCommands = (
|
||||
family: LinuxPackageFamily,
|
||||
archive: string,
|
||||
isRoot: boolean,
|
||||
): { readonly executable: string; readonly args: readonly string[] } => {
|
||||
const command =
|
||||
): readonly {
|
||||
readonly executable: string;
|
||||
readonly args: readonly string[];
|
||||
}[] => {
|
||||
const runtimeDependencies =
|
||||
family === "deb"
|
||||
? ["apt-get", "install", "-y", archive]
|
||||
? ["xvfb", "xauth", "python3", "libx11-6", "libxtst6"]
|
||||
: family === "rpm"
|
||||
? ["dnf", "install", "-y", archive]
|
||||
: ["pacman", "-U", "--noconfirm", archive];
|
||||
const executable = isRoot ? command[0] : "pkexec";
|
||||
if (executable === undefined) throw new Error("package command is empty");
|
||||
return { executable, args: isRoot ? command.slice(1) : command };
|
||||
};
|
||||
|
||||
const parseReleases = (
|
||||
bytes: Uint8Array,
|
||||
): z.infer<typeof releasesSchema> | undefined => {
|
||||
try {
|
||||
const parsed: unknown = JSON.parse(new TextDecoder().decode(bytes));
|
||||
const result = releasesSchema.safeParse(parsed);
|
||||
return result.success ? result.data : undefined;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
? [
|
||||
"xorg-x11-server-Xvfb",
|
||||
"xorg-x11-xauth",
|
||||
"python3",
|
||||
"libX11",
|
||||
"libXtst",
|
||||
]
|
||||
: ["xorg-server-xvfb", "xorg-xauth", "python", "libx11", "libxtst"];
|
||||
const commands =
|
||||
family === "deb"
|
||||
? [["apt-get", "install", "-y", archive, ...runtimeDependencies]]
|
||||
: family === "rpm"
|
||||
? [["dnf", "install", "-y", archive, ...runtimeDependencies]]
|
||||
: [
|
||||
["pacman", "-S", "--needed", "--noconfirm", ...runtimeDependencies],
|
||||
["pacman", "-U", "--noconfirm", archive],
|
||||
];
|
||||
return commands.map((command) => {
|
||||
const executable = isRoot ? command[0] : "pkexec";
|
||||
if (executable === undefined) throw new Error("package command is empty");
|
||||
return { executable, args: isRoot ? command.slice(1) : command };
|
||||
});
|
||||
};
|
||||
|
||||
const packageIntegrityMatches = (
|
||||
bytes: Uint8Array,
|
||||
release: z.infer<typeof releaseSchema>,
|
||||
release: LinuxHopperRelease,
|
||||
): boolean =>
|
||||
bytes.byteLength === Number(release.file_length) &&
|
||||
bytes.byteLength <= MAX_PACKAGE_BYTES &&
|
||||
@@ -255,19 +299,5 @@ const versionAtLeast = (
|
||||
): boolean =>
|
||||
version !== undefined &&
|
||||
Number.parseInt(version.split(".")[0] ?? "0", 10) >= minimum;
|
||||
const releaseKey = (
|
||||
family: LinuxPackageFamily,
|
||||
): "Ubuntu / Mint" | "Fedora" | "Arch" =>
|
||||
family === "deb" ? "Ubuntu / Mint" : family === "rpm" ? "Fedora" : "Arch";
|
||||
const isAbortCause = (cause: unknown): boolean =>
|
||||
cause instanceof Error && cause.name === "AbortError";
|
||||
const releaseSchema = z.object({
|
||||
filename: z.string().url(),
|
||||
file_length: z.string().regex(/^\d+$/u),
|
||||
file_hash: z.string().regex(/^[a-f0-9]{40}$/u),
|
||||
});
|
||||
const releasesSchema = z.object({
|
||||
"Ubuntu / Mint": releaseSchema,
|
||||
Fedora: releaseSchema,
|
||||
Arch: releaseSchema,
|
||||
});
|
||||
|
||||
+37
-20
@@ -106,10 +106,10 @@ export type SetupConfirmation = (
|
||||
|
||||
const setupPlan = (
|
||||
platform: NodeJS.Platform,
|
||||
hopperPath: string | undefined,
|
||||
installHopper: boolean,
|
||||
clients: readonly SetupClient[],
|
||||
): readonly SetupAction[] => [
|
||||
...(hopperPath === undefined
|
||||
...(installHopper
|
||||
? [
|
||||
{
|
||||
kind: "install_hopper" as const,
|
||||
@@ -118,7 +118,9 @@ const setupPlan = (
|
||||
? "~/Applications/Hopper Disassembler.app"
|
||||
: "system package manager",
|
||||
detail:
|
||||
"Download the official Hopper package, verify it, install it, and open Hopper for activation.",
|
||||
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,
|
||||
},
|
||||
]
|
||||
@@ -165,8 +167,16 @@ export const runSetup = async (
|
||||
const unsupported = await hostRemediation(host);
|
||||
if (unsupported !== undefined) return fail(unsupported);
|
||||
let hopperPath = await host.hopperPath();
|
||||
const initialDoctor = await host.doctor();
|
||||
const linuxHopperRepairNeeded = initialDoctor.checks.some(
|
||||
({ name, ok, detail }) =>
|
||||
!ok &&
|
||||
(name === "hopper-demo-runtime" ||
|
||||
(name === "hopper-version" && detail === "/opt/hopper/bin/Hopper")),
|
||||
);
|
||||
const installHopper = hopperPath === undefined || linuxHopperRepairNeeded;
|
||||
const detectedClients = await host.detectedClients();
|
||||
plannedActions = setupPlan(host.platform, hopperPath, detectedClients);
|
||||
plannedActions = setupPlan(host.platform, installHopper, detectedClients);
|
||||
let approved = options.approved;
|
||||
let interactiveApproval = false;
|
||||
if (!approved && confirm !== undefined && !options.structured) {
|
||||
@@ -184,10 +194,7 @@ export const runSetup = async (
|
||||
"Review the setup plan, then rerun interactively or with --yes.",
|
||||
};
|
||||
|
||||
if (
|
||||
hopperPath === undefined &&
|
||||
(interactiveApproval || options.installHopper)
|
||||
) {
|
||||
if (installHopper && (interactiveApproval || options.installHopper)) {
|
||||
hopperPath = await host.installHopper();
|
||||
if (hopperPath === undefined)
|
||||
return {
|
||||
@@ -217,26 +224,36 @@ export const runSetup = async (
|
||||
);
|
||||
if (skill === "installed") appliedActions.push("installed_skill");
|
||||
const doctor = await host.doctor();
|
||||
const activationRequired = appliedActions.includes("installed_hopper");
|
||||
const ready = doctor.healthy && !activationRequired;
|
||||
const remediation = finalSetupRemediation(
|
||||
host.platform,
|
||||
appliedActions.includes("installed_hopper"),
|
||||
doctor.healthy,
|
||||
hopperPath,
|
||||
);
|
||||
return {
|
||||
status: ready ? "ready" : "needs_human",
|
||||
status: remediation === undefined ? "ready" : "needs_human",
|
||||
plannedActions,
|
||||
appliedActions,
|
||||
clients,
|
||||
doctor,
|
||||
...(ready
|
||||
? {}
|
||||
: {
|
||||
remediation: activationRequired
|
||||
? "Open Hopper, complete its one-time activation, then rerun rea doctor --json."
|
||||
: hopperPath === undefined
|
||||
? "Hopper is optional for non-Hopper providers. Rerun with --yes --install-hopper for deep native analysis."
|
||||
: "Run rea doctor and apply each reported remediation.",
|
||||
}),
|
||||
...(remediation === undefined ? {} : { remediation }),
|
||||
};
|
||||
};
|
||||
|
||||
const finalSetupRemediation = (
|
||||
platform: NodeJS.Platform,
|
||||
installedHopper: boolean,
|
||||
healthy: boolean,
|
||||
hopperPath: string | undefined,
|
||||
): string | undefined => {
|
||||
if (platform === "darwin" && installedHopper)
|
||||
return "Open Hopper, choose its demo mode or activate a license, then rerun rea doctor --json.";
|
||||
if (healthy) return undefined;
|
||||
return hopperPath === undefined
|
||||
? "Hopper is optional for non-Hopper providers. Rerun with --yes --install-hopper for deep native analysis."
|
||||
: "Run rea doctor and apply each reported remediation.";
|
||||
};
|
||||
|
||||
const hostRemediation = async (
|
||||
host: SetupHost,
|
||||
): Promise<string | undefined> => {
|
||||
|
||||
@@ -282,9 +282,14 @@ export class HopperRemoteError extends HopperError {
|
||||
/** The owned Hopper bridge stopped before its client was closed. */
|
||||
export class HopperProcessError extends HopperError {
|
||||
readonly _tag = "HopperProcessError";
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -413,6 +418,7 @@ const STATIC_ERROR_CATEGORIES: Readonly<
|
||||
const userMessage = (error: AnalysisError): string => {
|
||||
if (error instanceof AnalysisInputError)
|
||||
return "Analysis input is invalid. Check the arguments and try again.";
|
||||
if (error.userMessage !== undefined) return error.userMessage;
|
||||
if (UNREADABLE_OUTPUT_TAGS.has(error._tag))
|
||||
return "Analysis returned an unreadable result. Retry once; if it continues, run `rea doctor`.";
|
||||
if (UNSUPPORTED_PROVIDER_TAGS.has(error._tag))
|
||||
|
||||
@@ -44,6 +44,7 @@ export interface HopperApplicationLauncherOptions {
|
||||
readonly targetKind: "executable" | "database";
|
||||
readonly loaderArgs: readonly string[];
|
||||
readonly bridgeScriptPath: string;
|
||||
readonly demoHelperPath?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,26 +102,16 @@ export class HopperApplicationLauncher implements BridgeLauncher {
|
||||
options.signal,
|
||||
);
|
||||
if (!prepared) return err(new HopperCancelledError());
|
||||
const child = spawn(this.options.launcherPath, args, {
|
||||
stdio: ["ignore", "ignore", "pipe"],
|
||||
detached: process.platform !== "win32",
|
||||
env: { ...process.env, REA_PROCESS_RUN_ID: session.runId },
|
||||
});
|
||||
const started = await new Promise<Result<undefined, HopperStartError>>(
|
||||
(resolve) => {
|
||||
const onSpawn = (): void => {
|
||||
child.off("error", onError);
|
||||
resolve(ok(undefined));
|
||||
};
|
||||
const onError = (cause: Error): void => {
|
||||
child.off("spawn", onSpawn);
|
||||
resolve(err(new HopperStartError({ cause })));
|
||||
};
|
||||
child.once("spawn", onSpawn);
|
||||
child.once("error", onError);
|
||||
},
|
||||
const linuxDemo = linuxDemoLaunch(this.options, session, args);
|
||||
const ownershipCommand =
|
||||
linuxDemo?.ownershipCommand ?? this.options.launcherPath;
|
||||
const started = await spawnLauncher(
|
||||
linuxDemo?.command ?? this.options.launcherPath,
|
||||
linuxDemo?.args ?? args,
|
||||
session.runId,
|
||||
);
|
||||
if (!started.ok) return started;
|
||||
const child = started.value;
|
||||
const pid = child.pid;
|
||||
if (pid === undefined)
|
||||
return err(
|
||||
@@ -132,7 +123,7 @@ export class HopperApplicationLauncher implements BridgeLauncher {
|
||||
pid,
|
||||
process_group_id: pid,
|
||||
parent_pid: process.pid,
|
||||
launcher: this.options.launcherPath,
|
||||
launcher: linuxDemo?.command ?? this.options.launcherPath,
|
||||
created_at: new Date().toISOString(),
|
||||
};
|
||||
try {
|
||||
@@ -143,7 +134,7 @@ export class HopperApplicationLauncher implements BridgeLauncher {
|
||||
);
|
||||
} catch (cause: unknown) {
|
||||
await cleanupOwnedProcessGroup(
|
||||
ownedProcessGroup(session, pid, this.options.launcherPath),
|
||||
ownedProcessGroup(session, pid, ownershipCommand),
|
||||
);
|
||||
return err(new HopperStartError({ cause }));
|
||||
}
|
||||
@@ -152,7 +143,7 @@ export class HopperApplicationLauncher implements BridgeLauncher {
|
||||
ownsProcessLifetime: true,
|
||||
cleanup: () =>
|
||||
cleanupOwnedProcessGroup(
|
||||
ownedProcessGroup(session, pid, this.options.launcherPath),
|
||||
ownedProcessGroup(session, pid, ownershipCommand),
|
||||
),
|
||||
});
|
||||
} catch (cause: unknown) {
|
||||
@@ -161,6 +152,63 @@ export class HopperApplicationLauncher implements BridgeLauncher {
|
||||
}
|
||||
}
|
||||
|
||||
const linuxDemoLaunch = (
|
||||
options: HopperApplicationLauncherOptions,
|
||||
session: BridgeSession,
|
||||
hopperArgs: readonly string[],
|
||||
):
|
||||
| {
|
||||
readonly command: string;
|
||||
readonly args: readonly string[];
|
||||
readonly ownershipCommand: string;
|
||||
}
|
||||
| undefined => {
|
||||
if (
|
||||
process.platform !== "linux" ||
|
||||
basename(options.launcherPath) !== "Hopper" ||
|
||||
options.demoHelperPath === undefined
|
||||
)
|
||||
return undefined;
|
||||
return {
|
||||
command: "/usr/bin/python3",
|
||||
ownershipCommand: "/usr/bin/python3",
|
||||
args: [
|
||||
options.demoHelperPath,
|
||||
"--hopper",
|
||||
options.launcherPath,
|
||||
"--socket",
|
||||
session.socketPath,
|
||||
"--",
|
||||
options.launcherPath,
|
||||
...hopperArgs,
|
||||
],
|
||||
};
|
||||
};
|
||||
|
||||
const spawnLauncher = async (
|
||||
command: string,
|
||||
args: readonly string[],
|
||||
runId: string,
|
||||
): Promise<Result<ChildProcess, HopperStartError>> => {
|
||||
const child = spawn(command, args, {
|
||||
stdio: ["ignore", "ignore", "pipe"],
|
||||
detached: process.platform !== "win32",
|
||||
env: { ...process.env, REA_PROCESS_RUN_ID: runId },
|
||||
});
|
||||
return new Promise((resolve) => {
|
||||
const onSpawn = (): void => {
|
||||
child.off("error", onError);
|
||||
resolve(ok(child));
|
||||
};
|
||||
const onError = (cause: Error): void => {
|
||||
child.off("spawn", onSpawn);
|
||||
resolve(err(new HopperStartError({ cause })));
|
||||
};
|
||||
child.once("spawn", onSpawn);
|
||||
child.once("error", onError);
|
||||
});
|
||||
};
|
||||
|
||||
const ownedProcessGroup = (
|
||||
session: BridgeSession,
|
||||
pid: number,
|
||||
|
||||
@@ -70,6 +70,7 @@ export class HopperClient {
|
||||
#nextId = 1;
|
||||
#buffer = "";
|
||||
#closing = false;
|
||||
#launcherExitCode: number | null | undefined;
|
||||
#startPromise: Promise<Result<HopperServerInfo, HopperError>> | undefined;
|
||||
#closePromise: Promise<void> | undefined;
|
||||
|
||||
@@ -102,6 +103,7 @@ export class HopperClient {
|
||||
}
|
||||
const socketPath = join(this.#directory, "bridge.sock");
|
||||
this.#token = randomBytes(32).toString("hex");
|
||||
this.#launcherExitCode = undefined;
|
||||
const runId = randomUUID();
|
||||
const launched = await this.#options.launcher.launch(
|
||||
{
|
||||
@@ -210,6 +212,8 @@ 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)
|
||||
return err(new HopperProcessError(this.#launcherExitCode));
|
||||
try {
|
||||
await access(socketPath);
|
||||
} catch {
|
||||
@@ -305,6 +309,7 @@ export class HopperClient {
|
||||
});
|
||||
});
|
||||
launch.process.on("exit", (code) => {
|
||||
this.#launcherExitCode = code;
|
||||
this.#options.onDiagnostic?.({ type: "launcher-exit", code });
|
||||
if (launch.ownsProcessLifetime && !this.#closing) {
|
||||
this.#failAll(new HopperProcessError(code));
|
||||
|
||||
@@ -114,6 +114,9 @@ export class HopperProvider implements AnalysisProvider {
|
||||
bridgeScriptPath: fileURLToPath(
|
||||
new URL("../../bridge/hopper_bridge.py", import.meta.url),
|
||||
),
|
||||
demoHelperPath: fileURLToPath(
|
||||
new URL("../../scripts/hopper-demo-x11.py", import.meta.url),
|
||||
),
|
||||
}),
|
||||
logger: this.logger.child({ layer: "bridge" }),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user