fix: name host and tool requirements in optional adapter refusals
Host and tool-configuration refusals from the pwntools, EVMole, firmware, mitmproxy, Wakaru, LLDB and xcrun adapters carried no userMessage, so CLI and MCP callers saw the generic "This analysis is unavailable for the current target. Choose another analysis or target." as both message and remediation. Choosing another target cannot satisfy a Linux-only profile or an unset REA_*_COMMAND. The actual requirement appeared only in details.reason. Pass each refusal's reason as its userMessage, as the adapters' other configuration refusals (EVMole limits, JADX, pwndbg) already do. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
e6905c18e0
commit
170d0bf9e2
@@ -4,10 +4,32 @@ import { join } from "node:path";
|
||||
import { expect, it as test } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "../../tests/fixtures/temporaryDirectory.js";
|
||||
import { AnalysisCapabilityUnavailableError } from "../domain/analysisErrorCore.js";
|
||||
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
|
||||
import { resolveFirmwareCommand } from "./FirmwareCommand.js";
|
||||
|
||||
const it = test.skipIf(process.platform !== "linux");
|
||||
|
||||
test("names the host and tool requirement of an unconfigured engine", async () => {
|
||||
const refusal: unknown = await resolveFirmwareCommand(
|
||||
{},
|
||||
"binwalk",
|
||||
"inspect_firmware_regions",
|
||||
).catch((cause: unknown) => cause);
|
||||
|
||||
expect(refusal).toMatchObject({
|
||||
_tag: "AnalysisCapabilityUnavailableError",
|
||||
});
|
||||
if (!(refusal instanceof AnalysisCapabilityUnavailableError))
|
||||
throw new Error("Expected a capability refusal");
|
||||
expect(projectAnalysisError(refusal)).toMatchObject({
|
||||
code: "capability_unavailable",
|
||||
message: refusal.reason,
|
||||
remediation: { action: refusal.reason },
|
||||
});
|
||||
expect(refusal.reason).toContain("REA_BINWALK_COMMAND");
|
||||
});
|
||||
|
||||
it("rejects a directory configured as the firmware engine executable", async () => {
|
||||
const root = await createTestTempDirectory("rea-firmware-command-");
|
||||
const command = join(root, "binwalk");
|
||||
|
||||
@@ -29,6 +29,16 @@ export type FirmwareLauncher = (
|
||||
options: OwnedProviderProcessSpawnOptions,
|
||||
) => Promise<SpawnedOwnedProviderProcess>;
|
||||
|
||||
/** Refuse an unmet host or tool requirement, which another target cannot satisfy. */
|
||||
export const firmwareToolUnavailable = (
|
||||
engine: string,
|
||||
operation: string,
|
||||
reason: string,
|
||||
): AnalysisCapabilityUnavailableError =>
|
||||
new AnalysisCapabilityUnavailableError(engine, operation, reason, {
|
||||
userMessage: reason,
|
||||
});
|
||||
|
||||
/** Resolve explicitly supplied executable paths; never install or search for engines. */
|
||||
export const resolveFirmwareCommand = async (
|
||||
environment: Readonly<Record<string, string | undefined>>,
|
||||
@@ -43,13 +53,13 @@ export const resolveFirmwareCommand = async (
|
||||
configured === undefined ||
|
||||
!isAbsolute(configured)
|
||||
)
|
||||
throw new AnalysisCapabilityUnavailableError(
|
||||
throw firmwareToolUnavailable(
|
||||
engine,
|
||||
operation,
|
||||
`This integration requires Linux and an absolute ${variable} path to the caller-supplied tool`,
|
||||
);
|
||||
const command = await realpath(configured).catch((cause: unknown) => {
|
||||
throw new AnalysisCapabilityUnavailableError(
|
||||
throw firmwareToolUnavailable(
|
||||
engine,
|
||||
operation,
|
||||
`${variable} is unavailable: ${cause instanceof Error ? cause.message : String(cause)}`,
|
||||
@@ -62,7 +72,7 @@ export const resolveFirmwareCommand = async (
|
||||
throw new TypeError("Configured path is not a regular file");
|
||||
sha256 = await hashFirmwareFile(command);
|
||||
} catch (cause: unknown) {
|
||||
throw new AnalysisCapabilityUnavailableError(
|
||||
throw firmwareToolUnavailable(
|
||||
engine,
|
||||
operation,
|
||||
`${variable} is not a readable executable regular file: ${command}: ${cause instanceof Error ? cause.message : String(cause)}`,
|
||||
@@ -71,7 +81,7 @@ export const resolveFirmwareCommand = async (
|
||||
const limiter =
|
||||
environment.REA_FIRMWARE_PRLIMIT_COMMAND ?? "/usr/bin/prlimit";
|
||||
if (!isAbsolute(limiter))
|
||||
throw new AnalysisCapabilityUnavailableError(
|
||||
throw firmwareToolUnavailable(
|
||||
engine,
|
||||
operation,
|
||||
"REA_FIRMWARE_PRLIMIT_COMMAND must be absolute",
|
||||
@@ -81,7 +91,7 @@ export const resolveFirmwareCommand = async (
|
||||
if (!(await stat(limiter)).isFile())
|
||||
throw new TypeError("Configured path is not a regular file");
|
||||
} catch (cause: unknown) {
|
||||
throw new AnalysisCapabilityUnavailableError(
|
||||
throw firmwareToolUnavailable(
|
||||
engine,
|
||||
operation,
|
||||
`Resource limiter is not an executable regular file: ${limiter}: ${cause instanceof Error ? cause.message : String(cause)}; provide util-linux prlimit`,
|
||||
|
||||
@@ -12,7 +12,6 @@ import {
|
||||
import { AnalysisError } from "../domain/analysisErrorBase.js";
|
||||
import {
|
||||
AnalysisCancelledError,
|
||||
AnalysisCapabilityUnavailableError,
|
||||
AnalysisInputError,
|
||||
AnalysisOutputError,
|
||||
AnalysisTimeoutError,
|
||||
@@ -29,6 +28,7 @@ import {
|
||||
} from "./FirmwareRelease.js";
|
||||
import { admitFirmwareVersion } from "./FirmwareVersion.js";
|
||||
import {
|
||||
firmwareToolUnavailable,
|
||||
resolveFirmwareCommand,
|
||||
runFirmwareCommand,
|
||||
readFirmwareCommandReport,
|
||||
@@ -144,14 +144,14 @@ export class FirmwareProvider implements FirmwareAnalysisPort {
|
||||
const versionRun = await run(["--version"]);
|
||||
const version = versionRun.stdout.text.trim();
|
||||
if (versionRun.stdout.bytes > 1024)
|
||||
throw new AnalysisCapabilityUnavailableError(
|
||||
throw firmwareToolUnavailable(
|
||||
engineName,
|
||||
request.operation,
|
||||
`Tool version banner is ${String(versionRun.stdout.bytes)} bytes; expected a short ${engineName} version line.`,
|
||||
);
|
||||
const admitted = admitFirmwareVersion(engineName, version);
|
||||
if (admitted.status === "unsupported" || admitted.status === "unresolved")
|
||||
throw new AnalysisCapabilityUnavailableError(
|
||||
throw firmwareToolUnavailable(
|
||||
engineName,
|
||||
request.operation,
|
||||
admitted.message,
|
||||
|
||||
Reference in New Issue
Block a user