fix: promote selected auth profile order

This commit is contained in:
Peter Steinberger
2026-01-09 05:36:14 +00:00
parent 8e35ad5484
commit 48a1b07097
2 changed files with 43 additions and 4 deletions

View File

@@ -5,7 +5,10 @@ import path from "node:path";
import type { OAuthCredentials } from "@mariozechner/pi-ai";
import { afterEach, describe, expect, it } from "vitest";
import { writeOAuthCredentials } from "./onboard-auth.js";
import {
applyAuthProfileConfig,
writeOAuthCredentials,
} from "./onboard-auth.js";
describe("writeOAuthCredentials", () => {
const previousStateDir = process.env.CLAWDBOT_STATE_DIR;
@@ -77,3 +80,28 @@ describe("writeOAuthCredentials", () => {
).rejects.toThrow();
});
});
describe("applyAuthProfileConfig", () => {
it("promotes the newly selected profile to the front of auth.order", () => {
const next = applyAuthProfileConfig(
{
auth: {
profiles: {
"anthropic:default": { provider: "anthropic", mode: "api_key" },
},
order: { anthropic: ["anthropic:default"] },
},
},
{
profileId: "anthropic:claude-cli",
provider: "anthropic",
mode: "oauth",
},
);
expect(next.auth?.order?.anthropic).toEqual([
"anthropic:claude-cli",
"anthropic:default",
]);
});
});