Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

antigravityUsageLimits.test.ts

666 lines25.4 KB

1import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
2import * as NodeServices from "@effect/platform-node/NodeServices";
3import * as Layer from "effect/Layer";
4import { describe, expect, it } from "@effect/vitest";
5import * as Context from "effect/Context";
6import * as DateTime from "effect/DateTime";
7import * as Effect from "effect/Effect";
8import * as FileSystem from "effect/FileSystem";
9import * as Path from "effect/Path";
10import * as TestClock from "effect/testing/TestClock";
11import { FetchHttpClient, HttpClient, HttpClientResponse } from "effect/http";
12​
13import { makeAntigravityUsageProbe } from "./antigravityUsageLimits.ts";
14​
15const summary = {
16 groups: [
17 {
18 displayName: "Gemini Models",
19 buckets: [
20 {
21 bucketId: "gemini-weekly",
22 window: "weekly",
23 remainingFraction: 0.96,
24 resetTime: "2026-10-12T19:41:43Z",
25 },
26 {
27 bucketId: "gemini-5h",
28 window: "5h",
29 remainingFraction: 0.91,
30 resetTime: "2026-10-09T16:06:01Z",
31 },
32 ],
33 },
34 {
35 displayName: "Claude and GPT models",
36 buckets: [
37 {
38 bucketId: "3p-weekly",
39 window: "weekly",
40 remainingFraction: 0,
41 resetTime: "2026-10-10T15:28:22Z",
42 },
43 {
44 bucketId: "3p-5h",
45 window: "5h",
46 remainingFraction: 0.44,
47 resetTime: "2026-10-09T16:06:30Z",
48 },
49 ],
50 },
51 ],
52};
53​
54const fixture = Effect.fn("AntigravityUsageTest.fixture")(function* (
55 options: {
56 summary?: unknown;
57 /** Per-host quota summaries; hosts not listed fall back to `summary`. */
58 summaryByHost?: Record<string, unknown>;
59 models?: unknown;
60 summaryStatus?: number;
61 /** Per-host summary statuses; hosts not listed fall back to `summaryStatus`. */
62 summaryStatusByHost?: Record<string, number>;
63 tokenStatus?: number;
64 refreshToken?: string;
65 userId?: string;
66 userInfoAt?: number;
67 missingToken?: boolean;
68 authMethod?: "oauth-personal" | "oauth-business" | "gemini-api-key";
69 } = {},
70) {
71 const fs = yield* FileSystem.FileSystem;
72 const path = yield* Path.Path;
73 const profileDirectory = yield* fs.makeTempDirectoryScoped();
74 yield* fs.makeDirectory(path.join(profileDirectory, "antigravity-acp"));
75 const tokenPath = path.join(profileDirectory, "antigravity-acp", "acp_token.json");
76 const writeToken = (refreshToken: string) =>
77 fs.writeFileString(
78 tokenPath,
79 JSON.stringify({
80 client_id: "client-id",
81 client_secret: "client-secret",
82 refresh_token: refreshToken,
83 project_id: "project-id",
84 }),
85 );
86 if (!options.missingToken) yield* writeToken(options.refreshToken ?? "refresh-a");
87 const requests: Array<{ url: string; body: string }> = [];
88 const http = HttpClient.make((request, url, _signal, fiber) =>
89 Effect.sync(() => {
90 const init = Context.getOrUndefined(fiber.context, FetchHttpClient.RequestInit);
91 expect(init?.redirect).toBe("manual");
92 const body =
93 request.body._tag === "Uint8Array" ? new TextDecoder().decode(request.body.body) : "";
94 requests.push({ url: request.url, body });
95 if (request.url.endsWith("/token")) {
96 expect(new URLSearchParams(body).get("grant_type")).toBe("refresh_token");
97 return HttpClientResponse.fromWeb(
98 request,
99 Response.json(
100 { access_token: "access-token", expires_in: 3600 },
101 { status: options.tokenStatus ?? 200 },
102 ),
103 );
104 }
105 expect(request.headers.authorization).toBe("Bearer access-token");
106 if (request.url.endsWith("/userinfo")) {
107 return HttpClientResponse.fromWeb(
108 request,
109 options.userId
110 ? Response.json({ id: options.userId, email: "someone@example.com" })
111 : Response.json({}, { status: 403 }),
112 );
113 }
114 expect(JSON.parse(body)).toEqual({ project: "project-id" });
115 expect(request.headers["user-agent"]).toMatch(/^antigravity\/hub\/2\.24\.0 /);
116 return HttpClientResponse.fromWeb(
117 request,
118 request.url.endsWith(":retrieveUserQuotaSummary")
119 ? Response.json(options.summaryByHost?.[url.host] ?? options.summary ?? summary, {
120 status: options.summaryStatusByHost?.[url.host] ?? options.summaryStatus ?? 200,
121 })
122 : Response.json(options.models ?? { models: {} }),
123 );
124 }).pipe(
125 Effect.tap(() =>
126 request.url.endsWith("/userinfo") && options.userInfoAt !== undefined
127 ? TestClock.setTime(options.userInfoAt)
128 : Effect.void,
129 ),
130 ),
131 );
132 const usage = yield* makeAntigravityUsageProbe({
133 profileDirectory,
134 authMethod: options.authMethod ?? "oauth-personal",
135 }).pipe(Effect.provideService(HttpClient.HttpClient, http));
136 return { ...usage, requests, writeToken, tokenPath };
137});
138​
139describe("Antigravity subscription limits", () => {
140 // Oracle: the 10:16 UTC payload and its narrow Workaround rule.
141 it.effect("omits rolling resets for untouched summary buckets and keeps used Gemini resets", () =>
142 Effect.gen(function* () {
143 yield* TestClock.setTime(DateTime.toEpochMillis(DateTime.makeUnsafe("2026-10-21T10:16:04Z")));
144 const { probe } = yield* fixture({
145 summary: {
146 groups: [
147 {
148 buckets: [
149 {
150 bucketId: "3p-5h",
151 window: "5h",
152 remainingFraction: 1,
153 resetTime: "2026-10-21T15:16:05Z",
154 },
155 {
156 bucketId: "3p-weekly",
157 window: "weekly",
158 remainingFraction: 1,
159 resetTime: "2026-10-28T10:16:05Z",
160 },
161 {
162 bucketId: "gemini-5h",
163 window: "5h",
164 remainingFraction: 0.848104,
165 resetTime: "2026-10-21T13:29:53Z",
166 description:
167 "You have used some of your 5-hour limit, it will fully refresh in 3 hours, 13 minutes.",
168 },
169 {
170 bucketId: "gemini-weekly",
171 window: "weekly",
172 remainingFraction: 0.9620177,
173 resetTime: "2026-10-28T08:29:53Z",
174 description:
175 "You have used some of your weekly limit, it will fully refresh in 6 days, 22 hours.",
176 },
177 ],
178 },
179 ],
180 },
181 });
182 const limits = yield* probe;
183 const byId = new Map(limits.windows.map((window) => [window.id, window]));
184 expect(byId.get("3p-5h")).toEqual({
185 id: "3p-5h",
186 label: "Claude & GPT (shared) · 5-hour",
187 kind: "session",
188 usedPercent: 0,
189 windowDurationMins: 300,
190 });
191 expect(byId.get("3p-weekly")).toEqual({
192 id: "3p-weekly",
193 label: "Claude & GPT (shared) · Weekly",
194 kind: "weekly",
195 usedPercent: 0,
196 windowDurationMins: 10080,
197 });
198 expect(byId.get("gemini-5h")?.resetsAt).toBe("2026-10-21T13:29:53.000Z");
199 expect(byId.get("gemini-weekly")?.resetsAt).toBe("2026-10-28T08:29:53.000Z");
200 }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
201 );
202​
203 // Oracle: measure the tolerance from the summary request, after auth.
204 it.effect("uses summary request time after authentication for the reset tolerance", () =>
205 Effect.gen(function* () {
206 yield* TestClock.setTime(DateTime.toEpochMillis(DateTime.makeUnsafe("2026-10-21T10:16:02Z")));
207 const { probe } = yield* fixture({
208 userInfoAt: DateTime.toEpochMillis(DateTime.makeUnsafe("2026-10-21T10:16:04Z")),
209 summary: {
210 buckets: [
211 {
212 bucketId: "3p-5h",
213 window: "5h",
214 remainingFraction: 1,
215 resetTime: "2026-10-21T15:17:03Z",
216 },
217 ],
218 },
219 });
220 expect((yield* probe).windows[0]?.resetsAt).toBeUndefined();
221 }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
222 );
223​
224 // Oracle: keep descriptions, measured resets, and spent buckets.
225 it.effect("keeps summary resets with a description, a distant reset, or no quota left", () =>
226 Effect.gen(function* () {
227 yield* TestClock.setTime(DateTime.toEpochMillis(DateTime.makeUnsafe("2026-10-21T10:16:04Z")));
228 const { probe } = yield* fixture({
229 summary: {
230 buckets: [
231 {
232 bucketId: "described",
233 window: "5h",
234 remainingFraction: 1,
235 description: "Reported reset",
236 resetTime: "2026-10-21T15:16:04Z",
237 },
238 {
239 bucketId: "distant",
240 window: "weekly",
241 remainingFraction: 1,
242 resetTime: "2026-10-28T12:16:04Z",
243 },
244 {
245 bucketId: "spent",
246 window: "5h",
247 remainingFraction: 0,
248 resetTime: "2026-10-21T15:16:04Z",
249 },
250 {
251 bucketId: "overfull",
252 window: "5h",
253 remainingFraction: 1.01,
254 resetTime: "2026-10-21T15:16:04Z",
255 },
256 {
257 bucketId: "empty-description",
258 window: "5h",
259 remainingFraction: 1,
260 description: "",
261 resetTime: "2026-10-21T15:16:04Z",
262 },
263 ],
264 },
265 });
266 expect((yield* probe).windows.map(({ id, resetsAt }) => ({ id, resetsAt }))).toEqual([
267 { id: "described", resetsAt: "2026-10-21T15:16:04.000Z" },
268 { id: "empty-description", resetsAt: "2026-10-21T15:16:04.000Z" },
269 { id: "overfull", resetsAt: "2026-10-21T15:16:04.000Z" },
270 { id: "spent", resetsAt: "2026-10-21T15:16:04.000Z" },
271 { id: "distant", resetsAt: "2026-10-28T12:16:04.000Z" },
272 ]);
273 }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
274 );
275​
276 // Oracle: the 60-second tolerance applies to both known window lengths.
277 it.effect("omits summary resets 59 seconds away but keeps resets 61 seconds away", () =>
278 Effect.gen(function* () {
279 yield* TestClock.setTime(DateTime.toEpochMillis(DateTime.makeUnsafe("2026-10-21T10:16:04Z")));
280 const { probe } = yield* fixture({
281 summary: {
282 buckets: [
283 {
284 bucketId: "5h-before",
285 window: "5h",
286 remainingFraction: 1,
287 resetTime: "2026-10-21T15:15:05Z",
288 },
289 {
290 bucketId: "5h-after",
291 window: "5h",
292 remainingFraction: 1,
293 resetTime: "2026-10-21T15:17:05Z",
294 },
295 {
296 bucketId: "5h-edge",
297 window: "5h",
298 remainingFraction: 1,
299 resetTime: "2026-10-21T15:17:04Z",
300 },
301 {
302 bucketId: "weekly-after",
303 window: "weekly",
304 remainingFraction: 1,
305 resetTime: "2026-10-28T10:17:03Z",
306 },
307 {
308 bucketId: "weekly-before",
309 window: "weekly",
310 remainingFraction: 1,
311 resetTime: "2026-10-28T10:15:03Z",
312 },
313 {
314 bucketId: "weekly-edge",
315 window: "weekly",
316 remainingFraction: 1,
317 resetTime: "2026-10-28T10:15:04Z",
318 },
319 ],
320 },
321 });
322 expect((yield* probe).windows.map(({ id, resetsAt }) => ({ id, resetsAt }))).toEqual([
323 { id: "5h-after", resetsAt: "2026-10-21T15:17:05.000Z" },
324 { id: "5h-before", resetsAt: undefined },
325 { id: "5h-edge", resetsAt: undefined },
326 { id: "weekly-after", resetsAt: undefined },
327 { id: "weekly-before", resetsAt: "2026-10-28T10:15:03.000Z" },
328 { id: "weekly-edge", resetsAt: undefined },
329 ]);
330 }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
331 );
332​
333 // Oracle: workspace sign-ins are metered on cloudcode-pa, so its reading wins even when less used.
334 it.effect("reports a business account's quota from the endpoint it is metered on", () =>
335 Effect.gen(function* () {
336 yield* TestClock.setTime(DateTime.toEpochMillis(DateTime.makeUnsafe("2026-10-21T10:16:04Z")));
337 const { probe } = yield* fixture({
338 authMethod: "oauth-business",
339 summaryByHost: {
340 "daily-cloudcode-pa.googleapis.com": {
341 buckets: [
342 {
343 bucketId: "3p-5h",
344 window: "5h",
345 remainingFraction: 1,
346 resetTime: "2026-10-21T15:16:04Z",
347 },
348 {
349 bucketId: "3p-weekly",
350 window: "weekly",
351 remainingFraction: 0.5,
352 resetTime: "2026-10-27T10:16:04Z",
353 },
354 ],
355 },
356 "cloudcode-pa.googleapis.com": {
357 buckets: [
358 {
359 bucketId: "3p-5h",
360 window: "5h",
361 remainingFraction: 0.5,
362 resetTime: "2026-10-21T13:16:04Z",
363 },
364 {
365 bucketId: "3p-weekly",
366 window: "weekly",
367 remainingFraction: 1,
368 resetTime: "2026-10-28T10:16:04Z",
369 },
370 ],
371 },
372 },
373 });
374 expect((yield* probe).windows).toEqual([
375 {
376 id: "3p-5h",
377 label: "Claude & GPT (shared) · 5-hour",
378 kind: "session",
379 usedPercent: 50,
380 windowDurationMins: 300,
381 resetsAt: "2026-10-21T13:16:04.000Z",
382 },
383 {
384 id: "3p-weekly",
385 label: "Claude & GPT (shared) · Weekly",
386 kind: "weekly",
387 usedPercent: 0,
388 windowDurationMins: 10080,
389 },
390 ]);
391 }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
392 );
393​
394 // Oracle: model quotas have no evidence for the summary-only rule.
395 it.effect("keeps full model fallback resets even at a full window from the request", () =>
396 Effect.gen(function* () {
397 yield* TestClock.setTime(DateTime.toEpochMillis(DateTime.makeUnsafe("2026-10-21T10:16:04Z")));
398 const { probe } = yield* fixture({
399 summaryStatus: 404,
400 models: {
401 models: {
402 "gemini-a": {
403 quotaInfo: { remainingFraction: 1, resetTime: "2026-10-21T15:16:04Z" },
404 weeklyQuotaInfo: { remainingFraction: 1, resetTime: "2026-10-28T10:16:04Z" },
405 },
406 },
407 },
408 });
409 expect(
410 (yield* probe).windows.map(({ id, resetsAt, windowDurationMins }) => ({
411 id,
412 resetsAt,
413 windowDurationMins,
414 })),
415 ).toEqual([
416 { id: "gemini-weekly", resetsAt: "2026-10-28T10:16:04.000Z", windowDurationMins: 10080 },
417 { id: "gemini-quota", resetsAt: "2026-10-21T15:16:04.000Z", windowDurationMins: undefined },
418 ]);
419 }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
420 );
421​
422 it.effect("reports separate Gemini and shared Claude/GPT five-hour and weekly limits", () =>
423 Effect.gen(function* () {
424 const { probe, requests } = yield* fixture();
425 const limits = yield* probe;
426 expect(limits.windows).toHaveLength(4);
427 expect(limits.unavailable).toBeUndefined();
428 expect(limits.credentialFingerprint).toMatch(/^[0-9a-f]{64}$/);
429 const byId = new Map(limits.windows.map((window) => [window.id, window]));
430 expect(byId.get("gemini-weekly")?.usedPercent).toBeCloseTo(4);
431 expect(byId.get("gemini-5h")?.usedPercent).toBeCloseTo(9);
432 expect(byId.get("3p-weekly")).toMatchObject({
433 label: "Claude & GPT (shared) · Weekly",
434 kind: "weekly",
435 usedPercent: 100,
436 windowDurationMins: 10080,
437 resetsAt: "2026-10-10T15:28:22.000Z",
438 });
439 expect(byId.get("3p-5h")).toMatchObject({ kind: "session", windowDurationMins: 300 });
440 expect(byId.get("3p-5h")?.usedPercent).toBeCloseTo(56);
441 yield* probe;
442 expect(requests.filter((request) => request.url.endsWith("/token"))).toHaveLength(1);
443 expect(
444 requests.filter((request) => request.url.endsWith(":retrieveUserQuotaSummary")),
445 ).toHaveLength(4);
446 }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
447 );
448​
449 it.effect("merges quota groups that only one endpoint reports", () =>
450 Effect.gen(function* () {
451 const { probe } = yield* fixture({
452 summaryByHost: {
453 // The daily endpoint can omit Gemini while the other endpoint returns all groups.
454 "daily-cloudcode-pa.googleapis.com": {
455 groups: [
456 {
457 displayName: "Claude and GPT models",
458 buckets: [
459 { bucketId: "3p-weekly", window: "weekly", remainingFraction: 0.5 },
460 { bucketId: "3p-5h", window: "5h", remainingFraction: 0.3 },
461 ],
462 },
463 ],
464 },
465 },
466 });
467 const limits = yield* probe;
468 expect(limits.windows.map((window) => window.id).toSorted()).toEqual([
469 "3p-5h",
470 "3p-weekly",
471 "gemini-5h",
472 "gemini-weekly",
473 ]);
474 const byId = new Map(limits.windows.map((window) => [window.id, window]));
475 expect(byId.get("gemini-weekly")?.label).toBe("Gemini · Weekly");
476 expect(byId.get("3p-5h")?.usedPercent).toBeCloseTo(70);
477 expect(byId.get("3p-weekly")?.usedPercent).toBe(50);
478 }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
479 );
480​
481 // Oracle: reported payloads for a personal sign-in, whose runtime meters on the daily endpoint.
482 it.effect("reports a personal account's quota from the daily endpoint it is metered on", () =>
483 Effect.gen(function* () {
484 yield* TestClock.setTime(DateTime.toEpochMillis(DateTime.makeUnsafe("2026-11-07T12:00:00Z")));
485 const argon = (remainingFraction: number, resetTime: string) => ({
486 groups: [
487 {
488 displayName: "Gemini 4 Argon",
489 buckets: [
490 {
491 bucketId: "gemini-argon-wtu-weekly",
492 window: "weekly",
493 remainingFraction,
494 resetTime,
495 },
496 ],
497 },
498 ],
499 });
500 const { probe } = yield* fixture({
501 authMethod: "oauth-personal",
502 summaryByHost: {
503 "daily-cloudcode-pa.googleapis.com": argon(0.8623059, "2026-11-14T08:41:35Z"),
504 "cloudcode-pa.googleapis.com": argon(0, "2026-11-08T18:27:14Z"),
505 },
506 });
507 expect((yield* probe).windows).toEqual([
508 expect.objectContaining({
509 id: "gemini-argon-wtu-weekly",
510 usedPercent: expect.closeTo(13.77, 2),
511 resetsAt: "2026-11-14T08:41:35.000Z",
512 }),
513 ]);
514 }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
515 );
516​
517 it.effect("labels Argon and Carbon quotas apart from the default Gemini quota", () =>
518 Effect.gen(function* () {
519 const { probe } = yield* fixture({
520 summary: {
521 groups: [
522 ...summary.groups,
523 {
524 displayName: "Gemini 4 Argon",
525 buckets: [
526 { bucketId: "gemini-argon-wtu-weekly", window: "weekly", remainingFraction: 0.6 },
527 ],
528 },
529 {
530 displayName: "Gemini 4 Carbon",
531 buckets: [
532 { bucketId: "gemini-carbon-wtu-weekly", window: "weekly", remainingFraction: 0.4 },
533 ],
534 },
535 {
536 displayName: " ",
537 buckets: [{ bucketId: "gemini-carbon-5h", window: "5h", remainingFraction: 0.8 }],
538 },
539 ],
540 },
541 });
542 const limits = yield* probe;
543 const byId = new Map(limits.windows.map((window) => [window.id, window]));
544 expect(byId.get("gemini-weekly")?.label).toBe("Gemini · Weekly");
545 expect(byId.get("gemini-argon-wtu-weekly")?.label).toBe("Gemini 4 Argon · Weekly");
546 expect(byId.get("gemini-carbon-wtu-weekly")?.label).toBe("Gemini 4 Carbon · Weekly");
547 expect(byId.get("gemini-carbon-5h")?.label).toBe("Gemini Carbon · 5-hour");
548 }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
549 );
550​
551 it.effect("keeps one endpoint's quotas when the other fails", () =>
552 Effect.gen(function* () {
553 const { probe } = yield* fixture({
554 summaryStatusByHost: { "daily-cloudcode-pa.googleapis.com": 503 },
555 });
556 const limits = yield* probe;
557 expect(limits.unavailable).toBeUndefined();
558 expect(limits.windows).toHaveLength(4);
559 }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
560 );
561​
562 it.effect("re-reads changed credentials and clears cached access after sign-out", () =>
563 Effect.gen(function* () {
564 const { probe, clear, requests, writeToken, tokenPath } = yield* fixture();
565 const first = yield* probe;
566 yield* writeToken("refresh-b");
567 const second = yield* probe;
568 expect(second.credentialFingerprint).not.toBe(first.credentialFingerprint);
569 expect(requests.filter((request) => request.url.endsWith("/token"))).toHaveLength(2);
570 yield* (yield* FileSystem.FileSystem).remove(tokenPath);
571 expect((yield* probe).unavailable?.reason).toBe("unsupported");
572 yield* writeToken("refresh-b");
573 yield* probe;
574 expect(requests.filter((request) => request.url.endsWith("/token"))).toHaveLength(3);
575 yield* clear;
576 yield* probe;
577 expect(requests.filter((request) => request.url.endsWith("/token"))).toHaveLength(4);
578 }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
579 );
580​
581 it.effect("names one Google account the same way from every sign-in", () =>
582 Effect.gen(function* () {
583 const read = (refreshToken: string, userId: string) =>
584 fixture({ refreshToken, userId }).pipe(Effect.flatMap((usage) => usage.probe));
585 const machineA = yield* read("refresh-a", "google-user-1");
586 const machineB = yield* read("refresh-b", "google-user-1");
587 const otherAccount = yield* read("refresh-c", "google-user-2");
588 expect(machineA.credentialFingerprint).toMatch(/^[0-9a-f]{64}$/);
589 expect(machineB.credentialFingerprint).toBe(machineA.credentialFingerprint);
590 expect(otherAccount.credentialFingerprint).not.toBe(machineA.credentialFingerprint);
591 expect(JSON.stringify(machineA)).not.toMatch(/google-user-1|someone@example.com/);
592 }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
593 );
594​
595 it.effect("falls back to model quotas without inventing a window duration", () =>
596 Effect.gen(function* () {
597 const { probe } = yield* fixture({
598 summaryStatus: 404,
599 models: {
600 models: {
601 "gemini-a": {
602 modelProvider: "MODEL_PROVIDER_GOOGLE",
603 quotaInfo: { remainingFraction: 0.8, resetTime: "2026-10-10T12:00:00Z" },
604 },
605 "gemini-b": {
606 modelProvider: "MODEL_PROVIDER_GOOGLE",
607 quotaInfo: { remainingFraction: 0.6, resetTime: "2026-10-10T12:00:00Z" },
608 },
609 "claude-a": { quotaInfo: { remainingFraction: 0.2 } },
610 },
611 },
612 });
613 const limits = yield* probe;
614 expect(limits.windows).toHaveLength(2);
615 expect(limits.windows.find((window) => window.id === "gemini-quota")?.usedPercent).toBe(40);
616 expect(
617 limits.windows.every(
618 (window) => window.kind === "other" && window.windowDurationMins === undefined,
619 ),
620 ).toBe(true);
621 }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
622 );
623​
624 it.effect("skips disabled and missing fractions and clamps valid percentages", () =>
625 Effect.gen(function* () {
626 const { probe } = yield* fixture({
627 summary: {
628 buckets: [
629 { bucketId: "disabled", remainingFraction: 0, disabled: true },
630 { bucketId: "missing", resetTime: "2026-10-10T12:00:00Z" },
631 { bucketId: "gemini-5h", window: "5h", remainingFraction: 2, resetTime: "invalid" },
632 ],
633 },
634 });
635 expect((yield* probe).windows).toEqual([
636 {
637 id: "gemini-5h",
638 kind: "session",
639 label: "Gemini · 5-hour",
640 usedPercent: 0,
641 windowDurationMins: 300,
642 },
643 ]);
644 }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
645 );
646​
647 it.effect("returns a safe failure when OAuth refresh fails", () =>
648 Effect.gen(function* () {
649 const { probe } = yield* fixture({ tokenStatus: 401 });
650 const limits = yield* probe;
651 expect(limits.windows).toEqual([]);
652 expect(limits.unavailable?.reason).toBe("probeFailed");
653 expect(JSON.stringify(limits)).not.toMatch(/client-secret|refresh-a|access-token/);
654 }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
655 );
656​
657 it.effect("does not make network requests for API keys or missing sign-ins", () =>
658 Effect.gen(function* () {
659 for (const options of [{ authMethod: "gemini-api-key" as const }, { missingToken: true }]) {
660 const { probe, requests } = yield* fixture(options);
661 expect((yield* probe).unavailable?.reason).toBe("unsupported");
662 expect(requests).toEqual([]);
663 }
664 }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
665 );
666});