@@ -851,6 +851,68 @@ describe("pooled account columns", () => {
851851 row . columns . map ( ( member ) => ( member . window ? member . account . key : null ) ) ,
852852 ) ;
853853
854+ it ( "counts an exhausted weekly as empty in session and model rows with the same reset" , ( ) => {
855+ const accounts = (
856+ [
857+ [ 90 , 0 , 96 ] ,
858+ [ 100 , 1 , 70 ] ,
859+ [ 100 , 1 , 70 ] ,
860+ [ 90 , 50 , 88 ] ,
861+ ] as const
862+ ) . map ( ( [ session , week , model ] , index ) =>
863+ account ( String ( index ) , [
864+ { ...window , usedPercent : 100 - session } ,
865+ { ...weekly , usedPercent : 100 - week , resetsAt : "2026-09-06T12:00:00.000Z" } ,
866+ { ...weekly , id : "seven_day_fable" , usedPercent : 100 - model } ,
867+ ] ) ,
868+ ) ;
869+ const rows = collectLimitPools ( accounts , now ) [ 0 ] ! . windows ;
870+ expect ( rows . map ( ( row ) => row . remainingPercent ) ) . toEqual ( [ 73 , 13 , 57 ] ) ;
871+ for ( const row of rows ) {
872+ expect ( row . columns [ 0 ] ?. window ) . toMatchObject ( {
873+ usedPercent : 100 ,
874+ resetsAt : "2026-09-06T12:00:00.000Z" ,
875+ windowDurationMins : weekly . windowDurationMins ,
876+ } ) ;
877+ expect ( row . resets . find ( ( reset ) => reset . member . account . key === "0" ) ) . toMatchObject ( {
878+ at : Date . parse ( "2026-09-06T12:00:00.000Z" ) ,
879+ restoresPercent : 25 ,
880+ } ) ;
881+ }
882+ expect ( accounts [ 0 ] ?. limits . windows [ 0 ] ?. usedPercent ) . toBe ( 10 ) ;
883+ const refreshed = accounts . map ( ( a ) => ( {
884+ ...a ,
885+ limits : { ...a . limits , windows : a . limits . windows . map ( ( w ) => ( { ...w , usedPercent : 0 } ) ) } ,
886+ } ) ) ;
887+ expect ( collectLimitPools ( refreshed , now ) [ 0 ] ?. windows [ 0 ] ?. remainingPercent ) . toBe ( 100 ) ;
888+ } ) ;
889+
890+ it . each ( [
891+ [ "codex" , "secondary" , 100 , 0 ] ,
892+ [ "claudeAgent" , "seven_day" , 99 , 60 ] ,
893+ [ "claudeAgent" , "seven_day_fable" , 100 , 60 ] ,
894+ [ "cursor" , "seven_day" , 100 , 60 ] ,
895+ ] ) ( "uses only the exhausted covering weekly for %s (%s, %i used)" , ( driver , id , used , left ) => {
896+ const a = account ( "a" , [ window , { ...weekly , id, usedPercent : used } ] ) ;
897+ const [ session ] = collectLimitPools (
898+ [ { ...a , driver : ProviderDriverKind . make ( driver ) } ] ,
899+ now ,
900+ ) [ 0 ] ! . windows ;
901+ expect ( session ?. remainingPercent ) . toBe ( left ) ;
902+ } ) ;
903+
904+ it . each ( [ undefined , "invalid" ] ) (
905+ "does not invent a reset when the weekly reports %s" ,
906+ ( resetsAt ) => {
907+ const [ session ] = collectLimitPools (
908+ [ account ( "a" , [ window , { ...weekly , usedPercent : 100 , resetsAt } ] ) ] ,
909+ now ,
910+ ) [ 0 ] ! . windows ;
911+ expect ( session ?. remainingPercent ) . toBe ( 0 ) ;
912+ expect ( session ?. resets ) . toEqual ( [ ] ) ;
913+ } ,
914+ ) ;
915+
854916 it ( "keeps session columns across rows with opposite reset and usage orders" , ( ) => {
855917 const accounts = [
856918 account ( "a" , [
0 commit comments