Skip to content

armgit / rea

Public Imported from GitHub
0

Reverse engineer anything with agents, from app behavior down to native binaries.

fix(providers): offer only admitted ambiguity choices

morlutocec8f1e8f305
diff --git a/src/application/binary/AnalysisProviderRegistry.test.ts b/src/application/binary/AnalysisProviderRegistry.test.ts
index 60089a936..bd258f370 100644
--- a/src/application/binary/AnalysisProviderRegistry.test.ts
+++ b/src/application/binary/AnalysisProviderRegistry.test.ts
@@ -229,6 +229,51 @@ describe("inspection without deep binding", () => {
});
describe("analysis provider registry: selection failures", () => {
+ it("offers only admitted providers for ambiguous automatic selection", async () => {
+ const alpha = candidate("alpha");
+ const beta = candidate("beta");
+ const ghidra = candidate("ghidra", {
+ available: false,
+ unconfigured: true,
+ });
+ const kuna = candidate("kuna", {
+ available: false,
+ unconfigured: true,
+ });
+ const registry = new AnalysisProviderRegistry([
+ alpha.provider,
+ beta.provider,
+ ghidra.provider,
+ kuna.provider,
+ ]);
+
+ const ambiguous = await registry.select(DATABASE_TARGET);
+ expect(ambiguous.ok).toBe(false);
+ if (!ambiguous.ok)
+ expect(projectAnalysisError(ambiguous.error)).toMatchObject({
+ details: {
+ selection_reason: "ambiguous",
+ candidate_ids: ["alpha", "beta"],
+ rejections: [
+ { provider_id: "ghidra", code: "not_configured" },
+ { provider_id: "kuna", code: "not_configured" },
+ ],
+ },
+ });
+
+ for (const selected of [
+ await registry.select(DATABASE_TARGET, "alpha"),
+ await registry.select(DATABASE_TARGET, "beta"),
+ ])
+ expect(selected).toMatchObject({ ok: true });
+ expect([
+ ...alpha.created,
+ ...beta.created,
+ ...ghidra.created,
+ ...kuna.created,
+ ]).toEqual([]);
+ });
+
it("returns actionable unknown, unavailable, and unsupported failures", async () => {
const unavailable = candidate("alpha", { available: false });
const registry = new AnalysisProviderRegistry([unavailable.provider]);
@@ -465,6 +510,7 @@ const candidate = (
id: string,
options: {
readonly available?: boolean;
+ readonly unconfigured?: boolean;
readonly profile?: "resolved" | "missing" | "error";
} = {},
): CandidateFixture => {
@@ -488,7 +534,7 @@ const candidate = (
}
: {
status: "unavailable",
- code: "runtime_missing",
+ code: options.unconfigured ? "not_configured" : "runtime_missing",
reason: `${id} runtime is unavailable`,
diagnostics: { executable_path: `/opt/${id}/bin/analyze` },
},
diff --git a/src/application/binary/AnalysisProviderRegistry.ts b/src/application/binary/AnalysisProviderRegistry.ts
index 1e4291f75..a2ddae0d0 100644
--- a/src/application/binary/AnalysisProviderRegistry.ts
+++ b/src/application/binary/AnalysisProviderRegistry.ts
@@ -534,7 +534,9 @@ export class AnalysisProviderRegistry {
reason,
selection.requestedProviderId,
selection.candidates,
- operation,
+ {
+ operation,
+ },
);
}
@@ -652,7 +654,14 @@ export class AnalysisProviderRegistry {
candidates: statuses,
});
if (usable.length > 1)
- return err(selectionError("ambiguous", "auto", statuses));
+ return err(
+ selectionError(
+ "ambiguous",
+ "auto",
+ usable.map(({ status }) => status),
+ { rejectionCandidates: statuses },
+ ),
+ );
const selected = usable[0];
if (selected === undefined)
throw new TypeError("Usable provider selection disappeared");
@@ -757,15 +766,20 @@ const replaceCandidate = (
const selectionError = (
reason: ProviderSelectionFailureReason,
requestedProviderId: string,
- candidates: readonly AnalysisProviderCandidateStatus[],
- operation = "open_binary",
+ candidateChoices: readonly AnalysisProviderCandidateStatus[],
+ options: {
+ readonly operation?: string;
+ readonly rejectionCandidates?: readonly AnalysisProviderCandidateStatus[];
+ } = {},
): ProviderSelectionError =>
new ProviderSelectionError({
- operation,
+ operation: options.operation ?? "open_binary",
reason,
requestedProviderId,
- candidateIds: candidates.map(({ provider }) => provider.id),
- rejections: candidateRejections(candidates),
+ candidateIds: candidateChoices.map(({ provider }) => provider.id),
+ rejections: candidateRejections(
+ options.rejectionCandidates ?? candidateChoices,
+ ),
});
const candidateRejections = (
diff --git a/tests/boundary/mcp/providerSelectionMcp.test.ts b/tests/boundary/mcp/providerSelectionMcp.test.ts
index 520bcd671..df484959d 100644
--- a/tests/boundary/mcp/providerSelectionMcp.test.ts
+++ b/tests/boundary/mcp/providerSelectionMcp.test.ts
@@ -169,7 +169,76 @@ describe("provider selection over MCP", () => {
});
});
-const candidate = (id: string, starts: string[]): AnalysisProviderCandidate => {
+it("offers admitted providers and retains unconfigured rejections", async () => {
+ directory = await createTestTempDirectory("rea-provider-mcp-mixed-");
+ const target = join(directory, "fixture.hop");
+ await writeFile(target, "fixture");
+ const starts: string[] = [];
+ const session = composeBinarySession(
+ new AnalysisProviderRegistry([
+ candidate("beta", starts),
+ candidate("ghidra", starts, false),
+ candidate("alpha", starts),
+ candidate("kuna", starts, false),
+ ]),
+ );
+ const server = createServer(
+ { kind: "session", session },
+ { logger: silentLogger },
+ );
+ const mcp = new Client({ name: "provider-selection", version: "1.0.0" });
+ const [clientTransport, serverTransport] =
+ InMemoryTransport.createLinkedPair();
+ resources.push(mcp, server);
+ await server.connect(serverTransport);
+ await mcp.connect(clientTransport);
+
+ const ambiguous = await mcp.callTool({
+ name: "open_binary",
+ arguments: { path: target },
+ });
+ expect(ambiguous.isError).toBe(true);
+ expect(structured(ambiguous)).toMatchObject({
+ error: {
+ code: "capability_unavailable",
+ details: {
+ selection_reason: "ambiguous",
+ candidate_ids: ["alpha", "beta"],
+ rejections: [
+ { provider_id: "ghidra", code: "not_configured" },
+ { provider_id: "kuna", code: "not_configured" },
+ ],
+ },
+ },
+ });
+ expect(starts).toEqual([]);
+
+ const retried = await mcp.callTool({
+ name: "open_binary",
+ arguments: { path: target, provider_id: "alpha" },
+ });
+ expect(retried.isError).not.toBe(true);
+ expect(
+ structured(
+ await mcp.callTool({
+ name: "binary_session",
+ arguments: {},
+ }),
+ ).result,
+ ).toMatchObject({
+ analysis_provider_binding: {
+ provider: { id: "alpha", version: "1" },
+ selection_source: "request",
+ },
+ });
+ expect(starts).toEqual([]);
+});
+
+const candidate = (
+ id: string,
+ starts: string[],
+ available = true,
+): AnalysisProviderCandidate => {
const identity: ProviderIdentity = {
id,
name: `${id} provider`,
@@ -178,12 +247,20 @@ const candidate = (id: string, starts: string[]): AnalysisProviderCandidate => {
return {
identity: () => identity,
capabilities: () => [capability(identity)],
- inspectAvailability: () => ({
- status: "available",
- code: null,
- reason: null,
- diagnostics: { executable_path: `/opt/${id}/bin/analyze` },
- }),
+ inspectAvailability: () =>
+ available
+ ? {
+ status: "available",
+ code: null,
+ reason: null,
+ diagnostics: { executable_path: `/opt/${id}/bin/analyze` },
+ }
+ : {
+ status: "unavailable",
+ code: "not_configured",
+ reason: `${id} is not configured`,
+ diagnostics: {},
+ },
inspectTargetSupport: () => ({
status: "supported",
code: null,