@@ -118,6 +118,66 @@ describe("Command Code provider quota", () => {
118118 expect ( JSON . stringify ( result ) ) . not . toContain ( "commandcode-secret" ) ;
119119 } ) ;
120120
121+ test ( "omits a zero Command Code window reset instead of treating it as the Unix epoch" , async ( ) => {
122+ globalThis . fetch = ( async ( input : RequestInfo | URL ) => {
123+ const url = String ( input ) ;
124+ if ( url === "https://api.commandcode.ai/alpha/whoami"
125+ || url === "https://api.commandcode.ai/alpha/billing/subscriptions"
126+ || url === "https://api.commandcode.ai/alpha/usage/summary" ) {
127+ return new Response ( "down" , { status : 500 } ) ;
128+ }
129+ if ( url !== "https://api.commandcode.ai/alpha/billing/credits" ) {
130+ throw new Error ( `unexpected Command Code quota probe: ${ url } ` ) ;
131+ }
132+ return new Response ( JSON . stringify ( {
133+ windowLimits : {
134+ fiveHour : { cap : 14 , used : 0 , resetAt : 0 } ,
135+ weekly : { cap : 35 , used : 34.9522404823 , resetAt : 1_787_184_801_319 } ,
136+ } ,
137+ } ) , { status : 200 , headers : { "content-type" : "application/json" } } ) ;
138+ } ) as typeof fetch ;
139+
140+ const result = await fetchProviderQuotaReports ( commandCodeConfig ( ) , true ) ;
141+
142+ expect ( result . reports [ 0 ] ?. quota ) . toEqual ( {
143+ fiveHourPercent : 0 ,
144+ weeklyPercent : 99.86354423514285 ,
145+ weeklyResetAt : 1_787_184_801_319 ,
146+ updatedAt : expect . any ( Number ) ,
147+ } ) ;
148+ expect ( result . reports [ 0 ] ?. quota ) . not . toHaveProperty ( "fiveHourResetAt" ) ;
149+ } ) ;
150+
151+ test ( "omits a signed numeric Command Code window reset instead of Date.parse-ing it" , async ( ) => {
152+ globalThis . fetch = ( async ( input : RequestInfo | URL ) => {
153+ const url = String ( input ) ;
154+ if ( url === "https://api.commandcode.ai/alpha/whoami"
155+ || url === "https://api.commandcode.ai/alpha/billing/subscriptions"
156+ || url === "https://api.commandcode.ai/alpha/usage/summary" ) {
157+ return new Response ( "down" , { status : 500 } ) ;
158+ }
159+ if ( url !== "https://api.commandcode.ai/alpha/billing/credits" ) {
160+ throw new Error ( `unexpected Command Code quota probe: ${ url } ` ) ;
161+ }
162+ return new Response ( JSON . stringify ( {
163+ windowLimits : {
164+ fiveHour : { cap : 14 , used : 0 , resetAt : "-1" } ,
165+ weekly : { cap : 35 , used : 34.9522404823 , resetAt : 1_787_184_801_319 } ,
166+ } ,
167+ } ) , { status : 200 , headers : { "content-type" : "application/json" } } ) ;
168+ } ) as typeof fetch ;
169+
170+ const result = await fetchProviderQuotaReports ( commandCodeConfig ( ) , true ) ;
171+
172+ expect ( result . reports [ 0 ] ?. quota ) . toEqual ( {
173+ fiveHourPercent : 0 ,
174+ weeklyPercent : 99.86354423514285 ,
175+ weeklyResetAt : 1_787_184_801_319 ,
176+ updatedAt : expect . any ( Number ) ,
177+ } ) ;
178+ expect ( result . reports [ 0 ] ?. quota ) . not . toHaveProperty ( "fiveHourResetAt" ) ;
179+ } ) ;
180+
121181 test ( "keeps rolling windows when whoami and usage summary fail" , async ( ) => {
122182 const seen : string [ ] = [ ] ;
123183 globalThis . fetch = ( async ( input : RequestInfo | URL ) => {
0 commit comments