diff --git a/scripts/verify/baselines/captured-output-copy.json b/scripts/verify/baselines/captured-output-copy.json index cb5a38b35b..f56790b4ca 100644 --- a/scripts/verify/baselines/captured-output-copy.json +++ b/scripts/verify/baselines/captured-output-copy.json @@ -5,8 +5,6 @@ "src/captures/TsharkCaptureProvider.ts": 1, "src/desktop/TaskReaderProcess.ts": 1, "src/evm/EvmoleInterfaceProvider.ts": 1, - "src/firmware/FirmwareCommand.ts": 4, - "src/firmware/FirmwareProvider.ts": 1, "src/gdb/GdbSessionManager.ts": 1, "src/javascript/recovery/WakaruCommand.ts": 1, "src/javascript/sourceMaps/SourceMapCommand.ts": 1, diff --git a/src/firmware/FirmwareCommand.ts b/src/firmware/FirmwareCommand.ts index 8e8def3a2c..bd4eee9f61 100644 --- a/src/firmware/FirmwareCommand.ts +++ b/src/firmware/FirmwareCommand.ts @@ -325,13 +325,7 @@ export const runFirmwareCommand = async (context: { diagnostics: { reason: "Tool failed; inspect exit status and stderr for format, dependency, sandbox or resource-limit failures", - exit_code: snapshot.exitCode ?? null, - signal: snapshot.signal ?? null, - stdout: snapshot.stdout.text, - stderr: snapshot.stderr.text, - stdout_bytes: snapshot.stdout.bytes, - stderr_bytes: snapshot.stderr.bytes, - truncated: snapshot.diagnosticTruncated === true, + ...capturedProviderOutput(snapshot), }, remediationAction: `Inspect exit status and stderr for format, dependency, sandbox, or resource-limit failures. ${firmwareProcessLimitRecovery(fileSizeBytes, fileSizeAdjustable)} A format or dependency failure is not repaired by changing analysis_timeout_ms.`, }); @@ -373,11 +367,7 @@ export const runFirmwareCommand = async (context: { operation, `Tool diagnostics exceeded the ${FIRMWARE_LIMITS.diagnosticBytes}-byte capture budget`, { - capturedOutput: { - stdout: snapshot.stdout.text, - stderr: snapshot.stderr.text, - truncated: true, - }, + capturedOutput: capturedProviderOutput(snapshot), userMessage: `Firmware diagnostics exceeded the ${String(FIRMWARE_LIMITS.diagnosticBytes)}-byte capture allowance. This release has no runtime override.`, remediationAction: firmwareLimitRecovery( `The firmware diagnostic capture allowance is ${String(FIRMWARE_LIMITS.diagnosticBytes)} bytes`, @@ -448,6 +438,20 @@ export const runFirmwareCommand = async (context: { }; }; +/** The captured output of a completed firmware command, from the shared owner. */ +export const firmwareExecutionOutput = ( + execution: Pick< + Awaited>, + "stdout" | "stderr" | "exit_code" | "signal" + >, +) => + capturedProviderOutput({ + stdout: execution.stdout, + stderr: execution.stderr, + exitCode: execution.exit_code, + signal: execution.signal, + }); + /** * Consume the report a completed command was asked to write. A successful exit * status is not analysis Evidence by itself: an absent, empty or malformed report @@ -486,15 +490,7 @@ export const readFirmwareCommandReport = async (context: { ); if (cause.partialObservation !== undefined) failure.retainPartialObservation(cause.partialObservation); - throw failure.retainCapturedOutput({ - stdout: execution.stdout.text, - stderr: execution.stderr.text, - stdout_bytes: execution.stdout.bytes, - stderr_bytes: execution.stderr.bytes, - exit_code: execution.exit_code ?? null, - signal: execution.signal, - truncated: false, - }); + throw failure.retainCapturedOutput(firmwareExecutionOutput(execution)); } const { engine, operation, execution } = context; const reportFailure = @@ -508,12 +504,7 @@ export const readFirmwareCommandReport = async (context: { command: execution.command, args: execution.args, resource_limiter: execution.resource_limiter, - exit_code: execution.exit_code ?? null, - signal: execution.signal, - stdout: execution.stdout.text, - stderr: execution.stderr.text, - stdout_bytes: execution.stdout.bytes, - stderr_bytes: execution.stderr.bytes, + ...firmwareExecutionOutput(execution), }; if (execution.exit_code === 1) throw new ProviderAdapterError(engine, operation, { diff --git a/src/firmware/FirmwareProvider.ts b/src/firmware/FirmwareProvider.ts index 04919da691..90faf98c7a 100644 --- a/src/firmware/FirmwareProvider.ts +++ b/src/firmware/FirmwareProvider.ts @@ -34,6 +34,7 @@ import type { ProviderProcessSupervisor } from "../process/ProviderProcess.js"; import { SafeOutputTree, outputDirectoryAdmissionRefusal, + AnalysisCleanupLease, } from "../resources/index.js"; import { publishFirmwareExtraction } from "./FirmwarePublication.js"; import { @@ -49,6 +50,7 @@ import { firmwareFileSizeLimit, firmwareToolUnavailable, resolveFirmwareCommand, + firmwareExecutionOutput, runFirmwareCommand, readFirmwareCommandReport, type FirmwareLauncher, @@ -67,7 +69,6 @@ import { firmwarePhaseInterruption, firmwareSignalInterruption, } from "./FirmwareFailures.js"; -import { AnalysisCleanupLease } from "../resources/index.js"; type Outcome = Awaited>; interface PendingFirmwareCleanup { @@ -430,15 +431,7 @@ export class FirmwareProvider implements FirmwareAnalysisPort { }); for (const selected of [command.command, command.limiter]) await assertArtifactCommandPath(selected, request.operation, { - capturedOutput: { - stdout: output.stdout.text, - stderr: output.stderr.text, - stdout_bytes: output.stdout.bytes, - stderr_bytes: output.stderr.bytes, - exit_code: output.exit_code ?? null, - signal: output.signal, - truncated: false, - }, + capturedOutput: firmwareExecutionOutput(output), }); return output; };