Skip to content

Commit 6687cb8

Browse files
committed
Use refreshed email for entitlement cache keys
1 parent da8ec04 commit 6687cb8

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1515,7 +1515,7 @@ while (attempted.size < Math.max(1, accountCount)) {
15151515
extractAccountEmail(accountAuth.access) ?? account.email;
15161516
const entitlementAccountKey = resolveEntitlementAccountKey({
15171517
accountId: account.accountId ?? accountId,
1518-
email: account.email ?? resolvedEmail,
1518+
email: resolvedEmail,
15191519
refreshToken: account.refreshToken,
15201520
index: account.index,
15211521
});

test/index.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,36 @@ describe("OpenAIOAuthPlugin fetch handler", () => {
11411141
expect(syncCodexCliSelectionMock).toHaveBeenCalledWith(0);
11421142
});
11431143

1144+
it("uses the refreshed token email when checking entitlement blocks", async () => {
1145+
mockStorage.accounts = [
1146+
{
1147+
accountId: "acc-1",
1148+
email: "stale@example.com",
1149+
refreshToken: "refresh-1",
1150+
},
1151+
];
1152+
extractAccountEmailMock.mockReturnValueOnce("fresh@example.com");
1153+
const entitlementModule = await import("../lib/entitlement-cache.js");
1154+
const isBlockedSpy = vi
1155+
.spyOn(entitlementModule.EntitlementCache.prototype, "isBlocked")
1156+
.mockReturnValue({ blocked: false, waitMs: 0 });
1157+
globalThis.fetch = vi.fn().mockResolvedValue(
1158+
new Response(JSON.stringify({ content: "test" }), { status: 200 }),
1159+
);
1160+
1161+
const { sdk } = await setupPlugin();
1162+
const response = await sdk.fetch!("https://api.openai.com/v1/chat", {
1163+
method: "POST",
1164+
body: JSON.stringify({ model: "gpt-5.1" }),
1165+
});
1166+
1167+
expect(response.status).toBe(200);
1168+
expect(isBlockedSpy).toHaveBeenCalledWith(
1169+
"account:acc-1::email:fresh@example.com",
1170+
"gpt-5.1",
1171+
);
1172+
});
1173+
11441174
it("handles network errors and rotates to next account", async () => {
11451175
globalThis.fetch = vi.fn().mockRejectedValue(new Error("Network timeout"));
11461176

0 commit comments

Comments
 (0)