@@ -135,6 +135,65 @@ describe("subscription widget snapshots", () => {
135135 } ) ;
136136} ) ;
137137
138+ describe ( "subscription widget expiry" , ( ) => {
139+ const maxAgeDeadline = now + 15 * 60_000 ;
140+ function single ( resetsAt : string ) {
141+ return buildSubscriptionUsageSnapshot (
142+ presentations ( [ provider ( { usageLimits : { checkedAt, windows : [ { ...window , resetsAt } ] } } ) ] ) ,
143+ deepLink ,
144+ ) . providers [ 0 ] ;
145+ }
146+
147+ it . each ( [ "2026-09-05T11:50:00.000Z" , checkedAt ] ) (
148+ "keeps usage whose reset at %s already happened when observed" ,
149+ ( resetsAt ) => {
150+ expect ( single ( resetsAt ) ) . toMatchObject ( {
151+ detail : "Subscription remaining" ,
152+ expiresAt : maxAgeDeadline ,
153+ windows : [ { remaining : 60 , reset : expect . stringMatching ( / ^ R e s e t / ) } ] ,
154+ } ) ;
155+ } ,
156+ ) ;
157+
158+ it . each ( [
159+ { resetAccount : 1 , expiresAt : maxAgeDeadline , label : / ^ R e s e t / } ,
160+ { resetAccount : 0 , expiresAt : now + 2 * 60_000 , label : / ^ N e x t r e s e t / } ,
161+ ] ) (
162+ "compares a pooled reset with its own account's observation (account $resetAccount)" ,
163+ ( { resetAccount, expiresAt, label } ) => {
164+ // Account 0 was observed at 12:00, account 1 at 12:05; the pooled reset is at 12:02.
165+ const snapshot = buildSubscriptionUsageSnapshot (
166+ presentations (
167+ [ checkedAt , "2026-09-05T12:05:00.000Z" ] . map ( ( accountCheckedAt , index ) =>
168+ provider ( {
169+ instanceId : ProviderInstanceId . make ( `codex-${ index } ` ) ,
170+ auth : { status : "authenticated" , email : `account-${ index } @example.com` } ,
171+ usageLimits : {
172+ checkedAt : accountCheckedAt ,
173+ windows : [
174+ {
175+ ...window ,
176+ resetsAt :
177+ index === resetAccount
178+ ? "2026-09-05T12:02:00.000Z"
179+ : "2026-09-05T13:00:00.000Z" ,
180+ } ,
181+ ] ,
182+ } ,
183+ } ) ,
184+ ) ,
185+ ) ,
186+ deepLink ,
187+ ) ;
188+ expect ( snapshot . providers [ 0 ] ) . toMatchObject ( {
189+ detail : "2 accounts · pooled" ,
190+ expiresAt,
191+ windows : [ { remaining : 60 , reset : expect . stringMatching ( label ) } ] ,
192+ } ) ;
193+ } ,
194+ ) ;
195+ } ) ;
196+
138197describe ( "widget refresh probes" , ( ) => {
139198 it ( "does not overlap a slow probe even after the refresh interval" , async ( ) => {
140199 let finish ! : ( ) => void ;
0 commit comments