11import * as NodeServices from "@effect/platform-node/NodeServices" ;
22import { describe , expect , it } from "@effect/vitest" ;
33import * as Context from "effect/Context" ;
4+ import * as DateTime from "effect/DateTime" ;
45import * as Effect from "effect/Effect" ;
56import * as FileSystem from "effect/FileSystem" ;
67import * as Path from "effect/Path" ;
8+ import * as TestClock from "effect/testing/TestClock" ;
79import { FetchHttpClient , HttpClient , HttpClientResponse } from "effect/http" ;
810
911import { makeAntigravityUsageProbe } from "./antigravityUsageLimits.ts" ;
@@ -59,6 +61,7 @@ const fixture = Effect.fn("AntigravityUsageTest.fixture")(function* (
5961 tokenStatus ?: number ;
6062 refreshToken ?: string ;
6163 userId ?: string ;
64+ userInfoAt ?: number ;
6265 missingToken ?: boolean ;
6366 authMethod ?: "oauth-personal" | "gemini-api-key" ;
6467 } = { } ,
@@ -115,7 +118,13 @@ const fixture = Effect.fn("AntigravityUsageTest.fixture")(function* (
115118 } )
116119 : Response . json ( options . models ?? { models : { } } ) ,
117120 ) ;
118- } ) ,
121+ } ) . pipe (
122+ Effect . tap ( ( ) =>
123+ request . url . endsWith ( "/userinfo" ) && options . userInfoAt !== undefined
124+ ? TestClock . setTime ( options . userInfoAt )
125+ : Effect . void ,
126+ ) ,
127+ ) ,
119128 ) ;
120129 const usage = yield * makeAntigravityUsageProbe ( {
121130 profileDirectory,
@@ -125,6 +134,288 @@ const fixture = Effect.fn("AntigravityUsageTest.fixture")(function* (
125134} ) ;
126135
127136describe ( "Antigravity subscription limits" , ( ) => {
137+ // Oracle: the 10:16 UTC payload and its narrow Workaround rule.
138+ it . effect ( "omits rolling resets for untouched summary buckets and keeps used Gemini resets" , ( ) =>
139+ Effect . gen ( function * ( ) {
140+ yield * TestClock . setTime ( DateTime . toEpochMillis ( DateTime . makeUnsafe ( "2026-10-21T10:16:04Z" ) ) ) ;
141+ const { probe } = yield * fixture ( {
142+ summary : {
143+ groups : [
144+ {
145+ buckets : [
146+ {
147+ bucketId : "3p-5h" ,
148+ window : "5h" ,
149+ remainingFraction : 1 ,
150+ resetTime : "2026-10-21T15:16:05Z" ,
151+ } ,
152+ {
153+ bucketId : "3p-weekly" ,
154+ window : "weekly" ,
155+ remainingFraction : 1 ,
156+ resetTime : "2026-10-28T10:16:05Z" ,
157+ } ,
158+ {
159+ bucketId : "gemini-5h" ,
160+ window : "5h" ,
161+ remainingFraction : 0.848104 ,
162+ resetTime : "2026-10-21T13:29:53Z" ,
163+ description :
164+ "You have used some of your 5-hour limit, it will fully refresh in 3 hours, 13 minutes." ,
165+ } ,
166+ {
167+ bucketId : "gemini-weekly" ,
168+ window : "weekly" ,
169+ remainingFraction : 0.9620177 ,
170+ resetTime : "2026-10-28T08:29:53Z" ,
171+ description :
172+ "You have used some of your weekly limit, it will fully refresh in 6 days, 22 hours." ,
173+ } ,
174+ ] ,
175+ } ,
176+ ] ,
177+ } ,
178+ } ) ;
179+ const limits = yield * probe ;
180+ const byId = new Map ( limits . windows . map ( ( window ) => [ window . id , window ] ) ) ;
181+ expect ( byId . get ( "3p-5h" ) ) . toEqual ( {
182+ id : "3p-5h" ,
183+ label : "Claude & GPT (shared) · 5-hour" ,
184+ kind : "session" ,
185+ usedPercent : 0 ,
186+ windowDurationMins : 300 ,
187+ } ) ;
188+ expect ( byId . get ( "3p-weekly" ) ) . toEqual ( {
189+ id : "3p-weekly" ,
190+ label : "Claude & GPT (shared) · Weekly" ,
191+ kind : "weekly" ,
192+ usedPercent : 0 ,
193+ windowDurationMins : 10080 ,
194+ } ) ;
195+ expect ( byId . get ( "gemini-5h" ) ?. resetsAt ) . toBe ( "2026-10-21T13:29:53.000Z" ) ;
196+ expect ( byId . get ( "gemini-weekly" ) ?. resetsAt ) . toBe ( "2026-10-28T08:29:53.000Z" ) ;
197+ } ) . pipe ( Effect . scoped , Effect . provide ( NodeServices . layer ) ) ,
198+ ) ;
199+
200+ // Oracle: measure the tolerance from the summary request, after auth.
201+ it . effect ( "uses summary request time after authentication for the reset tolerance" , ( ) =>
202+ Effect . gen ( function * ( ) {
203+ yield * TestClock . setTime ( DateTime . toEpochMillis ( DateTime . makeUnsafe ( "2026-10-21T10:16:02Z" ) ) ) ;
204+ const { probe } = yield * fixture ( {
205+ userInfoAt : DateTime . toEpochMillis ( DateTime . makeUnsafe ( "2026-10-21T10:16:04Z" ) ) ,
206+ summary : {
207+ buckets : [
208+ {
209+ bucketId : "3p-5h" ,
210+ window : "5h" ,
211+ remainingFraction : 1 ,
212+ resetTime : "2026-10-21T15:17:03Z" ,
213+ } ,
214+ ] ,
215+ } ,
216+ } ) ;
217+ expect ( ( yield * probe ) . windows [ 0 ] ?. resetsAt ) . toBeUndefined ( ) ;
218+ } ) . pipe ( Effect . scoped , Effect . provide ( NodeServices . layer ) ) ,
219+ ) ;
220+
221+ // Oracle: keep descriptions, measured resets, and spent buckets.
222+ it . effect ( "keeps summary resets with a description, a distant reset, or no quota left" , ( ) =>
223+ Effect . gen ( function * ( ) {
224+ yield * TestClock . setTime ( DateTime . toEpochMillis ( DateTime . makeUnsafe ( "2026-10-21T10:16:04Z" ) ) ) ;
225+ const { probe } = yield * fixture ( {
226+ summary : {
227+ buckets : [
228+ {
229+ bucketId : "described" ,
230+ window : "5h" ,
231+ remainingFraction : 1 ,
232+ description : "Reported reset" ,
233+ resetTime : "2026-10-21T15:16:04Z" ,
234+ } ,
235+ {
236+ bucketId : "distant" ,
237+ window : "weekly" ,
238+ remainingFraction : 1 ,
239+ resetTime : "2026-10-28T12:16:04Z" ,
240+ } ,
241+ {
242+ bucketId : "spent" ,
243+ window : "5h" ,
244+ remainingFraction : 0 ,
245+ resetTime : "2026-10-21T15:16:04Z" ,
246+ } ,
247+ {
248+ bucketId : "overfull" ,
249+ window : "5h" ,
250+ remainingFraction : 1.01 ,
251+ resetTime : "2026-10-21T15:16:04Z" ,
252+ } ,
253+ {
254+ bucketId : "empty-description" ,
255+ window : "5h" ,
256+ remainingFraction : 1 ,
257+ description : "" ,
258+ resetTime : "2026-10-21T15:16:04Z" ,
259+ } ,
260+ ] ,
261+ } ,
262+ } ) ;
263+ expect ( ( yield * probe ) . windows . map ( ( { id, resetsAt } ) => ( { id, resetsAt } ) ) ) . toEqual ( [
264+ { id : "described" , resetsAt : "2026-10-21T15:16:04.000Z" } ,
265+ { id : "empty-description" , resetsAt : "2026-10-21T15:16:04.000Z" } ,
266+ { id : "overfull" , resetsAt : "2026-10-21T15:16:04.000Z" } ,
267+ { id : "spent" , resetsAt : "2026-10-21T15:16:04.000Z" } ,
268+ { id : "distant" , resetsAt : "2026-10-28T12:16:04.000Z" } ,
269+ ] ) ;
270+ } ) . pipe ( Effect . scoped , Effect . provide ( NodeServices . layer ) ) ,
271+ ) ;
272+
273+ // Oracle: the 60-second tolerance applies to both known window lengths.
274+ it . effect ( "omits summary resets 59 seconds away but keeps resets 61 seconds away" , ( ) =>
275+ Effect . gen ( function * ( ) {
276+ yield * TestClock . setTime ( DateTime . toEpochMillis ( DateTime . makeUnsafe ( "2026-10-21T10:16:04Z" ) ) ) ;
277+ const { probe } = yield * fixture ( {
278+ summary : {
279+ buckets : [
280+ {
281+ bucketId : "5h-before" ,
282+ window : "5h" ,
283+ remainingFraction : 1 ,
284+ resetTime : "2026-10-21T15:15:05Z" ,
285+ } ,
286+ {
287+ bucketId : "5h-after" ,
288+ window : "5h" ,
289+ remainingFraction : 1 ,
290+ resetTime : "2026-10-21T15:17:05Z" ,
291+ } ,
292+ {
293+ bucketId : "5h-edge" ,
294+ window : "5h" ,
295+ remainingFraction : 1 ,
296+ resetTime : "2026-10-21T15:17:04Z" ,
297+ } ,
298+ {
299+ bucketId : "weekly-after" ,
300+ window : "weekly" ,
301+ remainingFraction : 1 ,
302+ resetTime : "2026-10-28T10:17:03Z" ,
303+ } ,
304+ {
305+ bucketId : "weekly-before" ,
306+ window : "weekly" ,
307+ remainingFraction : 1 ,
308+ resetTime : "2026-10-28T10:15:03Z" ,
309+ } ,
310+ {
311+ bucketId : "weekly-edge" ,
312+ window : "weekly" ,
313+ remainingFraction : 1 ,
314+ resetTime : "2026-10-28T10:15:04Z" ,
315+ } ,
316+ ] ,
317+ } ,
318+ } ) ;
319+ expect ( ( yield * probe ) . windows . map ( ( { id, resetsAt } ) => ( { id, resetsAt } ) ) ) . toEqual ( [
320+ { id : "5h-after" , resetsAt : "2026-10-21T15:17:05.000Z" } ,
321+ { id : "5h-before" , resetsAt : undefined } ,
322+ { id : "5h-edge" , resetsAt : undefined } ,
323+ { id : "weekly-after" , resetsAt : undefined } ,
324+ { id : "weekly-before" , resetsAt : "2026-10-28T10:15:03.000Z" } ,
325+ { id : "weekly-edge" , resetsAt : undefined } ,
326+ ] ) ;
327+ } ) . pipe ( Effect . scoped , Effect . provide ( NodeServices . layer ) ) ,
328+ ) ;
329+
330+ // Oracle: the existing endpoint merge keeps the most-used reading.
331+ it . effect ( "keeps the used endpoint reading and its reset over an untouched reading" , ( ) =>
332+ Effect . gen ( function * ( ) {
333+ yield * TestClock . setTime ( DateTime . toEpochMillis ( DateTime . makeUnsafe ( "2026-10-21T10:16:04Z" ) ) ) ;
334+ const { probe } = yield * fixture ( {
335+ summaryByHost : {
336+ "daily-cloudcode-pa.googleapis.com" : {
337+ buckets : [
338+ {
339+ bucketId : "3p-5h" ,
340+ window : "5h" ,
341+ remainingFraction : 1 ,
342+ resetTime : "2026-10-21T15:16:04Z" ,
343+ } ,
344+ {
345+ bucketId : "3p-weekly" ,
346+ window : "weekly" ,
347+ remainingFraction : 0.5 ,
348+ resetTime : "2026-10-27T10:16:04Z" ,
349+ } ,
350+ ] ,
351+ } ,
352+ "cloudcode-pa.googleapis.com" : {
353+ buckets : [
354+ {
355+ bucketId : "3p-5h" ,
356+ window : "5h" ,
357+ remainingFraction : 0.5 ,
358+ resetTime : "2026-10-21T13:16:04Z" ,
359+ } ,
360+ {
361+ bucketId : "3p-weekly" ,
362+ window : "weekly" ,
363+ remainingFraction : 1 ,
364+ resetTime : "2026-10-28T10:16:04Z" ,
365+ } ,
366+ ] ,
367+ } ,
368+ } ,
369+ } ) ;
370+ expect ( ( yield * probe ) . windows ) . toEqual ( [
371+ {
372+ id : "3p-5h" ,
373+ label : "Claude & GPT (shared) · 5-hour" ,
374+ kind : "session" ,
375+ usedPercent : 50 ,
376+ windowDurationMins : 300 ,
377+ resetsAt : "2026-10-21T13:16:04.000Z" ,
378+ } ,
379+ {
380+ id : "3p-weekly" ,
381+ label : "Claude & GPT (shared) · Weekly" ,
382+ kind : "weekly" ,
383+ usedPercent : 50 ,
384+ windowDurationMins : 10080 ,
385+ resetsAt : "2026-10-27T10:16:04.000Z" ,
386+ } ,
387+ ] ) ;
388+ } ) . pipe ( Effect . scoped , Effect . provide ( NodeServices . layer ) ) ,
389+ ) ;
390+
391+ // Oracle: model quotas have no evidence for the summary-only rule.
392+ it . effect ( "keeps full model fallback resets even at a full window from the request" , ( ) =>
393+ Effect . gen ( function * ( ) {
394+ yield * TestClock . setTime ( DateTime . toEpochMillis ( DateTime . makeUnsafe ( "2026-10-21T10:16:04Z" ) ) ) ;
395+ const { probe } = yield * fixture ( {
396+ summaryStatus : 404 ,
397+ models : {
398+ models : {
399+ "gemini-a" : {
400+ quotaInfo : { remainingFraction : 1 , resetTime : "2026-10-21T15:16:04Z" } ,
401+ weeklyQuotaInfo : { remainingFraction : 1 , resetTime : "2026-10-28T10:16:04Z" } ,
402+ } ,
403+ } ,
404+ } ,
405+ } ) ;
406+ expect (
407+ ( yield * probe ) . windows . map ( ( { id, resetsAt, windowDurationMins } ) => ( {
408+ id,
409+ resetsAt,
410+ windowDurationMins,
411+ } ) ) ,
412+ ) . toEqual ( [
413+ { id : "gemini-weekly" , resetsAt : "2026-10-28T10:16:04.000Z" , windowDurationMins : 10080 } ,
414+ { id : "gemini-quota" , resetsAt : "2026-10-21T15:16:04.000Z" , windowDurationMins : undefined } ,
415+ ] ) ;
416+ } ) . pipe ( Effect . scoped , Effect . provide ( NodeServices . layer ) ) ,
417+ ) ;
418+
128419 it . effect ( "reports separate Gemini and shared Claude/GPT five-hour and weekly limits" , ( ) =>
129420 Effect . gen ( function * ( ) {
130421 const { probe, requests } = yield * fixture ( ) ;
0 commit comments