fix(hopper): preserve observed process failures across requests (#1927)
* fix(hopper): preserve observed process failures across requests * test(hopper): consolidate retained cleanup and recover failed helper fixtures * docs(hopper): clarify first-use demo prompt and startup recovery
This commit is contained in:
@@ -245,7 +245,9 @@ Ghidra and IDA use your existing installations. See [provider setup](docs/instal
|
|||||||
<summary><strong>Do I need to start Hopper first?</strong></summary>
|
<summary><strong>Do I need to start Hopper first?</strong></summary>
|
||||||
|
|
||||||
REA starts Hopper when an operation needs it. On macOS, a first-run dialog may
|
REA starts Hopper when an operation needs it. On macOS, a first-run dialog may
|
||||||
ask you to choose demo mode or activate your license. See
|
ask you to choose demo mode or activate your license. Complete that prompt in the
|
||||||
|
same user session before your first CLI/MCP operation or unattended job. Open
|
||||||
|
Hopper manually if needed. See
|
||||||
[Hopper startup and troubleshooting](docs/installation.md#launcher-paths-and-troubleshooting).
|
[Hopper startup and troubleshooting](docs/installation.md#launcher-paths-and-troubleshooting).
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|||||||
+12
-2
@@ -567,8 +567,13 @@ need Xvfb, Python 3, X11 and XTEST; approved setup installs those dependencies
|
|||||||
on supported distributions. Add the curl installer's reported executable
|
on supported distributions. Add the curl installer's reported executable
|
||||||
directory, commonly `~/.local/bin`, to your shell `PATH` if needed.
|
directory, commonly `~/.local/bin`, to your shell `PATH` if needed.
|
||||||
|
|
||||||
REA starts Hopper when needed. On macOS, its launcher can bring a window or
|
REA starts Hopper when needed. On macOS, complete its demo or license prompt in
|
||||||
first-run dialog forward; choose demo mode or activate your existing license.
|
the same user session before the first CLI/MCP operation or unattended job. Open
|
||||||
|
Hopper manually if needed; its launcher can also bring the dialog forward.
|
||||||
|
If startup reports `Cannot launch Hopper! Connection is invalid.` or waits for
|
||||||
|
bridge readiness, check Hopper for a pending demo, license, or loader dialog.
|
||||||
|
Complete the dialog and retry. If REA reports `cleanup_incomplete`, follow the
|
||||||
|
retained-resource guidance below before reopening the target.
|
||||||
Hopper serializes analysis requests. Cancelling a wait can leave provider work
|
Hopper serializes analysis requests. Cancelling a wait can leave provider work
|
||||||
running, which the session reports. Successful decompilation is cached until
|
running, which the session reports. Successful decompilation is cached until
|
||||||
a relevant rename or comment changes it.
|
a relevant rename or comment changes it.
|
||||||
@@ -597,6 +602,11 @@ if document closure is unconfirmed, REA retains the backing image and reports
|
|||||||
MCP-exit behavior.
|
MCP-exit behavior.
|
||||||
Startup deadlines report missing bridge readiness and preserve the launcher
|
Startup deadlines report missing bridge readiness and preserve the launcher
|
||||||
outcome; a successful helper exit does not prove that a loader dialog completed.
|
outcome; a successful helper exit does not prove that a loader dialog completed.
|
||||||
|
If an owned provider process exits, request failures preserve its observed exit
|
||||||
|
code or signal and bounded output in `details.launcher`. An exit can precede
|
||||||
|
output-stream closure; `output_closed: false` keeps that uncertainty explicit.
|
||||||
|
Later requests retain the known exit instead of reducing it to socket loss.
|
||||||
|
An external GUI's helper exit does not establish that the GUI itself exited.
|
||||||
Cursor navigation returns the observed object start when Hopper snaps an interior
|
Cursor navigation returns the observed object start when Hopper snaps an interior
|
||||||
address; adjacent-object navigation rejects unmapped inputs and document ends.
|
address; adjacent-object navigation rejects unmapped inputs and document ends.
|
||||||
Native API text rejects NUL characters and unpaired Unicode surrogates before
|
Native API text rejects NUL characters and unpaired Unicode surrogates before
|
||||||
|
|||||||
@@ -51,9 +51,9 @@ export interface AnalysisCleanupObservation {
|
|||||||
|
|
||||||
/** Optional provider-neutral context that must survive typed error projection. */
|
/** Optional provider-neutral context that must survive typed error projection. */
|
||||||
export interface AnalysisErrorOptions extends ErrorOptions {
|
export interface AnalysisErrorOptions extends ErrorOptions {
|
||||||
readonly capturedOutput?: AnalysisCapturedOutput;
|
readonly capturedOutput?: AnalysisCapturedOutput | undefined;
|
||||||
readonly cleanup?: AnalysisCleanupObservation;
|
readonly cleanup?: AnalysisCleanupObservation | undefined;
|
||||||
readonly partialObservation?: AnalysisPartialObservation;
|
readonly partialObservation?: AnalysisPartialObservation | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Base class for expected analysis, provider, and session failures. */
|
/** Base class for expected analysis, provider, and session failures. */
|
||||||
|
|||||||
@@ -265,9 +265,12 @@ const hopperProcessMessage = (error: HopperProcessError): string => {
|
|||||||
const startup =
|
const startup =
|
||||||
error.userMessage === undefined ? "" : ` ${error.userMessage}`;
|
error.userMessage === undefined ? "" : ` ${error.userMessage}`;
|
||||||
if (error.providerState === "exited") {
|
if (error.providerState === "exited") {
|
||||||
|
const signal = error.launcherFailure?.signal;
|
||||||
const exit =
|
const exit =
|
||||||
error.exitCode === null
|
error.exitCode === null
|
||||||
? "no exit code was observed"
|
? signal === undefined || signal === null
|
||||||
|
? "no exit code was observed"
|
||||||
|
: `signal ${signal}`
|
||||||
: `exit code ${String(error.exitCode)}`;
|
: `exit code ${String(error.exitCode)}`;
|
||||||
const recovery =
|
const recovery =
|
||||||
error.failureCode === undefined && stage !== "launch"
|
error.failureCode === undefined && stage !== "launch"
|
||||||
|
|||||||
@@ -572,7 +572,7 @@ describe("analysis error projection: caller contract", () => {
|
|||||||
describe("analysis error projection: operational diagnostics", () => {
|
describe("analysis error projection: operational diagnostics", () => {
|
||||||
it("distinguishes an observed Hopper exit from an undetermined provider failure", () => {
|
it("distinguishes an observed Hopper exit from an undetermined provider failure", () => {
|
||||||
const exited = projectAnalysisError(
|
const exited = projectAnalysisError(
|
||||||
new HopperProcessError(7, undefined, "search_strings", 4),
|
new HopperProcessError(7, { operation: "search_strings", requestId: 4 }),
|
||||||
);
|
);
|
||||||
expect(exited).toMatchObject({
|
expect(exited).toMatchObject({
|
||||||
code: "provider_unavailable",
|
code: "provider_unavailable",
|
||||||
@@ -590,7 +590,10 @@ describe("analysis error projection: operational diagnostics", () => {
|
|||||||
expect(exited.remediation.action).toContain("Restart the owned provider");
|
expect(exited.remediation.action).toContain("Restart the owned provider");
|
||||||
|
|
||||||
const unknown = projectAnalysisError(
|
const unknown = projectAnalysisError(
|
||||||
new HopperProcessError(null, undefined, "search_strings", 5),
|
new HopperProcessError(null, {
|
||||||
|
operation: "search_strings",
|
||||||
|
requestId: 5,
|
||||||
|
}),
|
||||||
);
|
);
|
||||||
expect(unknown.details).toMatchObject({
|
expect(unknown.details).toMatchObject({
|
||||||
stage: "analysis",
|
stage: "analysis",
|
||||||
|
|||||||
+34
-16
@@ -1,4 +1,7 @@
|
|||||||
import { AnalysisError } from "./analysisErrorBase.js";
|
import {
|
||||||
|
AnalysisError,
|
||||||
|
type AnalysisErrorOptions,
|
||||||
|
} from "./analysisErrorBase.js";
|
||||||
import type {
|
import type {
|
||||||
HopperProcessProviderState,
|
HopperProcessProviderState,
|
||||||
ProviderFailureStage,
|
ProviderFailureStage,
|
||||||
@@ -73,10 +76,10 @@ export type HopperDiagnosticType =
|
|||||||
| "bridge_exception";
|
| "bridge_exception";
|
||||||
|
|
||||||
/** Hopper's JSON-RPC endpoint returned an expected remote error response. */
|
/** Hopper's JSON-RPC endpoint returned an expected remote error response. */
|
||||||
export interface HopperRemoteErrorContext {
|
export interface HopperRemoteErrorContext extends AnalysisErrorOptions {
|
||||||
readonly diagnosticType?: HopperDiagnosticType;
|
readonly diagnosticType?: HopperDiagnosticType | undefined;
|
||||||
readonly operation?: string;
|
readonly operation?: string | undefined;
|
||||||
readonly requestId?: number;
|
readonly requestId?: number | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class HopperRemoteError extends HopperError {
|
export class HopperRemoteError extends HopperError {
|
||||||
@@ -90,7 +93,7 @@ export class HopperRemoteError extends HopperError {
|
|||||||
readonly safeMessage: string,
|
readonly safeMessage: string,
|
||||||
context: HopperRemoteErrorContext = {},
|
context: HopperRemoteErrorContext = {},
|
||||||
) {
|
) {
|
||||||
super(`Hopper request failed (${String(code)}): ${safeMessage}`);
|
super(`Hopper request failed (${String(code)}): ${safeMessage}`, context);
|
||||||
this.diagnosticType = context.diagnosticType ?? "remote";
|
this.diagnosticType = context.diagnosticType ?? "remote";
|
||||||
this.operation = context.operation;
|
this.operation = context.operation;
|
||||||
this.requestId = context.requestId;
|
this.requestId = context.requestId;
|
||||||
@@ -98,35 +101,50 @@ export class HopperRemoteError extends HopperError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** The owned Hopper bridge stopped before its client was closed. */
|
/** The owned Hopper bridge stopped before its client was closed. */
|
||||||
|
export interface HopperProcessErrorContext extends AnalysisErrorOptions {
|
||||||
|
readonly diagnostic?: HopperStartupFailureDiagnostic | undefined;
|
||||||
|
readonly operation?: string | undefined;
|
||||||
|
readonly requestId?: number | undefined;
|
||||||
|
readonly providerState?: HopperProcessProviderState | undefined;
|
||||||
|
readonly stage?: ProviderFailureStage | undefined;
|
||||||
|
readonly launcherFailure?: HopperLauncherOutcome | undefined;
|
||||||
|
}
|
||||||
|
|
||||||
export class HopperProcessError extends HopperError {
|
export class HopperProcessError extends HopperError {
|
||||||
readonly _tag = "HopperProcessError";
|
readonly _tag = "HopperProcessError";
|
||||||
readonly failureCode: HopperStartupFailureCode | undefined;
|
readonly failureCode: HopperStartupFailureCode | undefined;
|
||||||
override readonly userMessage: string | undefined;
|
override readonly userMessage: string | undefined;
|
||||||
readonly providerState: HopperProcessProviderState;
|
readonly providerState: HopperProcessProviderState;
|
||||||
readonly stage: ProviderFailureStage;
|
readonly stage: ProviderFailureStage;
|
||||||
|
readonly diagnostic: HopperStartupFailureDiagnostic | undefined;
|
||||||
|
readonly operation: string | undefined;
|
||||||
|
readonly requestId: number | undefined;
|
||||||
|
readonly launcherFailure: HopperLauncherOutcome | undefined;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
readonly exitCode: number | null,
|
readonly exitCode: number | null,
|
||||||
readonly diagnostic?: HopperStartupFailureDiagnostic,
|
context: HopperProcessErrorContext = {},
|
||||||
readonly operation?: string,
|
|
||||||
readonly requestId?: number,
|
|
||||||
providerState?: HopperProcessProviderState,
|
|
||||||
stage?: ProviderFailureStage,
|
|
||||||
readonly launcherFailure?: HopperLauncherOutcome,
|
|
||||||
) {
|
) {
|
||||||
super(`Hopper bridge stopped unexpectedly with code ${String(exitCode)}`);
|
super(
|
||||||
|
`Hopper bridge stopped unexpectedly with code ${String(exitCode)}`,
|
||||||
|
context,
|
||||||
|
);
|
||||||
|
this.diagnostic = context.diagnostic;
|
||||||
|
this.operation = context.operation;
|
||||||
|
this.requestId = context.requestId;
|
||||||
|
this.launcherFailure = context.launcherFailure;
|
||||||
const failure = hopperStartupFailure(exitCode);
|
const failure = hopperStartupFailure(exitCode);
|
||||||
this.stage =
|
this.stage =
|
||||||
stage ??
|
context.stage ??
|
||||||
(failure === undefined
|
(failure === undefined
|
||||||
? operation === undefined
|
? context.operation === undefined
|
||||||
? "connection"
|
? "connection"
|
||||||
: "analysis"
|
: "analysis"
|
||||||
: "launch");
|
: "launch");
|
||||||
this.failureCode = failure?.code;
|
this.failureCode = failure?.code;
|
||||||
this.userMessage = failure?.message;
|
this.userMessage = failure?.message;
|
||||||
this.providerState =
|
this.providerState =
|
||||||
providerState ?? (exitCode === null ? "unknown" : "exited");
|
context.providerState ?? (exitCode === null ? "unknown" : "exited");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -362,10 +362,9 @@ export class HopperApplicationLauncher implements BridgeLauncher {
|
|||||||
? { ok: true, strategy: selection.strategy }
|
? { ok: true, strategy: selection.strategy }
|
||||||
: {
|
: {
|
||||||
ok: false,
|
ok: false,
|
||||||
error: new HopperProcessError(
|
error: new HopperProcessError(selection.exitCode, {
|
||||||
selection.exitCode,
|
diagnostic: selection.diagnostic,
|
||||||
selection.diagnostic,
|
}),
|
||||||
),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -202,9 +202,7 @@ const shutdownRequestFailure = (
|
|||||||
operation: "shutdown" | "shutdown_document",
|
operation: "shutdown" | "shutdown_document",
|
||||||
cause: unknown,
|
cause: unknown,
|
||||||
): HopperProcessError => {
|
): HopperProcessError => {
|
||||||
const failure = new HopperProcessError(null, undefined, operation);
|
return new HopperProcessError(null, { operation, cause });
|
||||||
failure.cause = cause;
|
|
||||||
return failure;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const shutdownFailureDetails = (
|
const shutdownFailureDetails = (
|
||||||
|
|||||||
+44
-44
@@ -129,13 +129,9 @@ export class HopperClient {
|
|||||||
this.#responses.push(chunk);
|
this.#responses.push(chunk);
|
||||||
};
|
};
|
||||||
readonly #onSocketError = (): void => {
|
readonly #onSocketError = (): void => {
|
||||||
const error = new HopperProcessError(
|
const error = new HopperProcessError(null, {
|
||||||
null,
|
providerState: "unreachable",
|
||||||
undefined,
|
});
|
||||||
undefined,
|
|
||||||
undefined,
|
|
||||||
"unreachable",
|
|
||||||
);
|
|
||||||
this.#failAll(error);
|
this.#failAll(error);
|
||||||
this.#rememberProcessFailure(error, []);
|
this.#rememberProcessFailure(error, []);
|
||||||
};
|
};
|
||||||
@@ -151,25 +147,18 @@ export class HopperClient {
|
|||||||
setImmediate(() => {
|
setImmediate(() => {
|
||||||
if (this.#closing || this.#launcherExitCode !== undefined) return;
|
if (this.#closing || this.#launcherExitCode !== undefined) return;
|
||||||
const exitCode = launch.process.exitCode ?? null;
|
const exitCode = launch.process.exitCode ?? null;
|
||||||
const error = new HopperProcessError(
|
const error = new HopperProcessError(exitCode, {
|
||||||
exitCode,
|
diagnostic: this.#launcherFailureDiagnostic,
|
||||||
this.#launcherFailureDiagnostic,
|
providerState: exitCode !== null ? "exited" : "unreachable",
|
||||||
undefined,
|
});
|
||||||
undefined,
|
|
||||||
exitCode !== null ? "exited" : "unreachable",
|
|
||||||
);
|
|
||||||
this.#failAll(error);
|
this.#failAll(error);
|
||||||
this.#rememberProcessFailure(error, []);
|
this.#rememberProcessFailure(error, []);
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const error = new HopperProcessError(
|
const error = new HopperProcessError(null, {
|
||||||
null,
|
providerState: "unreachable",
|
||||||
undefined,
|
});
|
||||||
undefined,
|
|
||||||
undefined,
|
|
||||||
"unreachable",
|
|
||||||
);
|
|
||||||
this.#failAll(error);
|
this.#failAll(error);
|
||||||
this.#rememberProcessFailure(error, []);
|
this.#rememberProcessFailure(error, []);
|
||||||
};
|
};
|
||||||
@@ -729,15 +718,12 @@ export class HopperClient {
|
|||||||
)) ?? false;
|
)) ?? false;
|
||||||
const launcherFailure = this.#launcherOutcome(outputClosed);
|
const launcherFailure = this.#launcherOutcome(outputClosed);
|
||||||
if (ownsProviderLifetime)
|
if (ownsProviderLifetime)
|
||||||
return new HopperProcessError(
|
return new HopperProcessError(exitCode, {
|
||||||
exitCode,
|
diagnostic: this.#launcherFailureDiagnostic,
|
||||||
this.#launcherFailureDiagnostic,
|
providerState: "exited",
|
||||||
undefined,
|
stage: "launch",
|
||||||
undefined,
|
|
||||||
"exited",
|
|
||||||
"launch",
|
|
||||||
launcherFailure,
|
launcherFailure,
|
||||||
);
|
});
|
||||||
if (
|
if (
|
||||||
this.#resources.launch?.authorizationDenialBeforeHandoff === true &&
|
this.#resources.launch?.authorizationDenialBeforeHandoff === true &&
|
||||||
nativeHopperLaunchWasDenied(launcherFailure)
|
nativeHopperLaunchWasDenied(launcherFailure)
|
||||||
@@ -766,18 +752,34 @@ export class HopperClient {
|
|||||||
},
|
},
|
||||||
): Promise<Result<JsonValue, HopperError>> {
|
): Promise<Result<JsonValue, HopperError>> {
|
||||||
const id = this.#nextId++;
|
const id = this.#nextId++;
|
||||||
|
if (
|
||||||
|
this.#resources.launch?.providerLifetime === "launcher-process" &&
|
||||||
|
this.#launcherExitCode !== undefined
|
||||||
|
) {
|
||||||
|
return this.#unavailableRequest(
|
||||||
|
new HopperProcessError(this.#launcherExitCode, {
|
||||||
|
diagnostic: this.#launcherFailureDiagnostic,
|
||||||
|
operation: method,
|
||||||
|
requestId: id,
|
||||||
|
providerState: "exited",
|
||||||
|
stage: hopperOperationStage(method),
|
||||||
|
launcherFailure: this.#launcherOutcome(
|
||||||
|
(await this.#resources.processSupervisor?.waitForOutputClose(0)) ??
|
||||||
|
false,
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
const socket = this.#socket;
|
const socket = this.#socket;
|
||||||
const token = this.#token;
|
const token = this.#token;
|
||||||
if (socket === undefined || socket.destroyed || token === undefined) {
|
if (socket === undefined || socket.destroyed || token === undefined) {
|
||||||
return this.#unavailableRequest(
|
return this.#unavailableRequest(
|
||||||
new HopperProcessError(
|
new HopperProcessError(null, {
|
||||||
null,
|
operation: method,
|
||||||
undefined,
|
requestId: id,
|
||||||
method,
|
providerState: "unreachable",
|
||||||
id,
|
stage: hopperOperationStage(method),
|
||||||
"unreachable",
|
}),
|
||||||
hopperOperationStage(method),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (options.signal?.aborted === true)
|
if (options.signal?.aborted === true)
|
||||||
@@ -888,13 +890,11 @@ export class HopperClient {
|
|||||||
if (launch.providerLifetime === "launcher-process" && !this.#closing) {
|
if (launch.providerLifetime === "launcher-process" && !this.#closing) {
|
||||||
this.#rememberExit(event.code);
|
this.#rememberExit(event.code);
|
||||||
this.#failAll(
|
this.#failAll(
|
||||||
new HopperProcessError(
|
new HopperProcessError(event.code, {
|
||||||
event.code,
|
diagnostic: this.#launcherFailureDiagnostic,
|
||||||
this.#launcherFailureDiagnostic,
|
providerState: "exited",
|
||||||
undefined,
|
launcherFailure: this.#launcherOutcome(false),
|
||||||
undefined,
|
}),
|
||||||
"exited",
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -273,14 +273,12 @@ export class HopperRequestQueue {
|
|||||||
this.accept(
|
this.accept(
|
||||||
entry.id,
|
entry.id,
|
||||||
err(
|
err(
|
||||||
new HopperProcessError(
|
new HopperProcessError(null, {
|
||||||
null,
|
operation: entry.method,
|
||||||
undefined,
|
requestId: entry.id,
|
||||||
entry.method,
|
providerState: "unreachable",
|
||||||
entry.id,
|
stage: hopperOperationStage(entry.method),
|
||||||
"unreachable",
|
}),
|
||||||
hopperOperationStage(entry.method),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -386,19 +384,20 @@ const withRequestContext = (
|
|||||||
entry: QueuedRequest,
|
entry: QueuedRequest,
|
||||||
): HopperError => {
|
): HopperError => {
|
||||||
if (error instanceof HopperProcessError)
|
if (error instanceof HopperProcessError)
|
||||||
return new HopperProcessError(
|
return new HopperProcessError(error.exitCode, {
|
||||||
error.exitCode,
|
...error,
|
||||||
error.diagnostic,
|
cause: error.cause,
|
||||||
error.operation ?? entry.method,
|
operation: error.operation ?? entry.method,
|
||||||
error.requestId ?? entry.id,
|
requestId: error.requestId ?? entry.id,
|
||||||
error.providerState,
|
stage:
|
||||||
error.operation === undefined && error.stage === "connection"
|
error.operation === undefined && error.stage === "connection"
|
||||||
? hopperOperationStage(entry.method)
|
? hopperOperationStage(entry.method)
|
||||||
: error.stage,
|
: error.stage,
|
||||||
);
|
});
|
||||||
if (error instanceof HopperRemoteError)
|
if (error instanceof HopperRemoteError)
|
||||||
return new HopperRemoteError(error.code, error.safeMessage, {
|
return new HopperRemoteError(error.code, error.safeMessage, {
|
||||||
diagnosticType: error.diagnosticType,
|
...error,
|
||||||
|
cause: error.cause,
|
||||||
operation: error.operation ?? entry.method,
|
operation: error.operation ?? entry.method,
|
||||||
requestId: error.requestId ?? entry.id,
|
requestId: error.requestId ?? entry.id,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -338,20 +338,22 @@ describe("tool result projection", () => {
|
|||||||
const result = delivery.toCallToolResult(
|
const result = delivery.toCallToolResult(
|
||||||
err(
|
err(
|
||||||
new HopperProcessError(80, {
|
new HopperProcessError(80, {
|
||||||
component: "hopper_private_display",
|
diagnostic: {
|
||||||
operation: "launch",
|
component: "hopper_private_display",
|
||||||
status: "error",
|
operation: "launch",
|
||||||
failure_code: "x11_socket_directory_unusable",
|
status: "error",
|
||||||
reason: "socket_directory_read_only",
|
failure_code: "x11_socket_directory_unusable",
|
||||||
socket_directory: "/tmp/.X11-unix",
|
reason: "socket_directory_read_only",
|
||||||
socket_directory_mode: "0777",
|
socket_directory: "/tmp/.X11-unix",
|
||||||
mount_read_only: true,
|
socket_directory_mode: "0777",
|
||||||
effective_socket_directory_mode: "1777",
|
mount_read_only: true,
|
||||||
effective_mount_read_only: false,
|
effective_socket_directory_mode: "1777",
|
||||||
wsl: true,
|
effective_mount_read_only: false,
|
||||||
strategy: "user-mount-namespace",
|
wsl: true,
|
||||||
fallback_reason: null,
|
strategy: "user-mount-namespace",
|
||||||
xvfb_stderr_bytes: 512,
|
fallback_reason: null,
|
||||||
|
xvfb_stderr_bytes: 512,
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
contract,
|
contract,
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import { access } from "node:fs/promises";
|
|||||||
|
|
||||||
import { afterEach, describe, expect, it } from "vitest";
|
import { afterEach, describe, expect, it } from "vitest";
|
||||||
|
|
||||||
import { projectAnalysisError } from "../../../../src/domain/analysisErrorProjection.js";
|
|
||||||
import { ok } from "../../../../src/domain/result.js";
|
import { ok } from "../../../../src/domain/result.js";
|
||||||
import type {
|
import type {
|
||||||
BridgeLauncher,
|
BridgeLauncher,
|
||||||
@@ -53,31 +52,6 @@ class OwnedFixtureLauncher implements BridgeLauncher {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class UnconfirmedFixtureLauncher implements BridgeLauncher {
|
|
||||||
constructor(readonly ownsProcessLifetime = false) {}
|
|
||||||
|
|
||||||
launch(session: BridgeSession) {
|
|
||||||
return Promise.resolve(
|
|
||||||
ok({
|
|
||||||
process: spawn(
|
|
||||||
process.execPath,
|
|
||||||
[
|
|
||||||
fixturePath,
|
|
||||||
session.socketPath,
|
|
||||||
session.token,
|
|
||||||
session.runId,
|
|
||||||
"unconfirmed",
|
|
||||||
],
|
|
||||||
{ stdio: ["ignore", "ignore", "pipe"] },
|
|
||||||
),
|
|
||||||
ownsProcessLifetime: this.ownsProcessLifetime,
|
|
||||||
providerLifetime: "external-application" as const,
|
|
||||||
shutdownMode: "bridge-request" as const,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const clients: HopperClient[] = [];
|
const clients: HopperClient[] = [];
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
@@ -137,42 +111,6 @@ describe("HopperClient cleanup", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it.each([
|
|
||||||
["unowned", false],
|
|
||||||
["owned helper", true],
|
|
||||||
] as const)(
|
|
||||||
"reports unconfirmed external document cleanup for an %s process",
|
|
||||||
async (_description, ownsProcessLifetime) => {
|
|
||||||
const client = new HopperClient({
|
|
||||||
launcher: new UnconfirmedFixtureLauncher(ownsProcessLifetime),
|
|
||||||
startupTimeoutMs: 1_000,
|
|
||||||
});
|
|
||||||
clients.push(client);
|
|
||||||
expect((await client.start()).ok).toBe(true);
|
|
||||||
|
|
||||||
const closed = await client.close();
|
|
||||||
|
|
||||||
expect(closed).toMatchObject({
|
|
||||||
ok: false,
|
|
||||||
error: {
|
|
||||||
_tag: "ProviderAdapterError",
|
|
||||||
cleanupIncomplete: true,
|
|
||||||
cleanupResources: expect.arrayContaining(["hopper-document"]),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
if (!closed.ok)
|
|
||||||
expect(projectAnalysisError(closed.error)).toMatchObject({
|
|
||||||
code: "cleanup_incomplete",
|
|
||||||
details: {
|
|
||||||
provider_id: "hopper",
|
|
||||||
operation: "close_binary",
|
|
||||||
cleanup: "incomplete",
|
|
||||||
resources: expect.arrayContaining(["hopper-document"]),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
it("kills only its owned Hopper group and emits sanitized shutdown coordinates", async () => {
|
it("kills only its owned Hopper group and emits sanitized shutdown coordinates", async () => {
|
||||||
const unrelated = spawn(
|
const unrelated = spawn(
|
||||||
process.execPath,
|
process.execPath,
|
||||||
|
|||||||
@@ -160,50 +160,71 @@ it("retains failed startup cleanup until an owned process and its backing image
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("keeps an unconfirmed external document visible across sequential closes", async () => {
|
it.each([false, true])(
|
||||||
const launcher = new RetryCleanupLauncher(true);
|
"keeps an unconfirmed external document across closes when helper ownership is %s",
|
||||||
const runtimeRoot = await PrivateRuntimeRoot.create();
|
async (ownsHelper) => {
|
||||||
onTestFinished(() => runtimeRoot.close());
|
const launcher = new RetryCleanupLauncher(true);
|
||||||
const launched = await launcher.launch({
|
const runtimeRoot = await PrivateRuntimeRoot.create();
|
||||||
directory: runtimeRoot.path,
|
onTestFinished(() => runtimeRoot.close());
|
||||||
socketPath: join(runtimeRoot.path, "bridge.sock"),
|
const launched = await launcher.launch({
|
||||||
token: "fixture-token",
|
directory: runtimeRoot.path,
|
||||||
runId: "fixture-run",
|
socketPath: join(runtimeRoot.path, "bridge.sock"),
|
||||||
});
|
token: "fixture-token",
|
||||||
if (!launched.ok) throw launched.error;
|
runId: "fixture-run",
|
||||||
const child = launched.value.process;
|
|
||||||
const supervisor = new ProviderProcessSupervisor(launched.value);
|
|
||||||
onTestFinished(() => supervisor.dispose());
|
|
||||||
const resources: HopperOwnedResources = {
|
|
||||||
launch: launched.value,
|
|
||||||
processSupervisor: supervisor,
|
|
||||||
runtimeRoot,
|
|
||||||
shutdownConfirmed: false,
|
|
||||||
};
|
|
||||||
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
||||||
await expect(
|
|
||||||
cleanupHopperSession({
|
|
||||||
socket: undefined,
|
|
||||||
resources,
|
|
||||||
activeRequest: null,
|
|
||||||
retainDocument: false,
|
|
||||||
progress: undefined,
|
|
||||||
logger: silentLogger,
|
|
||||||
onDiagnostic: undefined,
|
|
||||||
request: () => Promise.resolve(ok(null)),
|
|
||||||
releaseTransport: (socket) => socket?.destroy(),
|
|
||||||
}),
|
|
||||||
).resolves.toMatchObject({
|
|
||||||
ok: false,
|
|
||||||
error: { cleanupResources: ["hopper-document", runtimeRoot.path] },
|
|
||||||
});
|
});
|
||||||
}
|
if (!launched.ok) throw launched.error;
|
||||||
expect(child.exitCode).toBeNull();
|
const child = launched.value.process;
|
||||||
expect(child.signalCode).toBeNull();
|
const launch: BridgeLaunch = ownsHelper
|
||||||
await expect(
|
? { ...launched.value, ownsProcessLifetime: true }
|
||||||
access(join(runtimeRoot.path, "image.macho")),
|
: launched.value;
|
||||||
).resolves.toBeUndefined();
|
const supervisor = new ProviderProcessSupervisor(launch);
|
||||||
});
|
onTestFinished(() => supervisor.dispose());
|
||||||
|
const resources: HopperOwnedResources = {
|
||||||
|
launch,
|
||||||
|
processSupervisor: supervisor,
|
||||||
|
runtimeRoot,
|
||||||
|
shutdownConfirmed: false,
|
||||||
|
};
|
||||||
|
const socket = new Socket();
|
||||||
|
onTestFinished(() => {
|
||||||
|
socket.destroy();
|
||||||
|
});
|
||||||
|
for (let attempt = 0; attempt < 2; attempt += 1) {
|
||||||
|
await expect(
|
||||||
|
cleanupHopperSession({
|
||||||
|
socket: attempt === 0 ? socket : undefined,
|
||||||
|
resources,
|
||||||
|
activeRequest: null,
|
||||||
|
retainDocument: false,
|
||||||
|
progress: undefined,
|
||||||
|
logger: silentLogger,
|
||||||
|
onDiagnostic: undefined,
|
||||||
|
request: () =>
|
||||||
|
Promise.resolve(
|
||||||
|
ok({
|
||||||
|
shutdown: true,
|
||||||
|
analysis_stopped: true,
|
||||||
|
document_closed: false,
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
releaseTransport: (socket) => socket?.destroy(),
|
||||||
|
}),
|
||||||
|
).resolves.toMatchObject({
|
||||||
|
ok: false,
|
||||||
|
error: { cleanupResources: ["hopper-document", runtimeRoot.path] },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (ownsHelper)
|
||||||
|
expect(child.exitCode !== null || child.signalCode !== null).toBe(true);
|
||||||
|
else {
|
||||||
|
expect(child.exitCode).toBeNull();
|
||||||
|
expect(child.signalCode).toBeNull();
|
||||||
|
}
|
||||||
|
await expect(
|
||||||
|
access(join(runtimeRoot.path, "image.macho")),
|
||||||
|
).resolves.toBeUndefined();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
it("blocks a fresh launch while cleanup remains unverified", async () => {
|
it("blocks a fresh launch while cleanup remains unverified", async () => {
|
||||||
const launcher = new RetryCleanupLauncher();
|
const launcher = new RetryCleanupLauncher();
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { EventEmitter } from "node:events";
|
import { EventEmitter } from "node:events";
|
||||||
|
import { PassThrough } from "node:stream";
|
||||||
|
|
||||||
import { describe, expect, it, onTestFinished, vi } from "vitest";
|
import { describe, expect, it, onTestFinished, vi } from "vitest";
|
||||||
|
|
||||||
@@ -12,15 +13,18 @@ import { HopperClient } from "../../../../src/hopper/HopperClient.js";
|
|||||||
import { HopperFixtureLauncher } from "./hopperClient.fixture.js";
|
import { HopperFixtureLauncher } from "./hopperClient.fixture.js";
|
||||||
|
|
||||||
class ObservedProcess extends EventEmitter {
|
class ObservedProcess extends EventEmitter {
|
||||||
readonly stdout = null;
|
readonly stdout = new PassThrough();
|
||||||
readonly stderr = null;
|
readonly stderr = new PassThrough();
|
||||||
exitCode: number | null = null;
|
exitCode: number | null = null;
|
||||||
readonly signalCode = null;
|
signalCode: NodeJS.Signals | null = null;
|
||||||
|
|
||||||
exit(code: number): void {
|
exit(code: number | null, signal: NodeJS.Signals | null = null): void {
|
||||||
this.exitCode = code;
|
this.exitCode = code;
|
||||||
this.emit("exit", code, null);
|
this.signalCode = signal;
|
||||||
this.emit("close", code, null);
|
this.emit("exit", code, signal);
|
||||||
|
this.stdout.end();
|
||||||
|
this.stderr.end();
|
||||||
|
this.emit("close", code, signal);
|
||||||
}
|
}
|
||||||
|
|
||||||
kill(): boolean {
|
kill(): boolean {
|
||||||
@@ -66,7 +70,7 @@ describe("Hopper provider lifecycle health", () => {
|
|||||||
launcher.observed.exit(0);
|
launcher.observed.exit(0);
|
||||||
const pending = client.callTool("hang");
|
const pending = client.callTool("hang");
|
||||||
await launcher.fixture.waitForRequest("hang");
|
await launcher.fixture.waitForRequest("hang");
|
||||||
launcher.fixture.processes.at(-1)?.kill("SIGKILL");
|
launcher.fixture.processes.at(-1)?.send({ disconnect: true });
|
||||||
await vi.waitFor(() =>
|
await vi.waitFor(() =>
|
||||||
expect(client.operationHealth().state).toBe("unreachable"),
|
expect(client.operationHealth().state).toBe("unreachable"),
|
||||||
);
|
);
|
||||||
@@ -92,6 +96,7 @@ describe("Hopper provider lifecycle health", () => {
|
|||||||
operation: "procedure_pseudo_code",
|
operation: "procedure_pseudo_code",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
expect((await client.close()).ok).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("projects the exit code when the owned process exit is observed before disconnection", async () => {
|
it("projects the exit code when the owned process exit is observed before disconnection", async () => {
|
||||||
@@ -120,6 +125,7 @@ describe("Hopper provider lifecycle health", () => {
|
|||||||
stage: "analysis",
|
stage: "analysis",
|
||||||
operation: "hang",
|
operation: "hang",
|
||||||
request_id: request.id,
|
request_id: request.id,
|
||||||
|
launcher: { exit_code: 7, signal: null, output_closed: false },
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -166,3 +172,52 @@ describe("Hopper provider lifecycle health", () => {
|
|||||||
expect(client.operationHealth().state).toBe("idle");
|
expect(client.operationHealth().state).toBe("idle");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("preserves an owned signal exit and diagnostics for active, queued and later callers", async () => {
|
||||||
|
const { client, launcher } = await start(true);
|
||||||
|
const active = client.callTool("hang");
|
||||||
|
const request = await launcher.fixture.waitForRequest("hang");
|
||||||
|
const queued = client.callTool("echo");
|
||||||
|
await vi.waitFor(() =>
|
||||||
|
expect(client.requestActivity()?.queuedRequests).toBe(1),
|
||||||
|
);
|
||||||
|
const token = launcher.fixture.tokens[0];
|
||||||
|
launcher.observed.stderr.write(`API_KEY=local-evidence-kept ${token}\n`);
|
||||||
|
launcher.observed.exit(null, "SIGTERM");
|
||||||
|
const results = await Promise.all([active, queued]);
|
||||||
|
for (const [index, result] of results.entries()) {
|
||||||
|
if (result.ok) throw new Error("Expected an observed provider exit");
|
||||||
|
const projected = projectAnalysisError(result.error);
|
||||||
|
expect(projected).toMatchObject({
|
||||||
|
code: "provider_unavailable",
|
||||||
|
message: expect.stringContaining("signal SIGTERM"),
|
||||||
|
details: {
|
||||||
|
provider_state: "exited",
|
||||||
|
operation: index === 0 ? "hang" : "echo",
|
||||||
|
request_id: request.id + index,
|
||||||
|
launcher: {
|
||||||
|
exit_code: null,
|
||||||
|
signal: "SIGTERM",
|
||||||
|
output_closed: false,
|
||||||
|
stderr: {
|
||||||
|
text: "API_KEY=local-evidence-kept [redacted transport credential]\n",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
expect(JSON.stringify(projected)).not.toContain(token);
|
||||||
|
}
|
||||||
|
const later = await client.callTool("procedure_pseudo_code", {
|
||||||
|
procedure: "main",
|
||||||
|
});
|
||||||
|
if (later.ok) throw new Error("An exited provider must reject later queries");
|
||||||
|
expect(projectAnalysisError(later.error)).toMatchObject({
|
||||||
|
code: "provider_unavailable",
|
||||||
|
details: {
|
||||||
|
provider_state: "exited",
|
||||||
|
stage: "decompilation",
|
||||||
|
operation: "procedure_pseudo_code",
|
||||||
|
launcher: { signal: "SIGTERM", output_closed: true },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -1,13 +1,68 @@
|
|||||||
import { spawn } from "node:child_process";
|
import { spawn } from "node:child_process";
|
||||||
|
import { access } from "node:fs/promises";
|
||||||
|
|
||||||
import { expect, it, onTestFinished } from "vitest";
|
import { expect, it, onTestFinished } from "vitest";
|
||||||
|
|
||||||
import { AnalysisError } from "../../../../src/domain/analysisErrorBase.js";
|
import { AnalysisError } from "../../../../src/domain/analysisErrorBase.js";
|
||||||
import { projectAnalysisError } from "../../../../src/domain/analysisErrorProjection.js";
|
import { projectAnalysisError } from "../../../../src/domain/analysisErrorProjection.js";
|
||||||
import { ok } from "../../../../src/domain/result.js";
|
import { ok } from "../../../../src/domain/result.js";
|
||||||
import type { BridgeLauncher } from "../../../../src/hopper/BridgeLauncher.js";
|
import type {
|
||||||
|
BridgeLauncher,
|
||||||
|
BridgeSession,
|
||||||
|
} from "../../../../src/hopper/BridgeLauncher.js";
|
||||||
import { HopperApplicationLauncher } from "../../../../src/hopper/BridgeLauncher.js";
|
import { HopperApplicationLauncher } from "../../../../src/hopper/BridgeLauncher.js";
|
||||||
import { HopperClient } from "../../../../src/hopper/HopperClient.js";
|
import { HopperClient } from "../../../../src/hopper/HopperClient.js";
|
||||||
|
import { HopperFixtureLauncher } from "./hopperClient.fixture.js";
|
||||||
|
|
||||||
|
// Failure assertions keep the external document unknown. Teardown then publishes
|
||||||
|
// this run's authenticated bridge so normal cleanup can release its runtime/lease.
|
||||||
|
const trackFailedHelperClient = (
|
||||||
|
launcher: BridgeLauncher,
|
||||||
|
startupTimeoutMs = 10_000,
|
||||||
|
): HopperClient => {
|
||||||
|
let session: BridgeSession | undefined;
|
||||||
|
let external = false;
|
||||||
|
const client = new HopperClient({
|
||||||
|
launcher: {
|
||||||
|
async launch(input, options) {
|
||||||
|
session = input;
|
||||||
|
const launched = await launcher.launch(input, options);
|
||||||
|
external =
|
||||||
|
launched.ok &&
|
||||||
|
launched.value.providerLifetime === "external-application";
|
||||||
|
return launched;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
startupTimeoutMs,
|
||||||
|
});
|
||||||
|
onTestFinished(async () => {
|
||||||
|
const fixture = new HopperFixtureLauncher();
|
||||||
|
const published =
|
||||||
|
external && session !== undefined
|
||||||
|
? await fixture.launch(session)
|
||||||
|
: undefined;
|
||||||
|
try {
|
||||||
|
const closed = await client.close();
|
||||||
|
if (!closed.ok) throw closed.error;
|
||||||
|
if (published !== undefined) {
|
||||||
|
expect(fixture.requests.map((request) => request.method)).toEqual([
|
||||||
|
"health",
|
||||||
|
"shutdown_document",
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
if (session !== undefined)
|
||||||
|
await expect(access(session.directory)).rejects.toMatchObject({
|
||||||
|
code: "ENOENT",
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
if (published?.ok) {
|
||||||
|
const cleaned = await published.value.cleanup();
|
||||||
|
expect(cleaned.cleaned).toBe(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return client;
|
||||||
|
};
|
||||||
|
|
||||||
const projectPrimaryStartupFailure = (error: AnalysisError) => {
|
const projectPrimaryStartupFailure = (error: AnalysisError) => {
|
||||||
if (!error.cleanupIncomplete) return projectAnalysisError(error);
|
if (!error.cleanupIncomplete) return projectAnalysisError(error);
|
||||||
@@ -32,10 +87,7 @@ it("does not equate an owned native helper exit with an external GUI exit", asyn
|
|||||||
bridgeScriptPath: "/rea/hopper_bridge.py",
|
bridgeScriptPath: "/rea/hopper_bridge.py",
|
||||||
launchMode: "native",
|
launchMode: "native",
|
||||||
});
|
});
|
||||||
const client = new HopperClient({ launcher, startupTimeoutMs: 10_000 });
|
const client = trackFailedHelperClient(launcher);
|
||||||
onTestFinished(async () => {
|
|
||||||
await client.close();
|
|
||||||
}, 45_000);
|
|
||||||
const result = await client.start();
|
const result = await client.start();
|
||||||
expect(result).toMatchObject({
|
expect(result).toMatchObject({
|
||||||
ok: false,
|
ok: false,
|
||||||
@@ -84,10 +136,7 @@ it.each(["exit", "signal", "exit75"] as const)(
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const client = new HopperClient({ launcher, startupTimeoutMs: 10_000 });
|
const client = trackFailedHelperClient(launcher);
|
||||||
onTestFinished(async () => {
|
|
||||||
await client.close();
|
|
||||||
}, 45_000);
|
|
||||||
const result = await client.start();
|
const result = await client.start();
|
||||||
expect(result).toMatchObject({
|
expect(result).toMatchObject({
|
||||||
ok: false,
|
ok: false,
|
||||||
@@ -136,10 +185,7 @@ it.each([0, 1])(
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const client = new HopperClient({ launcher, startupTimeoutMs: 10_000 });
|
const client = trackFailedHelperClient(launcher);
|
||||||
onTestFinished(async () => {
|
|
||||||
await client.close();
|
|
||||||
}, 45_000);
|
|
||||||
const result = await client.start();
|
const result = await client.start();
|
||||||
expect(result).toMatchObject({
|
expect(result).toMatchObject({
|
||||||
ok: false,
|
ok: false,
|
||||||
@@ -174,10 +220,7 @@ it("preserves a successful helper's diagnostics when bridge readiness is never o
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const client = new HopperClient({ launcher, startupTimeoutMs: 1500 });
|
const client = trackFailedHelperClient(launcher, 1500);
|
||||||
onTestFinished(async () => {
|
|
||||||
await client.close();
|
|
||||||
}, 45_000);
|
|
||||||
const result = await client.start();
|
const result = await client.start();
|
||||||
if (result.ok)
|
if (result.ok)
|
||||||
throw new Error("Expected missing bridge readiness to time out");
|
throw new Error("Expected missing bridge readiness to time out");
|
||||||
|
|||||||
@@ -53,10 +53,7 @@ class CancelThenFixtureLauncher implements BridgeLauncher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class ExitingLauncher implements BridgeLauncher {
|
class ExitingLauncher implements BridgeLauncher {
|
||||||
constructor(
|
constructor(readonly code: number) {}
|
||||||
readonly code: number,
|
|
||||||
readonly ownsProcessLifetime = true,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
launch() {
|
launch() {
|
||||||
return Promise.resolve(
|
return Promise.resolve(
|
||||||
@@ -64,10 +61,8 @@ class ExitingLauncher implements BridgeLauncher {
|
|||||||
process: spawn(process.execPath, ["-e", `process.exit(${this.code})`], {
|
process: spawn(process.execPath, ["-e", `process.exit(${this.code})`], {
|
||||||
stdio: ["ignore", "ignore", "pipe"],
|
stdio: ["ignore", "ignore", "pipe"],
|
||||||
}),
|
}),
|
||||||
ownsProcessLifetime: this.ownsProcessLifetime,
|
ownsProcessLifetime: true as const,
|
||||||
providerLifetime: this.ownsProcessLifetime
|
providerLifetime: "launcher-process" as const,
|
||||||
? ("launcher-process" as const)
|
|
||||||
: ("external-application" as const),
|
|
||||||
shutdownMode: "bridge-request" as const,
|
shutdownMode: "bridge-request" as const,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@@ -286,21 +281,4 @@ describe("HopperClient startup failures", () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("allows a short-lived launcher to hand off bridge startup", async () => {
|
|
||||||
const client = new HopperClient({
|
|
||||||
launcher: new ExitingLauncher(0, false),
|
|
||||||
startupTimeoutMs: 100,
|
|
||||||
});
|
|
||||||
clients.push(client);
|
|
||||||
const result = await client.start();
|
|
||||||
expect(result.ok).toBe(false);
|
|
||||||
if (!result.ok) {
|
|
||||||
expect(result.error).toMatchObject({
|
|
||||||
cleanupIncomplete: true,
|
|
||||||
cause: { _tag: "HopperTimeoutError" },
|
|
||||||
diagnostics: { primary_error: { code: "provider_timeout" } },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
Vendored
+7
@@ -10,8 +10,13 @@ const [
|
|||||||
] = process.argv.slice(2);
|
] = process.argv.slice(2);
|
||||||
let diagnosticOutputEmitted = false;
|
let diagnosticOutputEmitted = false;
|
||||||
const heldReplies = new Map();
|
const heldReplies = new Map();
|
||||||
|
const sockets = new Set();
|
||||||
if (process.send !== undefined)
|
if (process.send !== undefined)
|
||||||
process.on("message", (message) => {
|
process.on("message", (message) => {
|
||||||
|
if (message?.disconnect === true) {
|
||||||
|
for (const socket of sockets) socket.destroy();
|
||||||
|
return;
|
||||||
|
}
|
||||||
const reply = heldReplies.get(message?.release);
|
const reply = heldReplies.get(message?.release);
|
||||||
if (reply === undefined) return;
|
if (reply === undefined) return;
|
||||||
heldReplies.delete(message.release);
|
heldReplies.delete(message.release);
|
||||||
@@ -173,6 +178,8 @@ const sendEchoWithProgress = (send, request) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const server = createServer((socket) => {
|
const server = createServer((socket) => {
|
||||||
|
sockets.add(socket);
|
||||||
|
socket.once("close", () => sockets.delete(socket));
|
||||||
socket.on("error", () => undefined);
|
socket.on("error", () => undefined);
|
||||||
socket.setEncoding("utf8");
|
socket.setEncoding("utf8");
|
||||||
let buffer = "";
|
let buffer = "";
|
||||||
|
|||||||
Reference in New Issue
Block a user