fix: keep model list synthetic auth refs exact

This commit is contained in:
Shakker
2026-04-29 17:59:00 +01:00
parent fceaecd123
commit 1df1ee48c0
2 changed files with 25 additions and 2 deletions

View File

@@ -144,6 +144,18 @@ describe("createModelListAuthIndex", () => {
expect(index.hasProviderAuth("codex")).toBe(true);
});
it("keeps synthetic auth refs exact instead of applying auth-choice aliases", () => {
const index = createModelListAuthIndex({
cfg: {},
authStore: emptyStore,
env: {},
syntheticAuthProviderRefs: ["claude-cli"],
});
expect(index.hasProviderAuth("claude-cli")).toBe(true);
expect(index.hasProviderAuth("anthropic")).toBe(false);
});
it("ignores derived synthetic auth snapshots", () => {
pluginRegistryMocks.loadPluginRegistrySnapshotWithMetadata.mockReturnValueOnce({
source: "derived",

View File

@@ -57,12 +57,20 @@ export function createModelListAuthIndex(
const aliasMap = resolveProviderAuthAliasMap({ config: params.cfg, env });
const envCandidateMap = resolveProviderEnvApiKeyCandidates({ config: params.cfg, env });
const authenticatedProviders = new Set<string>();
const syntheticAuthProviders = new Set<string>();
const addProvider = (provider: string | undefined) => {
if (!provider?.trim()) {
return;
}
authenticatedProviders.add(normalizeAuthProvider(provider, aliasMap));
};
const addSyntheticProvider = (provider: string | undefined) => {
const normalized = provider?.trim() ? normalizeProviderIdForAuth(provider) : "";
if (!normalized) {
return;
}
syntheticAuthProviders.add(normalized);
};
for (const credential of Object.values(params.authStore.profiles ?? {})) {
addProvider(credential.provider);
@@ -94,12 +102,15 @@ export function createModelListAuthIndex(
for (const provider of params.syntheticAuthProviderRefs ??
listValidatedSyntheticAuthProviderRefs({ cfg: params.cfg, env })) {
addProvider(provider);
addSyntheticProvider(provider);
}
return {
hasProviderAuth(provider: string): boolean {
return authenticatedProviders.has(normalizeAuthProvider(provider, aliasMap));
return (
authenticatedProviders.has(normalizeAuthProvider(provider, aliasMap)) ||
syntheticAuthProviders.has(normalizeProviderIdForAuth(provider))
);
},
};
}