@@ -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