Skip to content

Commit 392c15a

Browse files
committed
fix: dedupe canonical providers in models status
1 parent ee72081 commit 392c15a

2 files changed

Lines changed: 50 additions & 4 deletions

File tree

‎src/commands/models/list.status-command.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { resolveEnvApiKey } from "../../agents/model-auth.js";
1919
import {
2020
buildModelAliasIndex,
2121
isCliProvider,
22+
normalizeProviderId,
2223
parseModelRef,
2324
resolveConfiguredModelRef,
2425
resolveDefaultModelForAgent,
@@ -119,26 +120,26 @@ export async function modelsStatusCommand(
119120

120121
const providersFromStore = new Set(
121122
Object.values(store.profiles)
122-
.map((profile) => profile.provider)
123+
.map((profile) => normalizeProviderId(profile.provider))
123124
.filter((p): p is string => Boolean(p)),
124125
);
125126
const providersFromConfig = new Set(
126127
Object.keys(cfg.models?.providers ?? {})
127-
.map((p) => (typeof p === "string" ? p.trim() : ""))
128+
.map((p) => (typeof p === "string" ? normalizeProviderId(p) : ""))
128129
.filter(Boolean),
129130
);
130131
const providersFromModels = new Set<string>();
131132
const providersInUse = new Set<string>();
132133
for (const raw of [defaultLabel, ...fallbacks, imageModel, ...imageFallbacks, ...allowed]) {
133134
const parsed = parseModelRef(String(raw ?? ""), DEFAULT_PROVIDER);
134135
if (parsed?.provider) {
135-
providersFromModels.add(parsed.provider);
136+
providersFromModels.add(normalizeProviderId(parsed.provider));
136137
}
137138
}
138139
for (const raw of [defaultLabel, ...fallbacks, imageModel, ...imageFallbacks]) {
139140
const parsed = parseModelRef(String(raw ?? ""), DEFAULT_PROVIDER);
140141
if (parsed?.provider) {
141-
providersInUse.add(parsed.provider);
142+
providersInUse.add(normalizeProviderId(parsed.provider));
142143
}
143144
}
144145

‎src/commands/models/list.status.test.ts‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,51 @@ describe("modelsStatusCommand auth overview", () => {
329329
}
330330
});
331331

332+
it("dedupes alias and canonical provider ids in auth provider summaries", async () => {
333+
const localRuntime = createRuntime();
334+
const originalLoadConfig = mocks.loadConfig.getMockImplementation();
335+
const originalResolveEnvApiKey = mocks.resolveEnvApiKey.getMockImplementation();
336+
337+
mocks.loadConfig.mockReturnValue({
338+
agents: {
339+
defaults: {
340+
model: { primary: "z.ai/glm-4.7", fallbacks: [] },
341+
models: { "z.ai/glm-4.7": {} },
342+
},
343+
},
344+
models: { providers: { "z.ai": {} } },
345+
env: { shellEnv: { enabled: true } },
346+
});
347+
mocks.resolveEnvApiKey.mockImplementation((provider: string) => {
348+
if (provider === "zai" || provider === "z.ai" || provider === "z-ai") {
349+
return {
350+
apiKey: "sk-zai-0123456789abcdefghijklmnopqrstuvwxyz", // pragma: allowlist secret
351+
source: "shell env: ZAI_API_KEY",
352+
};
353+
}
354+
return null;
355+
});
356+
357+
try {
358+
await modelsStatusCommand({ json: true }, localRuntime as never);
359+
const payload = JSON.parse(String((localRuntime.log as Mock).mock.calls[0]?.[0]));
360+
const providers = payload.auth.providers as Array<{ provider: string }>;
361+
expect(providers.filter((provider) => provider.provider === "zai")).toHaveLength(1);
362+
expect(providers.some((provider) => provider.provider === "z.ai")).toBe(false);
363+
} finally {
364+
if (originalLoadConfig) {
365+
mocks.loadConfig.mockImplementation(originalLoadConfig);
366+
}
367+
if (originalResolveEnvApiKey) {
368+
mocks.resolveEnvApiKey.mockImplementation(originalResolveEnvApiKey);
369+
} else if (defaultResolveEnvApiKeyImpl) {
370+
mocks.resolveEnvApiKey.mockImplementation(defaultResolveEnvApiKeyImpl);
371+
} else {
372+
mocks.resolveEnvApiKey.mockImplementation(() => null);
373+
}
374+
}
375+
});
376+
332377
it("labels defaults when --agent has no overrides", async () => {
333378
const localRuntime = createRuntime();
334379
await withAgentScopeOverrides(

0 commit comments

Comments
 (0)