From 42817a1707709100983b19597f544b2fa9d1bd1c Mon Sep 17 00:00:00 2001 From: Gustavo Madeira Santana Date: Fri, 17 Apr 2026 12:49:44 -0400 Subject: [PATCH] Tests: isolate OAuth mirror external auth lookup Use the existing external auth test hook and a lightweight OAuth package mock so mirror-refresh coverage does not load provider runtime work while seeding test stores. --- .../auth-profiles/oauth.mirror-refresh.test.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/agents/auth-profiles/oauth.mirror-refresh.test.ts b/src/agents/auth-profiles/oauth.mirror-refresh.test.ts index 0f3d087f85b..a3531cd70ed 100644 --- a/src/agents/auth-profiles/oauth.mirror-refresh.test.ts +++ b/src/agents/auth-profiles/oauth.mirror-refresh.test.ts @@ -4,6 +4,7 @@ import path from "node:path"; import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import { resetFileLockStateForTest } from "../../infra/file-lock.js"; import { captureEnv } from "../../test-utils/env.js"; +import { __testing as externalAuthTesting } from "./external-auth.js"; import { clearRuntimeAuthProfileStoreSnapshots, ensureAuthProfileStore, @@ -35,6 +36,19 @@ vi.mock("../cli-credentials.js", () => ({ writeCodexCliCredentials: () => true, })); +vi.mock("@mariozechner/pi-ai/oauth", () => ({ + getOAuthProviders: () => [{ id: "anthropic" }, { id: "openai-codex" }], + getOAuthApiKey: vi.fn(async (provider: string, credentials: Record) => { + const credential = credentials[provider]; + return credential + ? { + apiKey: credential.access, + newCredentials: credential, + } + : null; + }), +})); + vi.mock("../../plugins/provider-runtime.runtime.js", () => ({ formatProviderAuthProfileApiKeyWithPlugin: (params: { context?: { access?: string } }) => formatProviderAuthProfileApiKeyWithPluginMock() ?? params?.context?.access, @@ -86,6 +100,7 @@ describe("resolveApiKeyForProfile OAuth refresh mirror-to-main (#26322)", () => refreshProviderOAuthCredentialWithPluginMock.mockResolvedValue(undefined); formatProviderAuthProfileApiKeyWithPluginMock.mockReset(); formatProviderAuthProfileApiKeyWithPluginMock.mockReturnValue(undefined); + externalAuthTesting.setResolveExternalAuthProfilesForTest(() => []); clearRuntimeAuthProfileStoreSnapshots(); tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-oauth-mirror-")); process.env.OPENCLAW_STATE_DIR = tempRoot; @@ -98,6 +113,7 @@ describe("resolveApiKeyForProfile OAuth refresh mirror-to-main (#26322)", () => afterEach(async () => { envSnapshot.restore(); resetFileLockStateForTest(); + externalAuthTesting.resetResolveExternalAuthProfilesForTest(); clearRuntimeAuthProfileStoreSnapshots(); if (resetOAuthRefreshQueuesForTest) { resetOAuthRefreshQueuesForTest();