mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-24 23:51:48 +00:00
84 lines
2.1 KiB
TypeScript
84 lines
2.1 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
type AuthProfileStore,
|
|
resolveAuthProfileOrder,
|
|
} from "./auth-profiles.js";
|
|
|
|
describe("resolveAuthProfileOrder", () => {
|
|
const store: AuthProfileStore = {
|
|
version: 1,
|
|
profiles: {
|
|
"anthropic:default": {
|
|
type: "api_key",
|
|
provider: "anthropic",
|
|
key: "sk-default",
|
|
},
|
|
"anthropic:work": {
|
|
type: "api_key",
|
|
provider: "anthropic",
|
|
key: "sk-work",
|
|
},
|
|
},
|
|
};
|
|
const cfg = {
|
|
auth: {
|
|
profiles: {
|
|
"anthropic:default": { provider: "anthropic", mode: "api_key" },
|
|
"anthropic:work": { provider: "anthropic", mode: "api_key" },
|
|
},
|
|
},
|
|
};
|
|
|
|
it("returns empty order without explicit config", () => {
|
|
const order = resolveAuthProfileOrder({
|
|
store,
|
|
provider: "anthropic",
|
|
});
|
|
expect(order).toEqual([]);
|
|
});
|
|
|
|
it("prioritizes preferred profiles", () => {
|
|
const order = resolveAuthProfileOrder({
|
|
cfg,
|
|
store,
|
|
provider: "anthropic",
|
|
preferredProfile: "anthropic:work",
|
|
});
|
|
expect(order[0]).toBe("anthropic:work");
|
|
expect(order).toContain("anthropic:default");
|
|
});
|
|
|
|
it("prioritizes last-good profile when no preferred override", () => {
|
|
const order = resolveAuthProfileOrder({
|
|
cfg,
|
|
store: { ...store, lastGood: { anthropic: "anthropic:work" } },
|
|
provider: "anthropic",
|
|
});
|
|
expect(order[0]).toBe("anthropic:work");
|
|
});
|
|
|
|
it("uses explicit profiles when order is missing", () => {
|
|
const order = resolveAuthProfileOrder({
|
|
cfg,
|
|
store,
|
|
provider: "anthropic",
|
|
});
|
|
expect(order).toEqual(["anthropic:default", "anthropic:work"]);
|
|
});
|
|
|
|
it("uses configured order when provided", () => {
|
|
const order = resolveAuthProfileOrder({
|
|
cfg: {
|
|
auth: {
|
|
order: { anthropic: ["anthropic:work", "anthropic:default"] },
|
|
profiles: cfg.auth.profiles,
|
|
},
|
|
},
|
|
store,
|
|
provider: "anthropic",
|
|
});
|
|
expect(order).toEqual(["anthropic:work", "anthropic:default"]);
|
|
});
|
|
});
|