@@ -24,6 +24,8 @@ let accounts: unknown[] = [];
2424let threshold = 80 ;
2525let nextAccountsResponseGate : Promise < void > | null = null ;
2626let pauseResponseActiveId : string | null = null ;
27+ let bulkPausedAccountIds : string [ ] = [ "a2" ] ;
28+ let bulkResponseActiveId : string | null = null ;
2729
2830beforeEach ( ( ) => {
2931 previous = Object . fromEntries ( globals . map ( ( k ) => [ k , Reflect . get ( globalThis , k ) ] ) ) as typeof previous ;
@@ -40,6 +42,8 @@ beforeEach(() => {
4042 calls = [ ] ;
4143 nextAccountsResponseGate = null ;
4244 pauseResponseActiveId = null ;
45+ bulkPausedAccountIds = [ "a2" ] ;
46+ bulkResponseActiveId = null ;
4347 accounts = [ { id : "a1" , email : "account-one" , isMain : true , paused : false , hasCredential : true , quota : null } ] ;
4448 Object . defineProperty ( globalThis , "fetch" , {
4549 configurable : true ,
@@ -57,14 +61,20 @@ beforeEach(() => {
5761 return { ok : true , json : async ( ) => ( { activeCodexAccountId : pauseResponseActiveId } ) } as unknown as Response ;
5862 }
5963 if ( path === "codex-auth/accounts/pause-exhausted" ) {
64+ const pausedIds = new Set ( bulkPausedAccountIds ) ;
6065 accounts = accounts . map ( account => (
61- typeof account === "object" && account !== null && "id" in account && account . id === "a2"
66+ typeof account === "object" && account !== null && "id" in account
67+ && ( pausedIds . has ( String ( account . id ) ) || ( pausedIds . has ( "__main__" ) && "isMain" in account && account . isMain === true ) )
6268 ? { ...account , paused : true }
6369 : account
6470 ) ) ;
6571 return {
6672 ok : true ,
67- json : async ( ) => ( { pausedAccountIds : [ "a2" ] , pausedCount : 1 , activeCodexAccountId : null } ) ,
73+ json : async ( ) => ( {
74+ pausedAccountIds : bulkPausedAccountIds ,
75+ pausedCount : bulkPausedAccountIds . length ,
76+ activeCodexAccountId : bulkResponseActiveId ,
77+ } ) ,
6878 } as unknown as Response ;
6979 }
7080 if ( path . startsWith ( "codex-auth/accounts" ) ) {
@@ -208,6 +218,31 @@ test("bulk pausing writes one endpoint and updates every returned account", asyn
208218 expect ( seen . current ! . pausingExhausted ) . toBe ( false ) ;
209219} ) ;
210220
221+ test ( "bulk pausing translates the main sentinel to its distinct account row" , async ( ) => {
222+ accounts = [
223+ { id : "a1" , email : "main" , isMain : true , paused : false , hasCredential : true , quota : null } ,
224+ { id : "a2" , email : "pool" , isMain : false , paused : false , hasCredential : true , quota : null } ,
225+ ] ;
226+ bulkPausedAccountIds = [ "__main__" ] ;
227+ bulkResponseActiveId = "a2" ;
228+ const seen = await mountController ( ) ;
229+ let releaseReload ! : ( ) => void ;
230+ nextAccountsResponseGate = new Promise < void > ( resolve => { releaseReload = resolve ; } ) ;
231+
232+ await act ( async ( ) => {
233+ expect ( await seen . current ! . pauseExhaustedAccounts ( ) ) . toEqual ( { ok : true , pausedCount : 1 } ) ;
234+ } ) ;
235+
236+ expect ( seen . current ! . accounts . find ( account => account . isMain ) ?. id ) . toBe ( "a1" ) ;
237+ expect ( seen . current ! . accounts . find ( account => account . isMain ) ?. paused ) . toBe ( true ) ;
238+ expect ( seen . current ! . activeId ) . toBe ( "a2" ) ;
239+
240+ await act ( async ( ) => {
241+ releaseReload ( ) ;
242+ await new Promise ( ( resolve ) => setTimeout ( resolve , 30 ) ) ;
243+ } ) ;
244+ } ) ;
245+
211246test ( "two pause holders both have to release before polling resumes" , async ( ) => {
212247 const seen = await mountController ( ) ;
213248 const controller = seen . current ! ;
0 commit comments