@@ -433,6 +433,55 @@ describe("pools", () => {
433433 expect ( account ?. environments ) . toEqual ( [ { environmentId : "env-a" , label : "Laptop" } ] ) ;
434434 } ) ;
435435
436+ it ( "redeems through the hub when it holds a credit, even with a fresher native read" , ( ) => {
437+ const native = provider ( {
438+ driver : claude ,
439+ instanceId : ProviderInstanceId . make ( "claude" ) ,
440+ auth :
{ status :
"authenticated" , email :
"[email protected] " } , 441+ usageLimits : {
442+ checkedAt : "2026-09-03T11:30:00.000Z" ,
443+ windows : [ { ...window , usedPercent : 40 } ] ,
444+ resetCredits : { availableCount : 3 , nextCreditId : "native-credit" } ,
445+ } ,
446+ } ) ;
447+ const input = new Map ( [
448+ [
449+ EnvironmentId . make ( "env-a" ) ,
450+ {
451+ ...laptop ,
452+ serverConfig : {
453+ providers : [ native ] ,
454+ usageLimitSources : [
455+ {
456+ ...source ,
457+ accounts : [
458+ {
459+ 460+ driver : claude ,
461+ 462+ usageLimits : {
463+ checkedAt,
464+ windows : [ { ...window , usedPercent : 55 } ] ,
465+ resetCredits : { availableCount : 2 , nextCreditId : "hub-credit" } ,
466+ } ,
467+ } ,
468+ ] ,
469+ } ,
470+ ] ,
471+ } ,
472+ } ,
473+ ] ,
474+ ] ) ;
475+ const [ account ] = collectLimitAccounts ( input ) ;
476+ // Only the hub path clears the routing cooldown it holds for this account.
477+ expect ( account ?. redeem ) . toEqual ( {
478+ environmentId : "env-a" ,
479+ input :
{ sourceId :
"hub" , accountId :
"[email protected] " , creditId :
"hub-credit" } , 480+ } ) ;
481+ // The fresher native balance is still the one shown.
482+ expect ( account ?. limits . resetCredits ?. availableCount ) . toBe ( 3 ) ;
483+ } ) ;
484+
436485 it ( "redeems on the environment whose snapshot supplied the credits on show" , ( ) => {
437486 const stale = provider ( {
438487 auth :
{ status :
"authenticated" , email :
"[email protected] " } , @@ -839,6 +888,46 @@ describe("/usage-limits", () => {
839888 } ) ;
840889 } ) ;
841890
891+ it ( "redeems a native duplicate through the hub even when the native snapshot is fresher" , ( ) => {
892+ const fresher = provider ( {
893+ usageLimits : {
894+ checkedAt : "2026-09-03T11:30:00.000Z" ,
895+ windows : [ window ] ,
896+ resetCredits : { availableCount : 3 , nextCreditId : "native-credit" } ,
897+ } ,
898+ auth :
{ status :
"authenticated" , email :
"[email protected] " } , 899+ } ) ;
900+ const stale = [
901+ {
902+ id : UsageLimitSourceId . make ( "hub" ) ,
903+ kind : "cliproxy" as const ,
904+ label : "Accounts" ,
905+ checkedAt : limits . checkedAt ,
906+ accounts : [
907+ {
908+ id : "duplicate" ,
909+ driver : fresher . driver ,
910+ 911+ usageLimits : {
912+ ...limits ,
913+ resetCredits : { availableCount : 2 , nextCreditId : "hub-credit" } ,
914+ } ,
915+ } ,
916+ ] ,
917+ } ,
918+ ] ;
919+ const report = collectProviderUsageLimits ( fresher . instanceId , [ fresher ] , stale , now ) ;
920+ // Only redeeming through the hub clears the routing cooldown it holds for
921+ // this account, so the hub wins the path even with a staler balance.
922+ expect ( report ?. accounts [ 0 ] ?. resetCreditInput ) . toEqual ( {
923+ sourceId : "hub" ,
924+ accountId : "duplicate" ,
925+ creditId : "hub-credit" ,
926+ } ) ;
927+ // The fresher native balance is still the one shown.
928+ expect ( report ?. accounts [ 0 ] ?. limits . resetCredits ?. availableCount ) . toBe ( 3 ) ;
929+ } ) ;
930+
842931 it ( "keeps accounts and custom instances separate, filtering by driver" , ( ) => {
843932 const report = collectProviderUsageLimits (
844933 selected . instanceId ,
0 commit comments