mirror of
https://github.com/morluto/rea
synced 2026-10-28 15:07:26 -04:00
fix(providers): report provider-selection diagnostics when the selected provider refuses its profile (#4103)
* fix(providers): report provider-selection diagnostics when the selected provider refuses its profile An explicitly selected provider that refuses the target during profile resolution now yields the target_unsupported selection error with its candidates and rejections, keeping the refusal's message and, when present, its specific recovery. Fixes #3930 * fix(providers): keep refusal evidence and cleanup ownership on selection failures A refusal with unconfirmed cleanup is returned unchanged; otherwise the selection failure carries the refusal's captured output, diagnostics, partial observation and cause. Registry tests cover the copied recovery and the cleanup guard.
This commit is contained in:
@@ -15,6 +15,7 @@ import { createAnalysisProfile } from "../../domain/analysisProfile.js";
|
||||
import type { BinaryTarget } from "../../domain/binaryTargetTypes.js";
|
||||
import { ProviderAdapterError } from "../../domain/providerAdapterError.js";
|
||||
import { ProviderCleanupError } from "../../domain/providerCleanupError.js";
|
||||
import { AnalysisUnsupportedTargetError } from "../../domain/analysisErrorCore.js";
|
||||
import { ProviderSelectionError } from "../../domain/providerSelectionError.js";
|
||||
import { projectAnalysisError } from "../../domain/analysisErrorProjection.js";
|
||||
import { AnalysisCancelledError } from "../../domain/analysisErrorCore.js";
|
||||
@@ -607,6 +608,73 @@ const capability = (provider: ProviderIdentity): CapabilityDescriptor => ({
|
||||
limitations: [],
|
||||
});
|
||||
|
||||
describe("analysis provider registry: explicit profile refusals", () => {
|
||||
const refusing = (refusal: AnalysisUnsupportedTargetError) => ({
|
||||
...candidate("ghidra").provider,
|
||||
resolveAnalysisProfile: () => Promise.resolve(err(refusal)),
|
||||
});
|
||||
|
||||
it("keeps a refusing provider's reason, recovery and evidence in the selection failure", async () => {
|
||||
const capturedOutput = {
|
||||
stdout: "",
|
||||
stderr: "x86-64 only",
|
||||
truncated: false,
|
||||
};
|
||||
const refusal = new AnalysisUnsupportedTargetError(
|
||||
"resolve_analysis_profile",
|
||||
DATABASE_TARGET.path,
|
||||
"The configured extension supports x86-64 only.",
|
||||
{
|
||||
remediationAction: "Omit the extension setting for this target.",
|
||||
capturedOutput,
|
||||
diagnostics: { extension: "fixture" },
|
||||
},
|
||||
);
|
||||
const selected = await new AnalysisProviderRegistry([
|
||||
refusing(refusal),
|
||||
]).select(DATABASE_TARGET, "ghidra");
|
||||
if (selected.ok) throw new Error("expected a profile refusal");
|
||||
expect(selected.error).toBeInstanceOf(ProviderSelectionError);
|
||||
expect(selected.error.cause).toBe(refusal);
|
||||
expect(projectAnalysisError(selected.error)).toMatchObject({
|
||||
code: "capability_unavailable",
|
||||
message: refusal.message,
|
||||
remediation: { action: "Omit the extension setting for this target." },
|
||||
details: {
|
||||
selection_reason: "target_unsupported",
|
||||
requested_provider_id: "ghidra",
|
||||
candidate_ids: ["ghidra"],
|
||||
rejections: [
|
||||
{
|
||||
provider_id: "ghidra",
|
||||
code: "target_format_unsupported",
|
||||
reason: "The configured extension supports x86-64 only.",
|
||||
},
|
||||
],
|
||||
captured_output: capturedOutput,
|
||||
diagnostics: { extension: "fixture" },
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("returns a refusal with unconfirmed cleanup unchanged", async () => {
|
||||
const refusal = new AnalysisUnsupportedTargetError(
|
||||
"resolve_analysis_profile",
|
||||
DATABASE_TARGET.path,
|
||||
"The configured extension supports x86-64 only.",
|
||||
{ cleanup: { reason: "probe close failed", resources: ["/tmp/probe"] } },
|
||||
);
|
||||
const selected = await new AnalysisProviderRegistry([
|
||||
refusing(refusal),
|
||||
]).select(DATABASE_TARGET, "ghidra");
|
||||
if (selected.ok) throw new Error("expected a profile refusal");
|
||||
expect(selected.error).toBe(refusal);
|
||||
expect(projectAnalysisError(selected.error)).toMatchObject({
|
||||
code: "cleanup_incomplete",
|
||||
details: { cleanup: "incomplete", resources: ["/tmp/probe"] },
|
||||
});
|
||||
});
|
||||
});
|
||||
describe("profile resolution terminal facts", () => {
|
||||
it.each([false, true])(
|
||||
"preserves a physical profile failure across late caller abort (throws: %s)",
|
||||
|
||||
@@ -14,10 +14,14 @@ import {
|
||||
} from "../../contracts/providerSelection.js";
|
||||
import type { AnalysisProfileCommitment } from "../../domain/analysisProfile.js";
|
||||
import type { BinaryTarget } from "../../domain/binaryTargetTypes.js";
|
||||
import { AnalysisCancelledError } from "../../domain/analysisErrorCore.js";
|
||||
import {
|
||||
AnalysisCancelledError,
|
||||
AnalysisUnsupportedTargetError,
|
||||
} from "../../domain/analysisErrorCore.js";
|
||||
import { AnalysisError } from "../../domain/analysisErrorBase.js";
|
||||
import {
|
||||
ProviderSelectionError,
|
||||
type ProviderSelectionErrorOptions,
|
||||
type ProviderSelectionFailureReason,
|
||||
type ProviderSelectionRejection,
|
||||
} from "../../domain/providerSelectionError.js";
|
||||
@@ -593,9 +597,29 @@ export class AnalysisProviderRegistry {
|
||||
);
|
||||
if (!evaluation.ok) return evaluation;
|
||||
const evaluated = evaluation.value;
|
||||
if (evaluated.profileError !== undefined)
|
||||
return err(evaluated.profileError);
|
||||
const statuses = replaceCandidate(baseline, evaluated.status);
|
||||
const refusal = evaluated.profileError;
|
||||
// A selected provider refusing the target is a selection outcome that keeps the
|
||||
// refusal's reason, recovery and evidence; unconfirmed cleanup stays with the refusal.
|
||||
if (
|
||||
refusal instanceof AnalysisUnsupportedTargetError &&
|
||||
!refusal.cleanupIncomplete
|
||||
)
|
||||
return err(
|
||||
selectionError("target_unsupported", providerId, statuses, {
|
||||
refusal: {
|
||||
userMessage: refusal.message,
|
||||
...(refusal.remediationAction === undefined
|
||||
? {}
|
||||
: { remediationAction: refusal.remediationAction }),
|
||||
capturedOutput: refusal.capturedOutput,
|
||||
diagnostics: refusal.diagnostics,
|
||||
partialObservation: refusal.partialObservation,
|
||||
cause: refusal,
|
||||
},
|
||||
}),
|
||||
);
|
||||
if (refusal !== undefined) return err(refusal);
|
||||
if (evaluated.profile === undefined)
|
||||
return err(selectionError("provider_unavailable", providerId, statuses));
|
||||
return ok(
|
||||
@@ -818,9 +842,19 @@ const selectionError = (
|
||||
options: {
|
||||
readonly operation?: string;
|
||||
readonly rejectionCandidates?: readonly AnalysisProviderCandidateStatus[];
|
||||
readonly refusal?: Pick<
|
||||
ProviderSelectionErrorOptions,
|
||||
| "userMessage"
|
||||
| "remediationAction"
|
||||
| "capturedOutput"
|
||||
| "diagnostics"
|
||||
| "partialObservation"
|
||||
| "cause"
|
||||
>;
|
||||
} = {},
|
||||
): ProviderSelectionError =>
|
||||
new ProviderSelectionError({
|
||||
...options.refusal,
|
||||
operation: options.operation ?? "open_binary",
|
||||
reason,
|
||||
requestedProviderId,
|
||||
|
||||
Reference in New Issue
Block a user