mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 06:20:43 +00:00
fix: use agent auth store for model status probes
This commit is contained in:
@@ -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<ModelCatalogEntry[]>>(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",
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user