From d3c6a8f0fb6d09904edd0848d6d88afba576db2a Mon Sep 17 00:00:00 2001 From: Shakker Date: Wed, 29 Apr 2026 21:57:21 +0100 Subject: [PATCH] fix: use agent auth store for model status probes --- .../models/list.probe.targets.test.ts | 61 ++++++++++++++++++- src/commands/models/list.probe.ts | 6 +- 2 files changed, 62 insertions(+), 5 deletions(-) diff --git a/src/commands/models/list.probe.targets.test.ts b/src/commands/models/list.probe.targets.test.ts index b3aabecc796..8449b23791e 100644 --- a/src/commands/models/list.probe.targets.test.ts +++ b/src/commands/models/list.probe.targets.test.ts @@ -4,6 +4,7 @@ import type { ModelCatalogEntry } from "../../agents/model-catalog.js"; import type { OpenClawConfig } from "../../config/config.js"; let mockStore: AuthProfileStore; +let mockAgentStore: AuthProfileStore | undefined; let mockAllowedProfiles: string[]; const loadModelCatalogMock = vi.fn<() => Promise>(async () => []); @@ -73,9 +74,10 @@ vi.mock("./shared.js", () => ({ })); vi.mock("../../agents/auth-profiles.js", () => ({ - ensureAuthProfileStore: () => mockStore, - listProfilesForProvider: (_store: AuthProfileStore, provider: string) => - Object.entries(mockStore.profiles) + ensureAuthProfileStore: (agentDir?: string) => + agentDir === "/tmp/coder-agent" && mockAgentStore ? mockAgentStore : mockStore, + listProfilesForProvider: (store: AuthProfileStore, provider: string) => + Object.entries(store.profiles) .filter( ([, profile]) => typeof profile.provider === "string" && profile.provider.toLowerCase() === provider, @@ -198,6 +200,7 @@ describe("buildProbeTargets reason codes", () => { anthropic: ["anthropic:default"], }, }; + mockAgentStore = undefined; mockAllowedProfiles = []; loadModelCatalogMock.mockReset(); loadModelCatalogMock.mockResolvedValue([]); @@ -378,4 +381,56 @@ describe("buildProbeTargets reason codes", () => { }), ); }); + + it("uses the requested agent auth store when building profile probe targets", async () => { + mockStore = { + version: 1, + profiles: {}, + order: {}, + }; + mockAgentStore = { + version: 1, + profiles: { + "anthropic:coder": { + type: "api_key", + provider: "anthropic", + key: "sk-ant-coder-profile", + }, + }, + order: {}, + }; + + const defaultPlan = await buildProbeTargets({ + cfg: {} as OpenClawConfig, + providers: ["anthropic"], + modelCandidates: ["anthropic/claude-sonnet-4-6"], + options: { + timeoutMs: 5_000, + concurrency: 1, + maxTokens: 16, + }, + }); + const agentPlan = await buildProbeTargets({ + cfg: {} as OpenClawConfig, + agentDir: "/tmp/coder-agent", + providers: ["anthropic"], + modelCandidates: ["anthropic/claude-sonnet-4-6"], + options: { + timeoutMs: 5_000, + concurrency: 1, + maxTokens: 16, + }, + }); + + expect(defaultPlan.targets).toEqual([]); + expect(agentPlan.results).toEqual([]); + expect(agentPlan.targets).toHaveLength(1); + expect(agentPlan.targets[0]).toEqual( + expect.objectContaining({ + provider: "anthropic", + profileId: "anthropic:coder", + source: "profile", + }), + ); + }); }); diff --git a/src/commands/models/list.probe.ts b/src/commands/models/list.probe.ts index 83c3f5380a6..1ebd9ae7f65 100644 --- a/src/commands/models/list.probe.ts +++ b/src/commands/models/list.probe.ts @@ -249,13 +249,14 @@ async function maybeResolveUnresolvedRefIssue(params: { export async function buildProbeTargets(params: { cfg: OpenClawConfig; + agentDir?: string; workspaceDir?: string; providers: string[]; modelCandidates: string[]; options: AuthProbeOptions; }): Promise<{ targets: AuthProbeTarget[]; results: AuthProbeResult[] }> { - const { cfg, providers, modelCandidates, options, workspaceDir } = params; - const store = ensureAuthProfileStore(); + const { cfg, agentDir, providers, modelCandidates, options, workspaceDir } = params; + const store = ensureAuthProfileStore(agentDir); const providerFilter = options.provider?.trim(); const providerFilterKey = providerFilter ? normalizeProviderId(providerFilter) : null; const profileFilter = new Set((options.profileIds ?? []).map((id) => id.trim()).filter(Boolean)); @@ -571,6 +572,7 @@ export async function runAuthProbes(params: { const startedAt = Date.now(); const plan = await buildProbeTargets({ cfg: params.cfg, + agentDir: params.agentDir, workspaceDir: params.workspaceDir, providers: params.providers, modelCandidates: params.modelCandidates,