Provider usage: narrow auth store before profile lookup

This commit is contained in:
Peter Steinberger
2026-04-07 15:34:11 +01:00
parent 17a8c896a4
commit 6fe93b55cb
2 changed files with 4 additions and 3 deletions

View File

@@ -9,7 +9,7 @@ const ensureAuthProfileStoreMock = vi.fn(() => ({
vi.mock("../agents/auth-profiles.js", () => ({
dedupeProfileIds: (profileIds: string[]) => [...new Set(profileIds)],
ensureAuthProfileStore: (...args: unknown[]) => ensureAuthProfileStoreMock(...args),
ensureAuthProfileStore: () => ensureAuthProfileStoreMock(),
listProfilesForProvider: () => [],
resolveApiKeyForProfile: async () => null,
resolveAuthProfileOrder: () => [],

View File

@@ -92,15 +92,16 @@ async function resolveOAuthToken(params: {
state: UsageAuthState;
provider: string;
}): Promise<ProviderAuth | null> {
const store = resolveUsageAuthStore(params.state);
const order = resolveAuthProfileOrder({
cfg: params.state.cfg,
store: resolveUsageAuthStore(params.state),
store,
provider: params.provider,
});
const deduped = dedupeProfileIds(order);
for (const profileId of deduped) {
const cred = params.state.store.profiles[profileId];
const cred = store.profiles[profileId];
if (!cred || (cred.type !== "oauth" && cred.type !== "token")) {
continue;
}