Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions src/application/DirectAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,13 +560,8 @@ const analysisProfileForRoute = (
const providerIdentityForRoute = (
route: SessionProviderRoute,
operation: string,
): ProviderIdentity => {
const selected =
route.capabilities?.get(operation)?.provider ?? route.identity;
return route.profile?.provider.id === selected.id
? route.profile.provider
: selected;
};
): ProviderIdentity =>
route.capabilities?.get(operation)?.provider ?? route.identity;

const analysisProfileForEvidence = (
session: BinarySession,
Expand Down
13 changes: 11 additions & 2 deletions src/application/binary/AnalysisProviderRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export interface AnalysisProviderBinding {
readonly identity: ProviderIdentity & { readonly version: string };
readonly selectionSource: "request" | "environment" | "auto-single-candidate";
readonly profile: AnalysisProfileCommitment;
/** The provider's capabilities, attributed to its resolved identity. */
readonly capabilities: readonly CapabilityDescriptor[];
}

/** Complete result used for both a bound and intentionally unbound target. */
Expand Down Expand Up @@ -361,18 +363,25 @@ const selectedResult = (
},
statuses: readonly AnalysisProviderCandidateStatus[],
): AnalysisProviderSelection => {
const identity = evaluated.profile.provider;
const capabilities = evaluated.status.capabilities.map((capability) => ({
...capability,
provider: structuredClone(identity),
}));
const selectedStatus = {
...evaluated.status,
provider: structuredClone(evaluated.profile.provider),
provider: structuredClone(identity),
selected: true,
capabilities,
} satisfies AnalysisProviderCandidateStatus;
return {
requestedProviderId,
binding: {
provider: evaluated.candidate,
identity: structuredClone(evaluated.profile.provider),
identity: structuredClone(identity),
selectionSource: source,
profile: structuredClone(evaluated.profile),
capabilities,
},
candidates: replaceCandidate(statuses, selectedStatus),
};
Expand Down
9 changes: 1 addition & 8 deletions src/application/binary/BinarySession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,7 @@ export class BinarySession
}
}
}
const profile = this.#active?.profile;
return structuredClone(
profile !== null &&
profile !== undefined &&
profile.provider.id === selected.id
? profile.provider
: selected,
);
return structuredClone(selected);
}

/** External live state cannot be replayed by a direct or composed CLI workflow. */
Expand Down
6 changes: 5 additions & 1 deletion src/application/binary/SessionProviderRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@ const selectableRoute = (
? undefined
: new CompositeProvider(providers);
const identity = provider?.identity() ?? emptyProviderIdentity();
const capabilities = capabilityMap(provider?.capabilities() ?? []);
// The binding attributes deep-provider capabilities to the resolved version.
const capabilities = capabilityMap([
...auxiliaryProviders.flatMap((auxiliary) => auxiliary.capabilities()),
...(binding?.capabilities ?? []),
]);
return {
identity,
capabilities,
Expand Down
32 changes: 32 additions & 0 deletions tests/composition/analysis-sessions/providerBinding.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,38 @@ describe("target-bound provider routing", () => {
});
});

describe("selected provider capability provenance", () => {
it("labels selected-provider capabilities with the resolved identity", async () => {
const target = await databaseTarget();
const alpha = deepProvider("alpha");
const session = selectableSession([alpha.provider], auxiliaryProvider());

expect((await session.open(target, { providerId: "alpha" })).ok).toBe(true);
const resolved = { id: "alpha", name: "alpha provider", version: "1" };
const status = bindingStatus(session);
expect(status).toMatchObject({
analysis_provider_binding: { provider: resolved },
analysis_provider_candidates: [
{
provider: resolved,
selected: true,
capabilities: [{ provider: resolved }],
},
],
});
expect(
z
.object({ capabilities: z.array(z.object({ provider: z.unknown() })) })
.parse(status)
.capabilities.map(({ provider }) => provider),
).toEqual([
{ id: "alpha", name: "alpha provider", version: "1" },
{ id: "auxiliary", name: "auxiliary provider", version: "1" },
]);
await session.close();
});
});

interface ClientState {
readonly calls: string[];
closed: boolean;
Expand Down
Loading