mirror of
https://github.com/morluto/rea.git
synced 2026-11-21 06:04:03 +00:00
feat(cli): expose provider selection diagnostics in session status (#9603)
* feat(cli): expose provider selection diagnostics in session status The registry now records how each deep provider became selected and why a candidate was rejected, but the session status projection dropped both fields. CLI providers/capabilities and MCP binary_session therefore showed a candidate list that could not explain an automatic or explicit choice, so users had to re-derive the reason from prose in selection errors. Project selection_source and rejections for every candidate. Complete detail keeps the rejection remediation and diagnostics; summary keeps the stable origin, code and reason and lists the dropped fields in omitted_fields. Existing candidate fields are unchanged, so both projections stay additive. * test(javascript): distinguish package scope in route fixtures * test(apple): separate identity and refusal fixture groups * fix(session): preserve binding source in refreshed candidates --------- Co-authored-by: 2SinceJuly <202121119+2SinceJuly@users.noreply.github.com> Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
8 files changed
+366
-77
No files matched your search
@@ -87,6 +87,9 @@ it.each([false, true])(
|
||||
analysis_provider_binding: {
|
||||
selection_source: "auto-single-candidate",
|
||||
},
|
||||
analysis_provider_candidates: [
|
||||
{ selected: true, selection_source: "auto-single-candidate" },
|
||||
],
|
||||
});
|
||||
expect((await session.execute("list_strings", {})).ok).toBe(true);
|
||||
expect(starts).toEqual([0, 1]);
|
||||
|
||||
@@ -672,43 +672,59 @@ it("keeps host unavailability ahead of target applicability", async () => {
|
||||
]);
|
||||
});
|
||||
|
||||
/** A rejected candidate whose diagnostic text must not reach the summary. */
|
||||
const unavailableReport = {
|
||||
provider: providerB,
|
||||
status: {
|
||||
code: "not_configured" as const,
|
||||
reason: "PROVIDER_B_HOME is not set.",
|
||||
remediation: "Set PROVIDER_B_HOME; see docs/provider-b.md.",
|
||||
},
|
||||
support: {
|
||||
code: "architecture_unsupported" as const,
|
||||
reason: "Provider B cannot select this slice.",
|
||||
},
|
||||
};
|
||||
const rejectedCandidate = (
|
||||
report: typeof unavailableReport,
|
||||
): AnalysisProviderCandidateStatus => ({
|
||||
...candidate(providerB, otherCapabilities),
|
||||
availability: {
|
||||
status: "unavailable",
|
||||
code: report.status.code,
|
||||
reason: report.status.reason,
|
||||
remediation: report.status.remediation,
|
||||
diagnostics: { checks: [{ name: "configuration", ok: false }] },
|
||||
},
|
||||
targetSupport: {
|
||||
status: "unsupported",
|
||||
code: report.support.code,
|
||||
reason: report.support.reason,
|
||||
diagnostics: { architecture: "arm64" },
|
||||
},
|
||||
selected: false,
|
||||
selectionSource: null,
|
||||
rejections: [
|
||||
{
|
||||
providerId: providerB.id,
|
||||
origin: "availability",
|
||||
code: report.status.code,
|
||||
reason: report.status.reason,
|
||||
remediation: report.status.remediation,
|
||||
diagnostics: { checks: [{ name: "configuration", ok: false }] },
|
||||
},
|
||||
{
|
||||
providerId: providerB.id,
|
||||
origin: "target",
|
||||
code: report.support.code,
|
||||
reason: report.support.reason,
|
||||
diagnostics: { architecture: "arm64" },
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
describe("binary session summary projection", () => {
|
||||
it("keeps each candidate's status, code and reason in summary without diagnostics or capability sets", async () => {
|
||||
const unavailable: AnalysisProviderCandidateStatus = {
|
||||
...candidate(providerB, otherCapabilities),
|
||||
availability: {
|
||||
status: "unavailable",
|
||||
code: "not_configured",
|
||||
reason: "PROVIDER_B_HOME is not set.",
|
||||
remediation: "Set PROVIDER_B_HOME; see docs/provider-b.md.",
|
||||
diagnostics: { checks: [{ name: "configuration", ok: false }] },
|
||||
},
|
||||
targetSupport: {
|
||||
status: "unsupported",
|
||||
code: "architecture_unsupported",
|
||||
reason: "Provider B cannot select this slice.",
|
||||
diagnostics: { architecture: "arm64" },
|
||||
},
|
||||
selected: false,
|
||||
selectionSource: null,
|
||||
rejections: [
|
||||
{
|
||||
providerId: providerB.id,
|
||||
origin: "availability",
|
||||
code: "not_configured",
|
||||
reason: "PROVIDER_B_HOME is not set.",
|
||||
remediation: "Set PROVIDER_B_HOME; see docs/provider-b.md.",
|
||||
diagnostics: { checks: [{ name: "configuration", ok: false }] },
|
||||
},
|
||||
{
|
||||
providerId: providerB.id,
|
||||
origin: "target",
|
||||
code: "architecture_unsupported",
|
||||
reason: "Provider B cannot select this slice.",
|
||||
diagnostics: { architecture: "arm64" },
|
||||
},
|
||||
],
|
||||
};
|
||||
const pending: AnalysisProviderCandidateStatus = {
|
||||
...candidate(providerA, selectedCapabilities),
|
||||
availability: {
|
||||
@@ -718,7 +734,7 @@ describe("binary session summary projection", () => {
|
||||
diagnostics: { startup: "pending" },
|
||||
},
|
||||
};
|
||||
const candidates = [pending, unavailable];
|
||||
const candidates = [pending, rejectedCandidate(unavailableReport)];
|
||||
const before = structuredClone(candidates);
|
||||
const runtimeUnavailability = new Map([
|
||||
["procedure_info", { reason: "Runtime operation failure" }],
|
||||
@@ -733,6 +749,7 @@ describe("binary session summary projection", () => {
|
||||
detail: "summary",
|
||||
});
|
||||
const summary = summaryStatusSchema.parse(raw);
|
||||
const { status, support } = unavailableReport;
|
||||
|
||||
expect(candidates).toEqual(before);
|
||||
expect(summary.capabilities).toEqual(complete.capabilities);
|
||||
@@ -750,30 +767,72 @@ describe("binary session summary projection", () => {
|
||||
reason: "No target is open.",
|
||||
},
|
||||
selected: true,
|
||||
selection_source: "auto-single-candidate",
|
||||
rejections: [],
|
||||
},
|
||||
{
|
||||
provider: providerB,
|
||||
availability: {
|
||||
status: "unavailable",
|
||||
code: "not_configured",
|
||||
reason: "PROVIDER_B_HOME is not set.",
|
||||
code: status.code,
|
||||
reason: status.reason,
|
||||
},
|
||||
target_support: {
|
||||
status: "unsupported",
|
||||
code: "architecture_unsupported",
|
||||
reason: "Provider B cannot select this slice.",
|
||||
code: support.code,
|
||||
reason: support.reason,
|
||||
},
|
||||
selected: false,
|
||||
selection_source: null,
|
||||
rejections: [
|
||||
{
|
||||
provider_id: providerB.id,
|
||||
origin: "availability",
|
||||
code: status.code,
|
||||
reason: status.reason,
|
||||
},
|
||||
{
|
||||
provider_id: providerB.id,
|
||||
origin: "target",
|
||||
code: support.code,
|
||||
reason: support.reason,
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
||||
expect(JSON.stringify(raw)).not.toContain("diagnostics");
|
||||
// Complete detail keeps the owner's repair copy on each rejection.
|
||||
expect(complete.analysis_provider_candidates[1]?.rejections).toEqual([
|
||||
{
|
||||
provider_id: providerB.id,
|
||||
origin: "availability",
|
||||
code: status.code,
|
||||
reason: status.reason,
|
||||
remediation: status.remediation,
|
||||
diagnostics: { checks: [{ name: "configuration", ok: false }] },
|
||||
},
|
||||
{
|
||||
provider_id: providerB.id,
|
||||
origin: "target",
|
||||
code: support.code,
|
||||
reason: support.reason,
|
||||
diagnostics: { architecture: "arm64" },
|
||||
},
|
||||
]);
|
||||
// Complete detail keeps the owner's repair; summary omits it.
|
||||
expect(
|
||||
complete.analysis_provider_candidates[1]?.availability,
|
||||
).toMatchObject({
|
||||
remediation: "Set PROVIDER_B_HOME; see docs/provider-b.md.",
|
||||
});
|
||||
).toMatchObject({ remediation: status.remediation });
|
||||
expect(JSON.stringify(raw)).not.toContain("PROVIDER_B_HOME;");
|
||||
// Summary keeps every rejection code and reason but never its repair text.
|
||||
expect(
|
||||
summary.analysis_provider_candidates[1]?.rejections.map(
|
||||
({ origin, code, reason }) => ({ origin, code, reason }),
|
||||
),
|
||||
).toEqual([
|
||||
{ origin: "availability", code: status.code, reason: status.reason },
|
||||
{ origin: "target", code: support.code, reason: support.reason },
|
||||
]);
|
||||
expect(
|
||||
analysisProviderCandidate
|
||||
.array()
|
||||
|
||||
@@ -27,6 +27,7 @@ import type {
|
||||
import { compareUnicodeCodePoints } from "../../domain/unicodeCodePointOrder.js";
|
||||
import type { BinarySessionDetail } from "../../contracts/sessionStatusContract.js";
|
||||
import type { AnalysisCleanupRetry } from "../../domain/analysisErrorRecovery.js";
|
||||
import type { ProviderSelectionRejection } from "../../domain/providerSelectionError.js";
|
||||
|
||||
interface BinarySessionStatusInput {
|
||||
readonly investigation: InvestigationStatistics;
|
||||
@@ -134,12 +135,16 @@ export const binarySessionStatus = async ({
|
||||
availability: providerStateSummary(candidate.availability),
|
||||
target_support: providerStateSummary(candidate.targetSupport),
|
||||
selected: candidate.selected,
|
||||
selection_source: candidate.selectionSource,
|
||||
rejections: candidate.rejections.map(rejectionSummary),
|
||||
}
|
||||
: {
|
||||
provider: providerSummary(candidate.provider),
|
||||
availability: structuredClone(candidate.availability),
|
||||
target_support: structuredClone(candidate.targetSupport),
|
||||
selected: candidate.selected,
|
||||
selection_source: candidate.selectionSource,
|
||||
rejections: candidate.rejections.map(selectionRejection),
|
||||
capabilities: providerCapabilitySets(
|
||||
candidate.capabilities
|
||||
.slice()
|
||||
@@ -323,6 +328,36 @@ const providerSummary = ({
|
||||
readonly version: string | null;
|
||||
}) => ({ id, name, version });
|
||||
|
||||
/** Carry every rejection fact at complete detail; clones keep the caller's copy immutable. */
|
||||
const selectionRejection = ({
|
||||
providerId,
|
||||
origin,
|
||||
code,
|
||||
reason,
|
||||
remediation,
|
||||
diagnostics,
|
||||
}: ProviderSelectionRejection) => ({
|
||||
provider_id: providerId,
|
||||
origin,
|
||||
code,
|
||||
reason,
|
||||
...(remediation === undefined ? {} : { remediation }),
|
||||
diagnostics: structuredClone(diagnostics),
|
||||
});
|
||||
|
||||
/** Rejection codes and reasons stay at summary detail; repair and diagnostics do not. */
|
||||
const rejectionSummary = ({
|
||||
providerId,
|
||||
origin,
|
||||
code,
|
||||
reason,
|
||||
}: ProviderSelectionRejection) => ({
|
||||
provider_id: providerId,
|
||||
origin,
|
||||
code,
|
||||
reason,
|
||||
});
|
||||
|
||||
const processLineageStatus = (
|
||||
snapshots: readonly ProviderRuntimeLineageSnapshot[],
|
||||
) =>
|
||||
|
||||
@@ -139,23 +139,27 @@ export class SessionProviderRouter {
|
||||
} = {},
|
||||
): Promise<readonly AnalysisProviderCandidateStatus[]> {
|
||||
const { signal, target, refresh = false } = options;
|
||||
if (refresh && route.selection !== undefined) {
|
||||
const current = await this.registry.candidates(
|
||||
target,
|
||||
signal === undefined ? {} : { signal },
|
||||
);
|
||||
return current.map((candidate) => ({
|
||||
const candidates =
|
||||
refresh && route.selection !== undefined
|
||||
? await this.registry.candidates(
|
||||
target,
|
||||
signal === undefined ? {} : { signal },
|
||||
)
|
||||
: (route.selection?.candidates ??
|
||||
(await this.registry.candidates(
|
||||
undefined,
|
||||
signal === undefined ? {} : { signal },
|
||||
)));
|
||||
const binding = route.binding;
|
||||
if (binding === null) return candidates;
|
||||
return candidates.map((candidate) => {
|
||||
const selected = candidate.provider.id === binding.identity.id;
|
||||
return {
|
||||
...candidate,
|
||||
selected: candidate.provider.id === route.binding?.identity.id,
|
||||
}));
|
||||
}
|
||||
return (
|
||||
route.selection?.candidates ??
|
||||
this.registry.candidates(
|
||||
undefined,
|
||||
signal === undefined ? {} : { signal },
|
||||
)
|
||||
);
|
||||
selected,
|
||||
selectionSource: selected ? binding.selectionSource : null,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/** Produce exact candidate rejections for an intentionally unbound route. */
|
||||
|
||||
Reference in new issue
Block a user