@@ -309,6 +309,38 @@ describe("main account rotation (Option A)", () => {
309309 }
310310 } ) ;
311311
312+ test ( "does not retry an in-flight usage response when the current identity is temporarily unknown" , async ( ) => {
313+ expect ( reconcileMainCodexAccountRuntimeState ( ) ) . toBe ( false ) ;
314+ const originalFetch = globalThis . fetch ;
315+ let resolveUsage ! : ( response : Response ) => void ;
316+ let usageCalls = 0 ;
317+ globalThis . fetch = ( async ( input , init ) => {
318+ if ( ! String ( input ) . includes ( "/backend-api/wham/usage" ) ) return originalFetch ( input , init ) ;
319+ usageCalls ++ ;
320+ expect ( new Headers ( init ?. headers ) . get ( "ChatGPT-Account-Id" ) ) . toBe ( "main_acct" ) ;
321+ return new Promise < Response > ( resolve => { resolveUsage = resolve ; } ) ;
322+ } ) as typeof fetch ;
323+ try {
324+ const infoPromise = fetchMainAccountInfo ( true ) ;
325+ rmSync ( join ( CODEX_DIR , "auth.json" ) ) ;
326+ resolveUsage ( new Response ( JSON . stringify ( {
327+ 328+ plan_type : "plus" ,
329+ rate_limit : { primary_window : { used_percent : 23 , reset_at : 1_788_000_000 } } ,
330+ } ) , { status : 200 } ) ) ;
331+
332+ await expect ( infoPromise ) . resolves . toMatchObject ( {
333+ 334+ plan : "plus" ,
335+ quota : { weeklyPercent : 23 } ,
336+ } ) ;
337+ expect ( usageCalls ) . toBe ( 1 ) ;
338+ expect ( isAccountNeedsReauth ( MAIN_CODEX_ACCOUNT_ID ) ) . toBe ( false ) ;
339+ } finally {
340+ globalThis . fetch = originalFetch ;
341+ }
342+ } ) ;
343+
312344 test ( "no active id selects from main plus added accounts and binds main affinity" , async ( ) => {
313345 const config = makeConfig ( { activeCodexAccountId : undefined , autoSwitchThreshold : 0 } ) ;
314346 updateAccountQuota ( MAIN_CODEX_ACCOUNT_ID , 5 , 0 ) ;
0 commit comments