@@ -60,6 +60,54 @@ describe("codexRateLimitsToLimits", () => {
6060 } ,
6161 ] ) ;
6262 } ) ;
63+
64+ it ( "selects the main Codex allowance and leaves Spark out" , ( ) => {
65+ const spark = {
66+ limitId : "codex_bengalfox" ,
67+ primary : { usedPercent : 0 , windowDurationMins : 300 } ,
68+ secondary : { usedPercent : 90 , windowDurationMins : 10080 } ,
69+ } ;
70+ expect (
71+ codexRateLimitsToLimits ( {
72+ checkedAt,
73+ snapshot : spark ,
74+ rateLimitsByLimitId : {
75+ codex_bengalfox : spark ,
76+ codex : { secondary : { usedPercent : 42 , windowDurationMins : 10080 } } ,
77+ } ,
78+ } ) . windows ,
79+ ) . toEqual ( [
80+ {
81+ id : "secondary" ,
82+ kind : "weekly" ,
83+ label : "Weekly" ,
84+ usedPercent : 42 ,
85+ windowDurationMins : 10080 ,
86+ } ,
87+ ] ) ;
88+ } ) ;
89+
90+ it . each ( [ undefined , null , { } ] ) (
91+ "supports legacy reads with no bucket map: %j" ,
92+ ( rateLimitsByLimitId ) => {
93+ const snapshot = { primary : { usedPercent : 12 , windowDurationMins : 300 } } ;
94+ expect ( codexRateLimitsToLimits ( { checkedAt, snapshot, rateLimitsByLimitId } ) ) . toEqual (
95+ codexRateLimitsToLimits ( { checkedAt, snapshot } ) ,
96+ ) ;
97+ } ,
98+ ) ;
99+
100+ it ( "does not show a model-specific legacy snapshot as the main allowance" , ( ) => {
101+ expect (
102+ codexRateLimitsToLimits ( {
103+ checkedAt,
104+ snapshot : {
105+ limitId : "codex_bengalfox" ,
106+ secondary : { usedPercent : 90 } ,
107+ } ,
108+ } ) . windows ,
109+ ) . toEqual ( [ ] ) ;
110+ } ) ;
63111} ) ;
64112
65113describe ( "codexRateLimitsToUpdate" , ( ) => {
@@ -81,6 +129,30 @@ describe("codexRateLimitsToUpdate", () => {
81129 } ) ;
82130 expect ( codexRateLimitsToUpdate ( { planType : "plus" } ) ) . toBeUndefined ( ) ;
83131 } ) ;
132+
133+ it ( "ignores Spark notifications so they cannot overwrite the main allowance" , ( ) => {
134+ expect (
135+ codexRateLimitsToUpdate ( {
136+ limitId : "codex_bengalfox" ,
137+ primary : { usedPercent : 0 , windowDurationMins : 300 } ,
138+ secondary : { usedPercent : 90 , windowDurationMins : 10080 } ,
139+ } ) ,
140+ ) . toBeUndefined ( ) ;
141+ expect (
142+ codexRateLimitsToUpdate ( {
143+ limitId : "codex" ,
144+ secondary : { usedPercent : 42 , windowDurationMins : 10080 } ,
145+ } ) ?. windows ,
146+ ) . toEqual ( [
147+ {
148+ id : "secondary" ,
149+ kind : "weekly" ,
150+ label : "Weekly" ,
151+ usedPercent : 42 ,
152+ windowDurationMins : 10080 ,
153+ } ,
154+ ] ) ;
155+ } ) ;
84156} ) ;
85157
86158describe ( "codexRateLimitsFailureMessage" , ( ) => {
0 commit comments