@@ -345,6 +345,70 @@ describe("CLIProxyAPI built-in management API", () => {
345345 } ) ,
346346 ) ;
347347
348+ it . effect . each ( [
349+ {
350+ name : "spend budget" ,
351+ budget : {
352+ spend : {
353+ enabled : true ,
354+ used : { amount_minor : 4_631 , currency : "USD" , exponent : 2 } ,
355+ limit : { amount_minor : 50_000 , currency : "USD" , exponent : 2 } ,
356+ } ,
357+ } ,
358+ } ,
359+ {
360+ name : "extra usage" ,
361+ budget : {
362+ extra_usage : {
363+ is_enabled : true ,
364+ used_credits : 4_631 ,
365+ monthly_limit : 50_000 ,
366+ utilization : 9 ,
367+ } ,
368+ } ,
369+ } ,
370+ ] ) ( "keeps Claude monthly spend from $name beside rolling windows" , ( { budget } ) =>
371+ Effect . gen ( function * ( ) {
372+ const test = fixture ( {
373+ accounts : [ { ...accounts [ 0 ] ! , provider : "claude" } ] ,
374+ upstream : ( ) => ( {
375+ status : 200 ,
376+ body : { five_hour : { utilization : 10 , resets_at : null } , ...budget } ,
377+ } ) ,
378+ } ) ;
379+ const result = yield * ( yield * test . api ) . readAccounts ( config ) ;
380+ expect (
381+ result [ 0 ] ?. usageLimits . windows . map ( ( window ) => [ window . id , window . usedPercent ] ) ,
382+ ) . toEqual ( [
383+ [ "five_hour" , 10 ] ,
384+ [ "monthly_spend" , expect . closeTo ( 9.262 , 10 ) ] ,
385+ ] ) ;
386+ } ) ,
387+ ) ;
388+
389+ it . effect ( "omits disabled Claude budgets without losing rolling windows" , ( ) =>
390+ Effect . gen ( function * ( ) {
391+ const test = fixture ( {
392+ accounts : [ { ...accounts [ 0 ] ! , provider : "claude" } ] ,
393+ upstream : ( ) => ( {
394+ status : 200 ,
395+ body : {
396+ five_hour : { utilization : 10 , resets_at : null } ,
397+ spend : { enabled : false , used : null , limit : null } ,
398+ extra_usage : {
399+ is_enabled : false ,
400+ used_credits : null ,
401+ monthly_limit : null ,
402+ utilization : null ,
403+ } ,
404+ } ,
405+ } ) ,
406+ } ) ;
407+ const result = yield * ( yield * test . api ) . readAccounts ( config ) ;
408+ expect ( result [ 0 ] ?. usageLimits . windows . map ( ( window ) => window . id ) ) . toEqual ( [ "five_hour" ] ) ;
409+ } ) ,
410+ ) ;
411+
348412 it . effect ( "pins redemption to the displayed credit and clears only that account's cooldown" , ( ) =>
349413 Effect . gen ( function * ( ) {
350414 const test = fixture ( ) ;
0 commit comments