Skip to content

Commit 206393f

Browse files
committed
fix(identity): use distinct org account ids in ambiguity check
1 parent 9ba8e5d commit 206393f

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ export const OpenAIOAuthPlugin: Plugin = async ({ client }: PluginInput) => {
645645
let newestNoAccountId: number | undefined;
646646
let newestExactAccountId: number | undefined;
647647
let newestAnyNonEmptyAccountId: number | undefined;
648-
let nonEmptyAccountIdCount = 0;
648+
const distinctNonEmptyAccountIds = new Set<string>();
649649

650650
for (const index of matches) {
651651
const existing = accounts[index];
@@ -658,7 +658,7 @@ export const OpenAIOAuthPlugin: Plugin = async ({ client }: PluginInput) => {
658658
: index;
659659
continue;
660660
}
661-
nonEmptyAccountIdCount += 1;
661+
distinctNonEmptyAccountIds.add(existingAccountId);
662662
newestAnyNonEmptyAccountId =
663663
typeof newestAnyNonEmptyAccountId === "number"
664664
? pickNewestAccountIndex(newestAnyNonEmptyAccountId, index)
@@ -677,7 +677,7 @@ export const OpenAIOAuthPlugin: Plugin = async ({ client }: PluginInput) => {
677677
if (typeof newestNoAccountId === "number") {
678678
return newestNoAccountId;
679679
}
680-
if (nonEmptyAccountIdCount === 1) {
680+
if (distinctNonEmptyAccountIds.size === 1) {
681681
return newestAnyNonEmptyAccountId;
682682
}
683683
return undefined;

test/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1965,7 +1965,7 @@ describe("OpenAIOAuthPlugin persistAccountPool", () => {
19651965
expect(mockStorage.accounts.some((account) => account.accountId === "token-personal")).toBe(true);
19661966
});
19671967

1968-
it("preserves org/no-org shared-refresh entries with different accountId values in pre-populated storage", async () => {
1968+
it("preserves org/no-org shared-refresh entries with different accountId values from a single login", async () => {
19691969
const accountsModule = await import("../lib/accounts.js");
19701970
const authModule = await import("../lib/auth/auth.js");
19711971

0 commit comments

Comments
 (0)