From a4a34edd219447375e368464ac5d62845c1609df Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 18 Apr 2026 22:52:32 +0100 Subject: [PATCH] test: reuse codex refresh helpers --- ...auth.openai-codex-refresh-fallback.test.ts | 49 +++++++++---------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/src/agents/auth-profiles/oauth.openai-codex-refresh-fallback.test.ts b/src/agents/auth-profiles/oauth.openai-codex-refresh-fallback.test.ts index 47606896fe6..0243f73020b 100644 --- a/src/agents/auth-profiles/oauth.openai-codex-refresh-fallback.test.ts +++ b/src/agents/auth-profiles/oauth.openai-codex-refresh-fallback.test.ts @@ -78,6 +78,25 @@ async function readPersistedStore(agentDir: string): Promise { ) as AuthProfileStore; } +function mockRotatedOpenAICodexRefresh() { + refreshProviderOAuthCredentialWithPluginMock.mockResolvedValueOnce({ + type: "oauth", + provider: "openai-codex", + access: "rotated-access-token", + refresh: "rotated-refresh-token", + expires: Date.now() + 86_400_000, + accountId: "acct-rotated", + }); +} + +function resolveOpenAICodexProfile(params: { profileId: string; agentDir: string }) { + return resolveApiKeyForProfile({ + store: ensureAuthProfileStore(params.agentDir), + profileId: params.profileId, + agentDir: params.agentDir, + }); +} + describe("resolveApiKeyForProfile openai-codex refresh fallback", () => { const envSnapshot = captureEnv(OAUTH_AGENT_ENV_KEYS); let tempRoot = ""; @@ -168,20 +187,9 @@ describe("resolveApiKeyForProfile openai-codex refresh fallback", () => { }, agentDir, ); - refreshProviderOAuthCredentialWithPluginMock.mockResolvedValueOnce({ - type: "oauth", - provider: "openai-codex", - access: "rotated-access-token", - refresh: "rotated-refresh-token", - expires: Date.now() + 86_400_000, - accountId: "acct-rotated", - }); + mockRotatedOpenAICodexRefresh(); - const result = await resolveApiKeyForProfile({ - store: ensureAuthProfileStore(agentDir), - profileId, - agentDir, - }); + const result = await resolveOpenAICodexProfile({ profileId, agentDir }); expect(result).toEqual({ apiKey: "rotated-access-token", @@ -201,20 +209,9 @@ describe("resolveApiKeyForProfile openai-codex refresh fallback", () => { }), agentDir, ); - refreshProviderOAuthCredentialWithPluginMock.mockResolvedValueOnce({ - type: "oauth", - provider: "openai-codex", - access: "rotated-access-token", - refresh: "rotated-refresh-token", - expires: Date.now() + 86_400_000, - accountId: "acct-rotated", - }); + mockRotatedOpenAICodexRefresh(); - const result = await resolveApiKeyForProfile({ - store: ensureAuthProfileStore(agentDir), - profileId, - agentDir, - }); + const result = await resolveOpenAICodexProfile({ profileId, agentDir }); expect(result).toEqual({ apiKey: "rotated-access-token",