From e5cf021ca6847e047d90e1835ac068b2a31f95a1 Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Mon, 16 Nov 2026 09:55:29 +0800 Subject: [PATCH] fix(process): classify GDB, Apktool and Java-probe launch failures through the shared launch owner (#11631) * fix(process): classify GDB, Apktool and Java-probe launch failures through the shared launch owner GDB session start, the Apktool version probe and the Jadx and Ghidra Java probes read a launcher's error with launcherFailureOf and report host capacity (EAGAIN, ENOMEM, EMFILE, ENFILE) and E2BIG through the shared classifyLaunchFailure, keeping their own unavailable reports for refusals. Only a launcher-raised errno counts as a launch failure, and a GDB launch failure no longer retries the MI2 dialect. The refusal-only classifyLaunchFailure helper is removed. Refs #11614 * fix(process): name the environment as the E2BIG repair for fixed-argument launches GDB, the Apktool version probe and the Jadx and Ghidra Java probes launch fixed arguments, so selecting less input cannot shrink an oversized launch. The shared launch report takes fixedArguments and then tells the caller to shrink the environment REA runs with. Launch tests check structured facts and guidance delivery instead of whole sentences. * fix(process): report which launch input an E2BIG refusal leaves to shrink as a structured fact --- scripts/verify-advertised-schemas.mjs | 10 ++- src/android/JadxJavaProbe.test.ts | 77 +++++++++++++++++++ src/android/JadxJavaProbe.ts | 32 +++++++- src/apktool/ApktoolConfiguration.ts | 27 +++++-- src/apktool/ApktoolVersionProbe.test.ts | 45 ++++++++++- src/gdb/GdbSessionManager.ts | 66 +++++++++++----- src/ghidra/GhidraJavaProbe.test.ts | 55 ++++++++++++- src/ghidra/GhidraJavaProbe.ts | 18 ++++- src/process/classifyProviderOutcome.ts | 19 ++++- src/process/launchFailure.test.ts | 4 - src/process/launchFailure.ts | 8 -- .../boundary/cli/gdbStartupCleanupCli.test.ts | 10 +-- .../GdbSessionManagerCoverage.test.ts | 56 ++++++++++++++ 13 files changed, 371 insertions(+), 56 deletions(-) diff --git a/scripts/verify-advertised-schemas.mjs b/scripts/verify-advertised-schemas.mjs index 21bf7395fe..4446fd6afd 100644 --- a/scripts/verify-advertised-schemas.mjs +++ b/scripts/verify-advertised-schemas.mjs @@ -18,7 +18,7 @@ import { withVerifierFixture, } from "./lib/verifier-fixture.mjs"; import { createVerifierCommands } from "./lib/verify-commands.mjs"; -import { classifyLaunchFailure } from "../dist/process/launchFailure.js"; +import { launcherFailureOf } from "../dist/process/launchFailure.js"; // Compile every regular expression and schema the packaged server advertises, // in every schema profile, with the engines and validators clients and @@ -80,11 +80,13 @@ const runHelper = async ( })); } } catch (error) { - const refusal = classifyLaunchFailure(error); - if (refusal !== undefined) + // Only a launch refusal means the engine is not installed; a host + // capacity failure is a broken check. + const launch = launcherFailureOf(error); + if (launch?.kind === "missing" || launch?.kind === "not_executable") return engines.map((engine) => ({ ...engine, - unavailable: `${command} could not start (${refusal.code})`, + unavailable: `${command} could not start (${launch.code})`, })); // A helper that started but failed is a broken check, not a missing // engine, so it fails even when engines are optional. diff --git a/src/android/JadxJavaProbe.test.ts b/src/android/JadxJavaProbe.test.ts index 898c5f24aa..31fda3503f 100644 --- a/src/android/JadxJavaProbe.test.ts +++ b/src/android/JadxJavaProbe.test.ts @@ -18,6 +18,8 @@ import { import type { OwnedProviderProcessSpawnOptions } from "../process/ProviderProcess.js"; import { failedInspectionDescriptor } from "../../tests/fixtures/processInspectionCleanup.js"; import { createInspectionResources } from "../../tests/fixtures/inspectionResources.js"; +import { spawnFailure } from "../../tests/support/process/spawnFailure.js"; +import { projectAnalysisError } from "../domain/analysisErrorProjection.js"; it.each([false, true])( "retains physical preparation instead of reporting a Java refusal (batch: %s)", @@ -210,3 +212,78 @@ it.each(["probe", "configuration"] as const)( } }, ); + +it.each([ + { code: "ENOENT", thrown: "launcher", expected: "runtime_missing" }, + { code: "ENOENT", thrown: "reader", expected: "runtime_unavailable" }, + { code: "EACCES", thrown: "launcher", expected: "runtime_unavailable" }, +] as const)( + "reads only a launcher's $code as a Java runtime refusal ($thrown)", + async ({ code, thrown, expected }) => { + const resources = createInspectionResources(); + const prepare = vi + .spyOn(systemProcessOwnershipHost, "prepare") + .mockResolvedValue(undefined); + try { + const result = await inspectJadxJava( + "/selected/java", + {}, + { + resourceOwner: resources.owner, + launcher: async () => { + throw thrown === "launcher" + ? spawnFailure(code, "/selected/java") + : Object.assign(new Error("read failed"), { code }); + }, + }, + ); + expect(result).toMatchObject({ ok: false, error: { code: expected } }); + } finally { + prepare.mockRestore(); + await resources.close(); + } + }, +); + +it.each([ + ["EAGAIN", true, {}], + // The probe's arguments are fixed, so only the environment can shrink. + ["E2BIG", false, { oversized_launch_input: "environment" }], +] as const)( + "reports a host launch constraint %s as a resource constraint, not a Java refusal", + async (code, retryable, facts) => { + const resources = createInspectionResources(); + const prepare = vi + .spyOn(systemProcessOwnershipHost, "prepare") + .mockResolvedValue(undefined); + try { + const result: unknown = await inspectJadxJava( + "/selected/java", + {}, + { + resourceOwner: resources.owner, + launcher: async () => { + throw spawnFailure(code, "/selected/java"); + }, + }, + ).catch((cause: unknown) => cause); + expect(result).toBeInstanceOf(AnalysisError); + if (!(result instanceof AnalysisError)) throw result; + expect(projectAnalysisError(result)).toMatchObject({ + code: "resource_constraint", + retryable, + details: { + diagnostics: { + system_code: code, + command: "/selected/java", + java_executable: "/selected/java", + ...facts, + }, + }, + }); + } finally { + prepare.mockRestore(); + await resources.close(); + } + }, +); diff --git a/src/android/JadxJavaProbe.ts b/src/android/JadxJavaProbe.ts index 8aee253e3e..adb611b59d 100644 --- a/src/android/JadxJavaProbe.ts +++ b/src/android/JadxJavaProbe.ts @@ -1,6 +1,7 @@ import { capturedProviderOutput } from "../process/capturedProviderOutput.js"; import type { ProcessInspectionFailure } from "../process/ProcessInspectionCleanup.js"; -import { classifyLaunchFailureCode } from "../process/launchFailure.js"; +import { launcherFailureOf } from "../process/launchFailure.js"; +import { classifyLaunchFailure } from "../process/classifyProviderOutcome.js"; import { randomUUID } from "node:crypto"; import type { RetainedResourceScope } from "../ports/AnalysisProvider.js"; import { @@ -164,6 +165,7 @@ export const inspectJadxJava = async ( "jadx", operation, ); + const hostConstraint = hostLaunchConstraint(command, cause); let primary: AnalysisError; if (observed !== undefined && !observed.ok) { if (cleanups.length === 0) return observed; @@ -244,6 +246,21 @@ export const inspectJadxJava = async ( cause, ...(output === undefined ? {} : { capturedOutput: output }), }); + } else if (hostConstraint !== undefined) { + // The host, not the selected Java runtime, refused this launch. + primary = classifyLaunchFailure(hostConstraint, { + providerId: "jadx", + operation, + fixedArguments: true, + command: java, + details: { + cause, + diagnostics: { + java_executable: java, + phase: "module-inspection", + }, + }, + }); } else { const failure = commandProbeRefusal( java, @@ -273,6 +290,17 @@ export const inspectJadxJava = async ( } }; +/** A launch the host refused for capacity or argument size, not the runtime's fault. */ +const hostLaunchConstraint = ( + command: Pick | undefined, + cause: unknown, +) => { + const launch = launcherFailureOf(command?.processError ?? cause); + return launch?.kind === "host-exhausted" || launch?.kind === "argument-list" + ? launch + : undefined; +}; + const commandProbeRefusal = ( java: string, command: @@ -289,7 +317,7 @@ const commandProbeRefusal = ( command?.processError ?? (cause instanceof Error ? cause : undefined); const systemCode = processError === undefined ? undefined : Reflect.get(processError, "code"); - const missing = classifyLaunchFailureCode(systemCode)?.kind === "missing"; + const missing = launcherFailureOf(processError)?.kind === "missing"; const limited = command?.reason === "output-limit"; const timedOut = command?.reason === "timeout"; return { diff --git a/src/apktool/ApktoolConfiguration.ts b/src/apktool/ApktoolConfiguration.ts index 13e5966bc2..a4e35015c9 100644 --- a/src/apktool/ApktoolConfiguration.ts +++ b/src/apktool/ApktoolConfiguration.ts @@ -10,7 +10,8 @@ import { ApktoolCommandCleanup } from "./ApktoolCommandCleanup.js"; import { AnalysisError } from "../domain/analysisErrorBase.js"; import { ProviderAdapterError } from "../domain/providerAdapterError.js"; import { DarwinProcessOwnershipInspectionError } from "../process/DarwinProcessRunTokenReader.js"; -import { classifyLaunchFailure } from "../process/launchFailure.js"; +import { launcherFailureOf } from "../process/launchFailure.js"; +import { classifyLaunchFailure } from "../process/classifyProviderOutcome.js"; import { AnalysisResourceConstraintError, AnalysisTimeoutError, @@ -519,9 +520,25 @@ const versionProbeFailure = ( ...apktoolVersionProbeTimeoutGuidance(), }, ); - const refusal = classifyLaunchFailure(cause); - if (refusal !== undefined) { - const execDenied = refusal.kind === "not_executable"; + const launch = launcherFailureOf(cause); + // The host, not the selected launcher, refused this launch. + if (launch?.kind === "host-exhausted" || launch?.kind === "argument-list") + return classifyLaunchFailure(launch, { + providerId: "apktool", + operation: "inspect_apktool_client", + command: selection.command, + fixedArguments: true, + selection: APKTOOL_COMMAND_ENV, + details: { + cause, + diagnostics: { + selected_command: selection.command, + command_source: selection.commandSource, + }, + }, + }); + if (launch?.kind === "missing" || launch?.kind === "not_executable") { + const execDenied = launch.kind === "not_executable"; return new ApktoolConfigurationFailure( execDenied ? "command_not_executable" : "command_missing", execDenied @@ -531,7 +548,7 @@ const versionProbeFailure = ( ? APKTOOL_NOT_EXECUTABLE_REMEDIATION : APKTOOL_MISSING_REMEDIATION, { - filesystem_error: refusal.code, + filesystem_error: launch.code, selected_command: selection.command, command_source: selection.commandSource, }, diff --git a/src/apktool/ApktoolVersionProbe.test.ts b/src/apktool/ApktoolVersionProbe.test.ts index 8786991d03..a68fb5114b 100644 --- a/src/apktool/ApktoolVersionProbe.test.ts +++ b/src/apktool/ApktoolVersionProbe.test.ts @@ -5,7 +5,9 @@ import { AnalysisCancelledError, AnalysisTimeoutError, } from "../domain/analysisErrorCore.js"; +import { AnalysisError } from "../domain/analysisErrorBase.js"; import { projectAnalysisError } from "../domain/analysisErrorProjection.js"; +import { spawnFailure } from "../../tests/support/process/spawnFailure.js"; import { OwnedCommandFailure, runOwnedCommand, @@ -205,7 +207,7 @@ it.each([ ["ENOENT", "command_missing"], ])("distinguishes launcher spawn %s", async (code, expected) => { vi.mocked(runOwnedCommand).mockRejectedValueOnce( - Object.assign(new Error(code), { code }), + spawnFailure(code, selection.command), ); await expect( inspectApktoolClient(selection, commands, { @@ -221,6 +223,47 @@ it.each([ }); }); +it("does not read an errno from outside the launcher as a launch refusal", async () => { + vi.mocked(runOwnedCommand).mockRejectedValueOnce( + Object.assign(new Error("read failed"), { code: "ENOENT" }), + ); + await expect( + inspectApktoolClient(selection, commands, { + environment: {}, + platform: "linux", + }), + ).rejects.toMatchObject({ code: "version_unresolved" }); +}); + +it.each([ + ["EAGAIN", true], + ["E2BIG", false], +])( + "reports a host launch constraint %s as a resource constraint, not a launcher fault", + async (code, retryable) => { + vi.mocked(runOwnedCommand).mockRejectedValueOnce( + spawnFailure(code, selection.command), + ); + const failure = await inspectApktoolClient(selection, commands, { + environment: {}, + platform: "linux", + }).catch((cause: unknown) => cause); + expect(failure).toBeInstanceOf(AnalysisError); + expect(projectAnalysisError(failure as AnalysisError)).toMatchObject({ + code: "resource_constraint", + retryable, + details: { + operation: "inspect_apktool_client", + diagnostics: { + system_code: code, + command: selection.command, + selected_command: selection.command, + }, + }, + }); + }, +); + it("reports version capture overflow as a resource constraint with the selected launcher", async () => { vi.mocked(runOwnedCommand).mockRejectedValueOnce( new OwnedCommandFailure("output-limit", "too much output"), diff --git a/src/gdb/GdbSessionManager.ts b/src/gdb/GdbSessionManager.ts index 23e5eefbd2..45edc4e67c 100644 --- a/src/gdb/GdbSessionManager.ts +++ b/src/gdb/GdbSessionManager.ts @@ -18,7 +18,14 @@ import { import { persistentDebuggerHostSupported } from "../process/PersistentDebuggerHost.js"; import { HOST_PLATFORM } from "../platform/HostPlatform.js"; import { AbortedWait, waitForAbortable } from "../process/AbortablePromise.js"; -import { classifyLaunchFailure } from "../process/launchFailure.js"; +import { + describeLaunchFailure, + launcherFailureOf, +} from "../process/launchFailure.js"; +import { + classifyLaunchFailure, + type LaunchUnavailableFailure, +} from "../process/classifyProviderOutcome.js"; import { snapshotGdbCommandRecords } from "./GdbCommandRecords.js"; import { randomUUID } from "node:crypto"; import { constants as fsConstants } from "node:fs"; @@ -108,22 +115,28 @@ const copiedTimeoutGuidance = ( : { diagnostics: cause.diagnostics }), ...(cause.limit === undefined ? {} : { limit: cause.limit }), }); -/** A host executable refusal cannot be repaired by changing MI dialect. */ -class GdbExecutableRefusal extends AnalysisCapabilityUnavailableError { - constructor(command: string, systemCode: string, cause: Error) { - super("gdb", "start_gdb_session", cause.message, { - cause, - userMessage: `Could not launch the selected GDB executable ${JSON.stringify(command)} (${systemCode}).`, +/** The selected GDB executable could not be started. */ +const gdbLaunchUnavailable = ( + command: string, + failure: LaunchUnavailableFailure, + details: AnalysisErrorOptions, +): AnalysisCapabilityUnavailableError => { + const reason = `Could not launch the selected GDB executable ${JSON.stringify(command)} (${describeLaunchFailure(failure)}).`; + return new AnalysisCapabilityUnavailableError( + "gdb", + "start_gdb_session", + reason, + { + ...details, + userMessage: reason, remediationAction: "Set REA_GDB_COMMAND to an installed executable GDB command, or make that command available on PATH. Check execute permission on the command and search permission on its parent directories before retrying.", - diagnostics: { - boundary: "provider-launch", - command, - system_code: systemCode, - }, - }); - } -} + }, + ); +}; + +/** Launch failures: changing the MI dialect cannot start the executable. */ +const gdbLaunchFailures = new WeakSet(); const MAX_COMMAND_OUTPUT_RECORDS = 16_384; const MAX_MI_LINE_BYTES = 16 * 1024 * 1024; @@ -551,7 +564,7 @@ export class GdbSessionManager { return mi3.ok || signal.aborted || this.#sessions.has(id) || - mi3.error instanceof GdbExecutableRefusal + gdbLaunchFailures.has(mi3.error) ? mi3 : this.#startProtocol( id, @@ -591,11 +604,22 @@ export class GdbSessionManager { cause instanceof AnalysisCancelledError ) return err(cancelledBy("start_gdb_session", carriedReason(cause))); - const refusal = classifyLaunchFailure(cause); - if (refusal !== undefined && cause instanceof Error) - return err( - new GdbExecutableRefusal(this.#command, refusal.code, cause), - ); + const launch = launcherFailureOf(cause); + if (launch !== undefined) { + const command = this.#command; + const failure = classifyLaunchFailure(launch, { + providerId: "gdb", + operation: "start_gdb_session", + command, + fixedArguments: true, + selection: "REA_GDB_COMMAND", + details: { cause }, + unavailable: (unavailable, details) => + gdbLaunchUnavailable(command, unavailable, details), + }); + gdbLaunchFailures.add(failure); + return err(failure); + } return err( new AnalysisCapabilityUnavailableError( "gdb", diff --git a/src/ghidra/GhidraJavaProbe.test.ts b/src/ghidra/GhidraJavaProbe.test.ts index 7f4994fec5..4a6437b345 100644 --- a/src/ghidra/GhidraJavaProbe.test.ts +++ b/src/ghidra/GhidraJavaProbe.test.ts @@ -12,6 +12,8 @@ import { projectGhidraDoctorInspection } from "./GhidraDoctor.js"; import { describe, expect, it, afterEach } from "vitest"; import { probeGhidraJava, parseGhidraJavaOutput } from "./GhidraJavaProbe.js"; import { createInspectionResources } from "../../tests/fixtures/inspectionResources.js"; +import { spawnFailure } from "../../tests/support/process/spawnFailure.js"; +import { projectAnalysisError } from "../domain/analysisErrorProjection.js"; let resources = createInspectionResources(); afterEach(async () => { await resources.close(); @@ -52,7 +54,7 @@ describe("Ghidra Java prerequisite process facts", () => { ])( "keeps %s distinct from other runtime failures", async (code, expected) => { - const error = Object.assign(new Error(`controlled ${code}`), { code }); + const error = spawnFailure(code, "/selected/bin/java"); const result = await probeGhidraJava( "/selected/bin/java", {}, @@ -76,6 +78,57 @@ describe("Ghidra Java prerequisite process facts", () => { }, ); + it("does not read an errno from outside the launcher as a missing runtime", async () => { + const result = await probeGhidraJava( + "/selected/bin/java", + {}, + { + resourceOwner: resources.owner, + launcher: async () => { + throw Object.assign(new Error("read failed"), { code: "ENOENT" }); + }, + }, + ); + expect(result).toMatchObject({ + ok: false, + error: { _tag: "GhidraJavaProbeFailure", code: "runtime_unavailable" }, + }); + }); + + it.each([ + ["EAGAIN", true], + ["E2BIG", false], + ])( + "reports a host launch constraint %s as a resource constraint, not a runtime fault", + async (code, retryable) => { + const result = await probeGhidraJava( + "/selected/bin/java", + {}, + { + resourceOwner: resources.owner, + launcher: async () => { + throw spawnFailure(code, "/selected/bin/java"); + }, + }, + ); + expect(result.ok).toBe(false); + if (result.ok) return; + expect(result.error).toBeInstanceOf(AnalysisError); + if (!(result.error instanceof AnalysisError)) return; + expect(projectAnalysisError(result.error)).toMatchObject({ + code: "resource_constraint", + retryable, + details: { + diagnostics: { + system_code: code, + command: "/selected/bin/java", + java_executable: "/selected/bin/java", + }, + }, + }); + }, + ); + it("keeps raw byte counts and both streams on a nonzero exit", () => { const result = probe({ status: 7, diff --git a/src/ghidra/GhidraJavaProbe.ts b/src/ghidra/GhidraJavaProbe.ts index be2759cfc5..3706472cef 100644 --- a/src/ghidra/GhidraJavaProbe.ts +++ b/src/ghidra/GhidraJavaProbe.ts @@ -1,6 +1,7 @@ import type { ProcessInspectionFailure } from "../process/ProcessInspectionCleanup.js"; import { HOST_PLATFORM } from "../platform/HostPlatform.js"; -import { classifyLaunchFailureCode } from "../process/launchFailure.js"; +import { launcherFailureOf } from "../process/launchFailure.js"; +import { classifyLaunchFailure } from "../process/classifyProviderOutcome.js"; import { GhidraAdmissionError } from "./GhidraAdmissionError.js"; import { retainOwnedCommandCleanup, @@ -291,6 +292,19 @@ const observeGhidraJava = async ( } else if (cause instanceof AnalysisError) { primary = cause; } + const launch = launcherFailureOf(commandFailure?.processError ?? cause); + if ( + primary === undefined && + (launch?.kind === "host-exhausted" || launch?.kind === "argument-list") + ) + // The host, not the selected Java runtime, refused this launch. + primary = classifyLaunchFailure(launch, { + providerId: "ghidra", + operation: "ghidra:java", + fixedArguments: true, + command, + details: { cause, diagnostics: { java_executable: command } }, + }); if (primary === undefined) { const code = commandFailure?.reason === "timeout" @@ -301,7 +315,7 @@ const observeGhidraJava = async ( const failed: GhidraJavaProbeFailure = { _tag: "GhidraJavaProbeFailure", code: - classifyLaunchFailureCode(code)?.kind === "missing" + launch?.kind === "missing" ? "runtime_missing" : "runtime_unavailable", detail: `${command}: ${errorMessage(cause)}`, diff --git a/src/process/classifyProviderOutcome.ts b/src/process/classifyProviderOutcome.ts index eb24b5339f..9081934f4c 100644 --- a/src/process/classifyProviderOutcome.ts +++ b/src/process/classifyProviderOutcome.ts @@ -68,6 +68,12 @@ export interface LaunchFailureContext { readonly selection?: string; /** Bytes of the refused argument list, when the caller measured them. */ readonly argumentBytes?: number; + /** + * The command's arguments do not depend on the request, so an oversized + * launch (E2BIG) can only be repaired by shrinking the environment REA + * passes to it. + */ + readonly fixedArguments?: boolean; /** * The provider's report that it cannot be started, such as a message naming * its configured executable. Without it the shared report names the @@ -139,8 +145,19 @@ export const classifyLaunchFailure = ( }, { ...details, + diagnostics: { + ...details.diagnostics, + // Fixed arguments leave the environment as the only input to shrink. + oversized_launch_input: + context.fixedArguments === true + ? "environment" + : "request_and_environment", + }, retryable: false, - remediationAction: `Select less input for one call, or pass large values through a file, then retry; ${unchanged}. An unchanged request fails the same way.`, + remediationAction: + context.fixedArguments === true + ? `This command's arguments do not depend on the request, so the environment REA passes to it is too large. Remove large or unneeded variables from the environment REA runs with, then retry; ${unchanged}. Retrying in the same environment fails the same way.` + : `Select less input for one call, or pass large values through a file, then retry; ${unchanged}. An unchanged request fails the same way.`, }, ); case "missing": diff --git a/src/process/launchFailure.test.ts b/src/process/launchFailure.test.ts index 15cc25f71b..42ef56cfd4 100644 --- a/src/process/launchFailure.test.ts +++ b/src/process/launchFailure.test.ts @@ -1,7 +1,6 @@ import { expect, it } from "vitest"; import { - classifyLaunchFailure, classifyLaunchFailureCode, classifyLaunchErrno, describeLaunchFailure, @@ -19,9 +18,6 @@ it.each([ ["EISDIR", "not_executable"], ])("classifies spawn %s as %s", (code, kind) => { expect(classifyLaunchFailureCode(code)).toEqual({ kind, code }); - expect( - classifyLaunchFailure(Object.assign(new Error(code), { code })), - ).toEqual({ kind, code }); }); it.each([["EAGAIN"], ["EMFILE"], ["ETIMEDOUT"], [1], [null], ["toString"]])( diff --git a/src/process/launchFailure.ts b/src/process/launchFailure.ts index c8a218e96b..1a61bfb969 100644 --- a/src/process/launchFailure.ts +++ b/src/process/launchFailure.ts @@ -89,14 +89,6 @@ export const classifyLaunchFailureCode = ( return kind === undefined ? undefined : { kind, code }; }; -/** Classify a spawn failure; undefined when it was not a launch refusal. */ -export const classifyLaunchFailure = ( - cause: unknown, -): LaunchRefusal | undefined => - cause instanceof Error && "code" in cause - ? classifyLaunchFailureCode(cause.code) - : undefined; - /** * Name the executable on an errno Node threw synchronously from `spawn`. * Node emits ENOENT and EACCES as `spawn ` with `path`, but throws diff --git a/tests/boundary/cli/gdbStartupCleanupCli.test.ts b/tests/boundary/cli/gdbStartupCleanupCli.test.ts index 6327be0a23..5344243460 100644 --- a/tests/boundary/cli/gdbStartupCleanupCli.test.ts +++ b/tests/boundary/cli/gdbStartupCleanupCli.test.ts @@ -1,5 +1,6 @@ import { EventEmitter } from "node:events"; import { PassThrough } from "node:stream"; +import { spawnFailure } from "../../support/process/spawnFailure.js"; import pino from "pino"; import { expect, it, vi } from "vitest"; @@ -144,12 +145,7 @@ it.each(["ENOENT", "EACCES", "EPERM"] as const)( "keeps selected GDB launch recovery in the public CLI for %s", async (code) => { const selected = "/selected/gdb command"; - const launchFailure = Object.assign( - new Error(`spawn ${selected} ${code}`), - { - code, - }, - ); + const launchFailure = spawnFailure(code, selected); const spawnProcess = vi.fn(async () => { throw launchFailure; }); @@ -170,7 +166,7 @@ it.each(["ENOENT", "EACCES", "EPERM"] as const)( message: expect.stringContaining(JSON.stringify(selected)), remediation: { action: expect.stringContaining("REA_GDB_COMMAND") }, details: { - reason: launchFailure.message, + reason: expect.stringContaining(JSON.stringify(selected)), diagnostics: { boundary: "provider-launch", command: selected, diff --git a/tests/boundary/providers/GdbSessionManagerCoverage.test.ts b/tests/boundary/providers/GdbSessionManagerCoverage.test.ts index 737b39f2ef..84fbd99843 100644 --- a/tests/boundary/providers/GdbSessionManagerCoverage.test.ts +++ b/tests/boundary/providers/GdbSessionManagerCoverage.test.ts @@ -34,6 +34,7 @@ import { stopOwnedDebuggerProcess, type OwnedDebuggerStopResult, } from "../../../src/process/ownedDebuggerSession.js"; +import { spawnFailure } from "../../support/process/spawnFailure.js"; import { parseLinuxProcessStat } from "../../../src/process/LinuxProcessStat.js"; import { answerFakeGdbStartup, @@ -1956,6 +1957,61 @@ it("uses a fallback message when the process launcher rejects without an Error", expect(attempts).toBe(2); }); +it.each([ + { + code: "EAGAIN", + tag: "AnalysisResourceConstraintError", + projected: { code: "resource_constraint", retryable: true }, + boundary: "host-capacity", + }, + { + code: "E2BIG", + tag: "AnalysisResourceConstraintError", + // GDB's arguments are fixed, so the repair names the environment. + projected: { code: "resource_constraint", retryable: false }, + boundary: "provider-launch", + facts: { oversized_launch_input: "environment" }, + }, + { + code: "EIO", + tag: "AnalysisCapabilityUnavailableError", + projected: { + code: "capability_unavailable", + remediation: { action: expect.stringContaining("REA_GDB_COMMAND") }, + }, + boundary: "provider-launch", + }, +])( + "classifies a $code launch failure once without retrying another MI dialect", + async ({ code, tag, projected, boundary, facts }) => { + let attempts = 0; + const manager = managerWithFakeSpawner(async () => { + attempts += 1; + throw spawnFailure(code, "fake-gdb"); + }); + + const started = await manager.start(); + + expect(attempts).toBe(1); + expect(started.ok).toBe(false); + if (!started.ok) { + expect(started.error._tag).toBe(tag); + expect(projectAnalysisError(started.error)).toMatchObject({ + ...projected, + details: { + diagnostics: { + boundary, + system_code: code, + syscall: "spawn fake-gdb", + command: "fake-gdb", + ...facts, + }, + }, + }); + } + }, +); + it("returns startup timeout when the MI prompt never arrives", async () => { const provider = await createProvider( "process.stdin.resume(); setInterval(() => {}, 1000);\n",