test(auth): isolate provider alias registry mock

This commit is contained in:
Peter Steinberger
2026-04-17 18:09:28 +01:00
parent f93b7da4c4
commit 1519b006b8

View File

@@ -1,9 +1,7 @@
import { mkdtemp, rm } from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { resolveAuthProfileOrder } from "./order.js";
import { markAuthProfileGood } from "./profiles.js";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { saveAuthProfileStore } from "./store.js";
import type { AuthProfileStore } from "./types.js";
@@ -28,12 +26,30 @@ vi.mock("./external-auth.js", () => ({
shouldPersistExternalAuthProfile: () => true,
}));
async function importAuthProfileModulesWithAliasRegistry() {
vi.resetModules();
vi.doMock("../../plugins/manifest-registry.js", () => ({
loadPluginManifestRegistry,
}));
const [{ resolveAuthProfileOrder }, { markAuthProfileGood }] = await Promise.all([
import("./order.js"),
import("./profiles.js"),
]);
return { markAuthProfileGood, resolveAuthProfileOrder };
}
describe("resolveAuthProfileOrder", () => {
beforeEach(() => {
loadPluginManifestRegistry.mockClear();
});
it("accepts aliased provider credentials from manifest metadata", () => {
afterEach(() => {
vi.doUnmock("../../plugins/manifest-registry.js");
vi.resetModules();
});
it("accepts aliased provider credentials from manifest metadata", async () => {
const { resolveAuthProfileOrder } = await importAuthProfileModulesWithAliasRegistry();
const store: AuthProfileStore = {
version: 1,
profiles: {
@@ -54,6 +70,7 @@ describe("resolveAuthProfileOrder", () => {
});
it("marks aliased provider profiles good under the canonical auth provider", async () => {
const { markAuthProfileGood } = await importAuthProfileModulesWithAliasRegistry();
const agentDir = await mkdtemp(path.join(os.tmpdir(), "openclaw-auth-profile-alias-"));
try {
const store: AuthProfileStore = {