Open History to see the last commit
1import * as NodeServices from "@effect/platform-node/NodeServices";
2import { describe, expect, it } from "@effect/vitest";
3import {
4 ANTIGRAVITY_DEFAULT_MODEL,
5 AntigravitySettings,
6 ProviderDriverKind,
7 ProviderInstanceId,
8 ProviderSetupError,
9 type ServerProviderUsageLimits,
10} from "@t3tools/contracts";
11import * as Deferred from "effect/Deferred";
12import * as Effect from "effect/Effect";
13import * as Fiber from "effect/Fiber";
14import * as Layer from "effect/Layer";
15import * as Ref from "effect/Ref";
16import * as Schema from "effect/Schema";
17import * as Stream from "effect/Stream";
18import * as EffectAcpErrors from "effect-acp/errors";
19import type * as EffectAcpSchema from "effect-acp/compat";
20
21import * as BackgroundPolicy from "../background/BackgroundPolicy.ts";
22import * as ServerConfig from "../config.ts";
23import * as ServerSettings from "../serverSettings.ts";
24import * as ProviderHostLive from "./ProviderHostLive.ts";
25import * as ServerSecretStore from "../auth/ServerSecretStore.ts";
26import type * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime";
27import {
28 buildAntigravityModelsFromSession,
29 makeAntigravityProvider,
30} from "./AntigravityProvider.ts";
31
32const decodeSettings = Schema.decodeSync(AntigravitySettings);
33const instanceId = ProviderInstanceId.make("antigravity-test");
34const driver = ProviderDriverKind.make("antigravity");
35
36const initializeResult = {
37 protocolVersion: 1,
38 agentCapabilities: {
39 loadSession: true,
40 promptCapabilities: { image: true, audio: true, embeddedContext: true },
41 sessionCapabilities: { list: {}, resume: {} },
42 },
43 authMethods: [{ id: "oauth-personal", name: "Log in with Google" }],
44 agentInfo: {
45 name: "antigravity-acp",
46 title: "Google Antigravity",
47 version: "agy_acp_server_20260818_01_RC01",
48 },
49} satisfies EffectAcpSchema.InitializeResponse;
50
51const modelOptions = [
52 { value: "gemini-3.8-flash-high", name: "Gemini 3.8 Flash (High)" },
53 { value: "gemini-3.8-flash-medium", name: "Gemini 3.8 Flash (Medium)" },
54 { value: "gemini-3.8-flash-low", name: "Gemini 3.8 Flash (Low)" },
55 { value: "gemini-3.7-flash-high", name: "Gemini 3.7 Flash (High)" },
56 { value: "gemini-3.7-flash-medium", name: "Gemini 3.7 Flash (Medium)" },
57 { value: "gemini-3.7-flash-low", name: "Gemini 3.7 Flash (Low)" },
58 { value: "gemini-3.6-flash-high", name: "Gemini 3.6 Flash (High)" },
59 { value: "gemini-3.6-flash-medium", name: "Gemini 3.6 Flash (Medium)" },
60 { value: "gemini-3.6-flash-low", name: "Gemini 3.6 Flash (Low)" },
61 { value: "gemini-pro-agent", name: "Gemini 3.1 Pro (High)" },
62 { value: "gemini-3.1-pro-low", name: "Gemini 3.1 Pro (Low)" },
63];
64
65const modelConfig = {
66 id: "model",
67 name: "Model",
68 category: "model",
69 type: "select",
70 currentValue: "gemini-3.7-flash-high",
71 options: modelOptions,
72} satisfies EffectAcpSchema.SessionConfigOption;
73
74const sessionSetupResult = {
75 sessionId: "session-1",
76 models: {
77 currentModelId: "gemini-3.7-flash-high",
78 availableModels: modelOptions.map((option) => ({ modelId: option.value, name: option.name })),
79 },
80 configOptions: [
81 modelConfig,
82 {
83 id: "mode",
84 name: "Session Mode",
85 category: "mode",
86 type: "select",
87 currentValue: "default",
88 options: [
89 { value: "default", name: "Default" },
90 { value: "yolo", name: "YOLO" },
91 ],
92 },
93 ],
94} satisfies EffectAcpSchema.NewSessionResponse;
95
96const started = {
97 sessionId: "session-1",
98 initializeResult,
99 sessionSetupResult,
100 modelConfigId: "model",
101} satisfies AcpSessionRuntime.AcpSessionRuntimeStartResult;
102
103const commands = [
104 { name: "plan", description: "Create a plan", input: { type: "text", hint: "What to plan" } },
105 { name: "logout", description: "Sign out of Google" },
106] satisfies ReadonlyArray<EffectAcpSchema.AvailableCommand>;
107
108const expectedCommands = [
109 { name: "plan", description: "Create a plan", input: { hint: "What to plan" } },
110 { name: "logout", description: "Sign out of Google" },
111];
112
113const layerTest = ProviderHostLive.layer.pipe(
114 Layer.provideMerge(
115 Layer.mock(BackgroundPolicy.BackgroundPolicy)({
116 shouldRunScopeWork: () => Effect.succeed(false),
117 }),
118 ),
119 Layer.provideMerge(ServerSettings.layerTest()),
120 Layer.provideMerge(ServerSecretStore.layer),
121 Layer.provide(
122 ServerConfig.layerTest(process.cwd(), { prefix: "t3-antigravity-provider-test-" }).pipe(
123 Layer.provideMerge(NodeServices.layer),
124 ),
125 ),
126);
127
128type ProbeError = EffectAcpErrors.AcpError | ProviderSetupError;
129
130const makeHarness = Effect.fn("makeAntigravityProviderHarness")(function* (
131 options: {
132 readonly enabled?: boolean;
133 readonly safe?: boolean;
134 readonly probeUsage?: Effect.Effect<ServerProviderUsageLimits>;
135 } = {},
136) {
137 const initialProbe = yield* Deferred.make<EffectAcpSchema.InitializeResponse, ProbeError>();
138 const probeCalls = yield* Ref.make(0);
139 const safetyCalls = yield* Ref.make(0);
140 const probe = yield* Ref.make<Effect.Effect<EffectAcpSchema.InitializeResponse, ProbeError>>(
141 Deferred.await(initialProbe),
142 );
143 const safety = yield* Ref.make<Effect.Effect<boolean>>(Effect.succeed(options.safe ?? true));
144 const provider = yield* makeAntigravityProvider(
145 decodeSettings({ enabled: options.enabled ?? true, customModels: ["do-not-seed-me"] }),
146 {
147 stampIdentity: (snapshot) => Effect.succeed({ ...snapshot, instanceId, driver }),
148 ...(options.probeUsage ? { probeUsage: options.probeUsage } : {}),
149 probe: Ref.update(probeCalls, (count) => count + 1).pipe(
150 Effect.andThen(Ref.get(probe)),
151 Effect.flatten,
152 ),
153 supportsTextGeneration: Ref.update(safetyCalls, (count) => count + 1).pipe(
154 Effect.andThen(Ref.get(safety)),
155 Effect.flatten,
156 ),
157 },
158 );
159 const initialUpdate = yield* Stream.toPull(
160 provider.snapshot.streamChanges.pipe(
161 Stream.filter((snapshot) => snapshot.installed || snapshot.status === "error"),
162 ),
163 );
164 const initialize = Deferred.succeed(initialProbe, initializeResult).pipe(
165 Effect.andThen(initialUpdate),
166 Effect.asVoid,
167 );
168 return {
169 provider,
170 probe,
171 probeCalls,
172 safety,
173 safetyCalls,
174 initialProbe,
175 initialUpdate,
176 initialize,
177 };
178});
179
180describe("Antigravity model catalog", () => {
181 it("uses legacy session models only when model config is absent", () => {
182 const fromLegacy = buildAntigravityModelsFromSession({
183 models: sessionSetupResult.models,
184 });
185 expect(fromLegacy).toEqual(buildAntigravityModelsFromSession(sessionSetupResult));
186 expect(
187 buildAntigravityModelsFromSession({
188 ...sessionSetupResult,
189 configOptions: [{ ...modelConfig, options: [] }],
190 }),
191 ).toEqual([]);
192 });
193
194 it("flattens native option groups without combining distinct model IDs", () => {
195 const models = buildAntigravityModelsFromSession({
196 configOptions: [
197 {
198 ...modelConfig,
199 currentValue: "gemini-pro-agent",
200 options: [
201 { groupId: "Flash", name: "Flash", options: [modelOptions[3]!, modelOptions[4]!] },
202 { groupId: "Pro", name: "Pro", options: [modelOptions[9]!, modelOptions[3]!] },
203 ],
204 },
205 ],
206 });
207 expect(models.map((model) => model.slug)).toEqual([
208 "gemini-3.7-flash-high",
209 "gemini-3.7-flash-medium",
210 "gemini-pro-agent",
211 ]);
212 expect(models.find((model) => model.isDefault)?.slug).toBe("gemini-pro-agent");
213 expect(models.find((model) => model.aliases?.includes(ANTIGRAVITY_DEFAULT_MODEL))?.slug).toBe(
214 "gemini-pro-agent",
215 );
216 });
217
218 it("labels models that share a display name with their IDs", () => {
219 const models = buildAntigravityModelsFromSession({
220 configOptions: [
221 {
222 ...modelConfig,
223 currentValue: "gemini-3.8-flash",
224 options: [
225 { value: "gemini-3.8-flash", name: "Gemini 3.8 Flash" },
226 { value: "gemini-3.8-flash-preview", name: "Gemini 3.8 Flash" },
227 ],
228 },
229 ],
230 });
231 expect(models.map((model) => model.name)).toEqual([
232 "Gemini 3.8 Flash",
233 "Gemini 3.8 Flash (gemini-3.8-flash-preview)",
234 ]);
235 });
236
237 it("offers each model the thinking levels it reported when selected", () => {
238 const thinking = (currentValue: string) =>
239 ({
240 id: "thinking_level",
241 name: "Thinking Level",
242 category: "thought_level",
243 type: "select",
244 currentValue,
245 options: [
246 { value: "low", name: "Low" },
247 { value: "high", name: "High" },
248 ],
249 }) satisfies EffectAcpSchema.SessionConfigOption;
250 const models = buildAntigravityModelsFromSession(
251 {
252 configOptions: [
253 {
254 ...modelConfig,
255 currentValue: "gemini",
256 options: [
257 { value: "gemini", name: "Gemini" },
258 { value: "claude", name: "Claude" },
259 { value: "plain", name: "Plain" },
260 { value: "unseen", name: "Unseen" },
261 ],
262 },
263 thinking("high"),
264 ],
265 },
266 new Map([
267 ["claude", thinking("low")],
268 ["plain", null],
269 ]),
270 );
271 const thinkingOf = (slug: string) =>
272 models.find((model) => model.slug === slug)?.capabilities?.optionDescriptors?.[0];
273
274 expect(thinkingOf("gemini")).toMatchObject({ id: "thinking_level", currentValue: "high" });
275 expect(thinkingOf("claude")).toMatchObject({ id: "thinking_level", currentValue: "low" });
276 expect(thinkingOf("plain")).toBeUndefined();
277 expect(thinkingOf("unseen")).toMatchObject({ id: "thinking_level" });
278 expect(thinkingOf("unseen")).not.toHaveProperty("currentValue");
279 });
280});
281
282it.layer(layerTest)("Antigravity provider snapshots", (it) => {
283 it.effect("does not probe or run helper safety checks while disabled", () =>
284 Effect.scoped(
285 Effect.gen(function* () {
286 const harness = yield* makeHarness({ enabled: false });
287 const snapshot = yield* harness.provider.snapshot.refresh;
288 expect(snapshot).toMatchObject({
289 enabled: false,
290 installed: false,
291 status: "disabled",
292 auth: { status: "unknown" },
293 models: [],
294 setup: { canAuthenticate: true, canInstall: true },
295 showInteractionModeToggle: false,
296 supportsConversationRollback: false,
297 supportsTextGeneration: false,
298 });
299 expect(yield* Ref.get(harness.probeCalls)).toBe(0);
300 expect(yield* Ref.get(harness.safetyCalls)).toBe(0);
301 }),
302 ),
303 );
304
305 it.effect("treats initialize as installation proof, not account or model discovery", () =>
306 Effect.scoped(
307 Effect.gen(function* () {
308 const harness = yield* makeHarness();
309 expect(yield* harness.provider.snapshot.getSnapshot).toMatchObject({
310 installed: false,
311 status: "warning",
312 auth: { status: "unknown" },
313 models: [],
314 });
315 yield* harness.initialize;
316 const snapshot = yield* harness.provider.snapshot.getSnapshot;
317 expect(snapshot).toMatchObject({
318 installed: true,
319 status: "warning",
320 version: "agy_acp_server_20260818_01_RC01",
321 auth: { status: "unknown" },
322 models: [],
323 });
324 expect(yield* Ref.get(harness.probeCalls)).toBe(1);
325 }),
326 ),
327 );
328
329 it.effect("publishes session metadata and native commands without another health probe", () =>
330 Effect.scoped(
331 Effect.gen(function* () {
332 const harness = yield* makeHarness();
333 yield* harness.initialize;
334 const nextReady = yield* Stream.toPull(
335 harness.provider.snapshot.streamChanges.pipe(
336 Stream.filter(
337 (snapshot) =>
338 snapshot.auth.status === "authenticated" && snapshot.slashCommands.length > 0,
339 ),
340 ),
341 );
342 yield* harness.provider.onSessionStarted(started, "/workspace");
343 yield* harness.provider.onAvailableCommands(commands, "/workspace");
344 const [snapshot] = yield* nextReady;
345 expect(snapshot).toMatchObject({
346 status: "ready",
347 auth: { status: "authenticated", type: "oauth-personal" },
348 supportsTextGeneration: true,
349 });
350 expect(snapshot.models).toEqual(buildAntigravityModelsFromSession(sessionSetupResult));
351 expect(snapshot.slashCommands).toEqual(expectedCommands);
352 expect((yield* harness.provider.snapshotForCwd("/workspace")).slashCommands).toEqual(
353 expectedCommands,
354 );
355 expect(yield* Ref.get(harness.probeCalls)).toBe(1);
356 }),
357 ),
358 );
359
360 it.effect("clears all account metadata on sign-out and authentication failure", () =>
361 Effect.scoped(
362 Effect.gen(function* () {
363 const harness = yield* makeHarness();
364 yield* harness.initialize;
365 for (const clear of [harness.provider.onSignedOut, harness.provider.onAuthRequired]) {
366 yield* harness.provider.onSessionStarted(started, "/workspace");
367 yield* harness.provider.onAvailableCommands(commands, "/workspace");
368 yield* clear;
369 expect(yield* harness.provider.snapshot.getSnapshot).toMatchObject({
370 installed: true,
371 status: "warning",
372 auth: { status: "unauthenticated" },
373 models: [],
374 slashCommands: [],
375 skills: [],
376 workspaceSnapshots: [],
377 supportsTextGeneration: false,
378 });
379 yield* harness.provider.onAvailableCommands(commands, "/workspace");
380 yield* harness.provider.onConfigOptionsUpdated([modelConfig]);
381 expect((yield* harness.provider.snapshotForCwd("/workspace")).slashCommands).toEqual([]);
382 expect((yield* harness.provider.snapshot.getSnapshot).models).toEqual([]);
383 }
384 const refreshed = yield* harness.provider.snapshot.refresh;
385 expect(refreshed.auth.status).toBe("unauthenticated");
386 expect(refreshed.supportsTextGeneration).toBe(false);
387 }),
388 ),
389 );
390
391 it.effect("replaces live model choices and accepts an empty catalog", () =>
392 Effect.scoped(
393 Effect.gen(function* () {
394 const harness = yield* makeHarness();
395 yield* harness.initialize;
396 yield* harness.provider.onSessionStarted(started, "/workspace");
397 yield* harness.provider.onAvailableCommands(commands, "/workspace");
398 const before = yield* harness.provider.snapshot.getSnapshot;
399 const configOptions = [
400 {
401 ...modelConfig,
402 currentValue: "gemini-3.8-flash-high",
403 options: modelOptions.slice(0, 3),
404 },
405 ];
406 const nextSnapshot = yield* Stream.toPull(
407 harness.provider.snapshot.streamChanges.pipe(
408 Stream.filter((snapshot) => snapshot.models.length === 3),
409 ),
410 );
411 yield* harness.provider.onConfigOptionsUpdated(configOptions);
412 expect((yield* nextSnapshot)[0]).toMatchObject({
413 models: buildAntigravityModelsFromSession({ configOptions }),
414 auth: before.auth,
415 workspaceSnapshots: before.workspaceSnapshots,
416 slashCommands: expectedCommands,
417 });
418 yield* harness.provider.onConfigOptionsUpdated([]);
419 expect((yield* harness.provider.snapshot.getSnapshot).models).toEqual([]);
420 }),
421 ),
422 );
423
424 it.effect("does not guess a version before a custom launcher's first handshake", () =>
425 Effect.scoped(
426 Effect.gen(function* () {
427 const harness = yield* makeHarness();
428 yield* Deferred.succeed(harness.initialProbe, {
429 ...initializeResult,
430 agentInfo: { ...initializeResult.agentInfo, version: "unknown" },
431 });
432 yield* harness.initialUpdate;
433 expect((yield* harness.provider.snapshot.getSnapshot).version).toBeNull();
434 }),
435 ),
436 );
437
438 it.effect("does not replace a handshake version with an unknown custom-launcher probe", () =>
439 Effect.scoped(
440 Effect.gen(function* () {
441 const harness = yield* makeHarness();
442 yield* harness.initialize;
443 yield* harness.provider.onSessionStarted({
444 ...started,
445 initializeResult: {
446 ...initializeResult,
447 agentInfo: { ...initializeResult.agentInfo, version: "1.4.0" },
448 },
449 });
450 yield* Ref.set(
451 harness.probe,
452 Effect.succeed({
453 ...initializeResult,
454 agentInfo: { ...initializeResult.agentInfo, version: "unknown" },
455 }),
456 );
457 expect((yield* harness.provider.snapshot.refresh).version).toBe("1.4.0");
458 }),
459 ),
460 );
461
462 it.effect("replaces one account's catalog instead of combining accounts", () =>
463 Effect.scoped(
464 Effect.gen(function* () {
465 const harness = yield* makeHarness();
466 yield* harness.initialize;
467 yield* harness.provider.onSessionStarted(started);
468 yield* harness.provider.onSignedOut;
469 yield* harness.provider.onSessionStarted({
470 ...started,
471 sessionSetupResult: {
472 sessionId: "new-account-session",
473 configOptions: [
474 { ...modelConfig, currentValue: "gemini-pro-agent", options: [modelOptions[9]!] },
475 ],
476 },
477 });
478 expect(
479 (yield* harness.provider.snapshot.getSnapshot).models.map((model) => model.slug),
480 ).toEqual(["gemini-pro-agent"]);
481 }),
482 ),
483 );
484
485 it.effect("retains known account metadata when a local health check fails", () =>
486 Effect.scoped(
487 Effect.gen(function* () {
488 const harness = yield* makeHarness();
489 yield* harness.initialize;
490 yield* harness.provider.onSessionStarted(started, "/workspace");
491 yield* harness.provider.onAvailableCommands(commands, "/workspace");
492 yield* Ref.set(
493 harness.probe,
494 Effect.fail(EffectAcpErrors.AcpRequestError.internalError("probe failed")),
495 );
496 const snapshot = yield* harness.provider.snapshot.refresh;
497 expect(snapshot).toMatchObject({
498 installed: true,
499 status: "error",
500 auth: { status: "authenticated" },
501 });
502 expect(snapshot.models).toEqual(buildAntigravityModelsFromSession(sessionSetupResult));
503 expect(snapshot.slashCommands).toEqual(expectedCommands);
504 expect(snapshot.workspaceSnapshots?.[0]?.cwd).toBe("/workspace");
505 }),
506 ),
507 );
508
509 it.effect("distinguishes missing executables from a failed installed executable", () =>
510 Effect.scoped(
511 Effect.gen(function* () {
512 const harness = yield* makeHarness();
513 yield* harness.initialize;
514 const failures = [
515 {
516 error: new EffectAcpErrors.AcpSpawnError({ cause: { code: "ENOENT" } }),
517 installed: false,
518 },
519 {
520 error: new EffectAcpErrors.AcpSpawnError({ cause: { code: "EACCES" } }),
521 installed: true,
522 },
523 {
524 error: new ProviderSetupError({
525 instanceId,
526 operation: "resolve",
527 detail: "Antigravity is not installed.",
528 }),
529 installed: false,
530 },
531 ];
532 for (const { error, installed } of failures) {
533 yield* harness.provider.onSessionStarted(started, "/workspace");
534 yield* harness.provider.onAvailableCommands(commands, "/workspace");
535 yield* Ref.set(harness.probe, Effect.fail(error));
536 const snapshot = yield* harness.provider.snapshot.refresh;
537 expect(snapshot).toMatchObject({
538 installed,
539 status: "error",
540 auth: { status: "authenticated" },
541 });
542 expect(snapshot.models).toHaveLength(installed ? 11 : 0);
543 expect(snapshot.slashCommands).toHaveLength(installed ? 2 : 0);
544 expect(snapshot.workspaceSnapshots).toHaveLength(installed ? 1 : 0);
545 expect(snapshot.supportsTextGeneration).toBe(installed);
546 }
547 }),
548 ),
549 );
550
551 it.effect("does not let an old health result restore a signed-out account", () =>
552 Effect.scoped(
553 Effect.gen(function* () {
554 const harness = yield* makeHarness();
555 yield* harness.initialize;
556 yield* harness.provider.onSessionStarted(started);
557 const releaseProbe = yield* Deferred.make<EffectAcpSchema.InitializeResponse>();
558 const probeEntered = yield* Deferred.make<void>();
559 yield* Ref.set(
560 harness.probe,
561 Deferred.succeed(probeEntered, undefined).pipe(
562 Effect.andThen(Deferred.await(releaseProbe)),
563 ),
564 );
565 const refresh = yield* harness.provider.snapshot.refresh.pipe(Effect.forkChild);
566 yield* Deferred.await(probeEntered);
567 yield* harness.provider.onSignedOut;
568 yield* Deferred.succeed(releaseProbe, initializeResult);
569 const snapshot = yield* Fiber.join(refresh);
570 expect(snapshot).toMatchObject({
571 auth: { status: "unauthenticated" },
572 models: [],
573 supportsTextGeneration: false,
574 });
575 }),
576 ),
577 );
578
579 it.effect("exposes helper support only when the supplied safety check allows it", () =>
580 Effect.scoped(
581 Effect.gen(function* () {
582 const harness = yield* makeHarness({ safe: false });
583 yield* harness.initialize;
584 yield* harness.provider.onSessionStarted(started);
585 expect((yield* harness.provider.snapshot.getSnapshot).supportsTextGeneration).toBe(false);
586 yield* Ref.set(harness.safety, Effect.succeed(true));
587 yield* harness.provider.snapshot.refresh;
588 expect((yield* harness.provider.snapshot.getSnapshot).supportsTextGeneration).toBe(true);
589 }),
590 ),
591 );
592
593 it.effect("keeps discovered workspace skills through session and command updates", () =>
594 Effect.scoped(
595 Effect.gen(function* () {
596 const harness = yield* makeHarness();
597 yield* harness.initialize;
598 const skills = [
599 {
600 name: "deploy",
601 description: "Ship it",
602 path: "/workspace/.agent/skills/deploy",
603 enabled: true,
604 },
605 ];
606 const discovered = yield* harness.provider.snapshotForCwd("/workspace", skills);
607 expect(discovered.skills).toEqual(skills);
608 yield* harness.provider.onSessionStarted(started, "/workspace");
609 yield* harness.provider.onAvailableCommands(commands, "/workspace");
610 const after = yield* harness.provider.snapshot.getSnapshot;
611 expect(
612 after.workspaceSnapshots?.find((entry) => entry.cwd === "/workspace")?.skills,
613 ).toEqual(skills);
614 expect((yield* harness.provider.snapshotForCwd("/workspace")).skills).toEqual(skills);
615
616 const rescanned = [
617 ...skills,
618 { name: "review", path: "/workspace/.agent/skills/review", enabled: true },
619 ];
620 yield* harness.provider.snapshotForCwd("/workspace", rescanned);
621 yield* harness.provider.onSessionStarted(started, "/workspace");
622 expect(
623 (yield* harness.provider.snapshot.getSnapshot).workspaceSnapshots?.find(
624 (entry) => entry.cwd === "/workspace",
625 )?.skills,
626 ).toEqual(rescanned);
627 }),
628 ),
629 );
630
631 it.effect("bounds workspace metadata without starting sessions for workspace lookup", () =>
632 Effect.scoped(
633 Effect.gen(function* () {
634 const harness = yield* makeHarness();
635 yield* harness.initialize;
636 yield* harness.provider.onSessionStarted(started);
637 for (let index = 0; index < 35; index++) {
638 yield* harness.provider.onAvailableCommands(commands, `/workspace-${index}`);
639 }
640 const snapshot = yield* harness.provider.snapshotForCwd("/workspace-34");
641 expect(snapshot.workspaceSnapshots).toHaveLength(32);
642 expect(snapshot.workspaceSnapshots?.[0]?.cwd).toBe("/workspace-3");
643 expect(snapshot.slashCommands).toEqual(expectedCommands);
644 expect(yield* Ref.get(harness.probeCalls)).toBe(1);
645 }),
646 ),
647 );
648
649 it.effect(
650 "publishes limits, retains a successful read on failure, and clears them on sign-out",
651 () =>
652 Effect.scoped(
653 Effect.gen(function* () {
654 const limits: ServerProviderUsageLimits = {
655 checkedAt: "2026-10-09T12:00:00.000Z",
656 windows: [
657 {
658 id: "3p-weekly",
659 kind: "weekly",
660 label: "Claude & GPT (shared) · Weekly",
661 usedPercent: 75,
662 },
663 ],
664 };
665 const usage = yield* Ref.make(limits);
666 const harness = yield* makeHarness({ probeUsage: Ref.get(usage) });
667 yield* harness.initialize;
668 expect((yield* harness.provider.snapshot.getSnapshot).usageLimits).toEqual(limits);
669 yield* Ref.set(harness.probe, Effect.succeed(initializeResult));
670 yield* Ref.set(usage, {
671 checkedAt: "2026-10-09T12:01:00.000Z",
672 windows: [],
673 unavailable: { reason: "probeFailed" },
674 });
675 expect((yield* harness.provider.snapshot.refresh).usageLimits).toEqual(limits);
676 yield* harness.provider.onSignedOut;
677 expect((yield* harness.provider.snapshot.getSnapshot).usageLimits).toBeUndefined();
678 yield* Ref.set(usage, {
679 checkedAt: "2026-10-09T12:02:00.000Z",
680 windows: [],
681 unavailable: { reason: "unsupported" },
682 });
683 expect((yield* harness.provider.snapshot.refresh).usageLimits?.windows).toEqual([]);
684 }),
685 ),
686 );
687
688 it.effect("a quota read finishing after sign-out cannot restore account limits", () =>
689 Effect.scoped(
690 Effect.gen(function* () {
691 const readStarted = yield* Deferred.make<void>();
692 const readResult = yield* Deferred.make<ServerProviderUsageLimits>();
693 const usage = yield* Ref.make<Effect.Effect<ServerProviderUsageLimits>>(
694 Effect.succeed({ checkedAt: "2026-10-09T12:00:00.000Z", windows: [] }),
695 );
696 const harness = yield* makeHarness({ probeUsage: Ref.get(usage).pipe(Effect.flatten) });
697 yield* harness.initialize;
698 yield* Ref.set(harness.probe, Effect.succeed(initializeResult));
699 yield* Ref.set(
700 usage,
701 Deferred.succeed(readStarted, undefined).pipe(Effect.andThen(Deferred.await(readResult))),
702 );
703 const refresh = yield* harness.provider.snapshot.refresh.pipe(Effect.forkChild);
704 yield* Deferred.await(readStarted);
705 yield* harness.provider.onSignedOut;
706 yield* Deferred.succeed(readResult, {
707 checkedAt: "2026-10-09T12:01:00.000Z",
708 windows: [
709 { id: "gemini-5h", kind: "session", label: "Gemini · 5-hour", usedPercent: 10 },
710 ],
711 });
712 yield* Fiber.join(refresh);
713 expect((yield* harness.provider.snapshot.getSnapshot).usageLimits).toBeUndefined();
714 }),
715 ),
716 );
717});