fix: restore auth fallback ordering

This commit is contained in:
Peter Steinberger
2026-01-06 01:38:09 +00:00
parent 6f541d6304
commit 87f4efda8d
5 changed files with 59 additions and 8 deletions

View File

@@ -30,12 +30,12 @@ describe("resolveAuthProfileOrder", () => {
},
};
it("returns empty order without explicit config", () => {
it("uses stored profiles when no config exists", () => {
const order = resolveAuthProfileOrder({
store,
provider: "anthropic",
});
expect(order).toEqual([]);
expect(order).toEqual(["anthropic:default", "anthropic:work"]);
});
it("prioritizes preferred profiles", () => {
@@ -80,4 +80,29 @@ describe("resolveAuthProfileOrder", () => {
});
expect(order).toEqual(["anthropic:work", "anthropic:default"]);
});
it("prioritizes oauth profiles when order missing", () => {
const mixedStore: AuthProfileStore = {
version: 1,
profiles: {
"anthropic:default": {
type: "api_key",
provider: "anthropic",
key: "sk-default",
},
"anthropic:oauth": {
type: "oauth",
provider: "anthropic",
access: "access-token",
refresh: "refresh-token",
expires: Date.now() + 60_000,
},
},
};
const order = resolveAuthProfileOrder({
store: mixedStore,
provider: "anthropic",
});
expect(order).toEqual(["anthropic:oauth", "anthropic:default"]);
});
});