diff --git a/src/agents/auth-profiles/oauth.fallback-to-main-agent.e2e.test.ts b/src/agents/auth-profiles/oauth.fallback-to-main-agent.e2e.test.ts index 0713d5c4c4c..ce745cdb051 100644 --- a/src/agents/auth-profiles/oauth.fallback-to-main-agent.e2e.test.ts +++ b/src/agents/auth-profiles/oauth.fallback-to-main-agent.e2e.test.ts @@ -38,6 +38,39 @@ describe("resolveApiKeyForProfile fallback to main agent", () => { await fs.rm(tmpDir, { recursive: true, force: true }); }); + async function resolveOauthProfileForConfiguredMode(mode: "token" | "api_key") { + const profileId = "anthropic:default"; + const store: AuthProfileStore = { + version: 1, + profiles: { + [profileId]: { + type: "oauth", + provider: "anthropic", + access: "oauth-token", + refresh: "refresh-token", + expires: Date.now() + 60_000, + }, + }, + }; + + const result = await resolveApiKeyForProfile({ + cfg: { + auth: { + profiles: { + [profileId]: { + provider: "anthropic", + mode, + }, + }, + }, + }, + store, + profileId, + }); + + return result; + } + it("falls back to main agent credentials when secondary agent token is expired and refresh fails", async () => { const profileId = "anthropic:claude-cli"; const now = Date.now(); @@ -216,34 +249,7 @@ describe("resolveApiKeyForProfile fallback to main agent", () => { }); it("accepts mode=token + type=oauth for legacy compatibility", async () => { - const profileId = "anthropic:default"; - const store: AuthProfileStore = { - version: 1, - profiles: { - [profileId]: { - type: "oauth", - provider: "anthropic", - access: "oauth-token", - refresh: "refresh-token", - expires: Date.now() + 60_000, - }, - }, - }; - - const result = await resolveApiKeyForProfile({ - cfg: { - auth: { - profiles: { - [profileId]: { - provider: "anthropic", - mode: "token", - }, - }, - }, - }, - store, - profileId, - }); + const result = await resolveOauthProfileForConfiguredMode("token"); expect(result?.apiKey).toBe("oauth-token"); }); @@ -281,34 +287,7 @@ describe("resolveApiKeyForProfile fallback to main agent", () => { }); it("rejects true mode/type mismatches", async () => { - const profileId = "anthropic:default"; - const store: AuthProfileStore = { - version: 1, - profiles: { - [profileId]: { - type: "oauth", - provider: "anthropic", - access: "oauth-token", - refresh: "refresh-token", - expires: Date.now() + 60_000, - }, - }, - }; - - const result = await resolveApiKeyForProfile({ - cfg: { - auth: { - profiles: { - [profileId]: { - provider: "anthropic", - mode: "api_key", - }, - }, - }, - }, - store, - profileId, - }); + const result = await resolveOauthProfileForConfiguredMode("api_key"); expect(result).toBeNull(); });