mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-17 20:21:13 +00:00
test: speed up auth profile store tests
This commit is contained in:
@@ -10,6 +10,10 @@ import {
|
||||
import { AUTH_STORE_VERSION, log } from "./auth-profiles/constants.js";
|
||||
import type { AuthProfileCredential } from "./auth-profiles/types.js";
|
||||
|
||||
vi.mock("../plugins/provider-runtime.js", () => ({
|
||||
resolveExternalAuthProfilesWithPlugins: () => [],
|
||||
}));
|
||||
|
||||
describe("ensureAuthProfileStore", () => {
|
||||
function withTempAgentDir<T>(prefix: string, run: (agentDir: string) => T): T {
|
||||
const agentDir = fs.mkdtempSync(path.join(os.tmpdir(), prefix));
|
||||
|
||||
@@ -22,6 +22,10 @@ vi.mock("./auth-profiles/external-cli-sync.js", () => ({
|
||||
syncExternalCliCredentials: mocks.syncExternalCliCredentials,
|
||||
}));
|
||||
|
||||
vi.mock("../plugins/provider-runtime.js", () => ({
|
||||
resolveExternalAuthProfilesWithPlugins: () => [],
|
||||
}));
|
||||
|
||||
let clearRuntimeAuthProfileStoreSnapshots: typeof import("./auth-profiles.js").clearRuntimeAuthProfileStoreSnapshots;
|
||||
let loadAuthProfileStoreForRuntime: typeof import("./auth-profiles.js").loadAuthProfileStoreForRuntime;
|
||||
|
||||
|
||||
@@ -15,6 +15,10 @@ vi.mock("./auth-profiles/external-cli-sync.js", () => ({
|
||||
syncExternalCliCredentials: mocks.syncExternalCliCredentials,
|
||||
}));
|
||||
|
||||
vi.mock("../plugins/provider-runtime.js", () => ({
|
||||
resolveExternalAuthProfilesWithPlugins: () => [],
|
||||
}));
|
||||
|
||||
let clearRuntimeAuthProfileStoreSnapshots: typeof import("./auth-profiles.js").clearRuntimeAuthProfileStoreSnapshots;
|
||||
let ensureAuthProfileStore: typeof import("./auth-profiles.js").ensureAuthProfileStore;
|
||||
|
||||
|
||||
@@ -34,6 +34,10 @@ vi.mock("../../plugins/provider-runtime.runtime.js", () => ({
|
||||
refreshProviderOAuthCredentialWithPlugin: async () => null,
|
||||
}));
|
||||
|
||||
vi.mock("../plugins/provider-runtime.js", () => ({
|
||||
resolveExternalAuthProfilesWithPlugins: () => [],
|
||||
}));
|
||||
|
||||
let clearRuntimeAuthProfileStoreSnapshots: typeof import("./store.js").clearRuntimeAuthProfileStoreSnapshots;
|
||||
let ensureAuthProfileStore: typeof import("./store.js").ensureAuthProfileStore;
|
||||
let resolveApiKeyForProfile: typeof import("./oauth.js").resolveApiKeyForProfile;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { resetFileLockStateForTest } from "../../infra/file-lock.js";
|
||||
import { captureEnv } from "../../test-utils/env.js";
|
||||
import {
|
||||
@@ -66,10 +66,9 @@ vi.mock("../../plugins/provider-runtime.runtime.js", () => ({
|
||||
buildProviderAuthDoctorHintWithPlugin: buildProviderAuthDoctorHintWithPluginMock,
|
||||
}));
|
||||
|
||||
async function loadFreshOAuthModuleForTest() {
|
||||
vi.resetModules();
|
||||
({ resolveApiKeyForProfile } = await import("./oauth.js"));
|
||||
}
|
||||
vi.mock("../plugins/provider-runtime.js", () => ({
|
||||
resolveExternalAuthProfilesWithPlugins: () => [],
|
||||
}));
|
||||
|
||||
async function readPersistedStore(agentDir: string): Promise<AuthProfileStore> {
|
||||
return JSON.parse(
|
||||
@@ -105,6 +104,10 @@ describe("resolveApiKeyForProfile openai-codex refresh fallback", () => {
|
||||
let tempRoot = "";
|
||||
let agentDir = "";
|
||||
|
||||
beforeAll(async () => {
|
||||
({ resolveApiKeyForProfile } = await import("./oauth.js"));
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
resetFileLockStateForTest();
|
||||
getOAuthApiKeyMock.mockReset();
|
||||
@@ -128,7 +131,6 @@ describe("resolveApiKeyForProfile openai-codex refresh fallback", () => {
|
||||
process.env.OPENCLAW_STATE_DIR = tempRoot;
|
||||
process.env.OPENCLAW_AGENT_DIR = agentDir;
|
||||
process.env.PI_CODING_AGENT_DIR = agentDir;
|
||||
await loadFreshOAuthModuleForTest();
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
|
||||
Reference in New Issue
Block a user