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

AntigravityProvider.test.ts

998 lines38.5 KB

1import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
2import * as NodeServices from "@effect/platform-node/NodeServices";
3import { describe, expect, it } from "@effect/vitest";
4import {
5 ANTIGRAVITY_DEFAULT_MODEL,
6 AntigravitySettings,
7 ProviderDriverKind,
8 ProviderInstanceId,
9 ProviderSetupError,
10 type RuntimeMode,
11 type ServerProviderUsageLimits,
12} from "@t3tools/contracts";
13import * as Deferred from "effect/Deferred";
14import * as Effect from "effect/Effect";
15import * as Fiber from "effect/Fiber";
16import * as Layer from "effect/Layer";
17import * as Ref from "effect/Ref";
18import * as Schema from "effect/Schema";
19import * as Stream from "effect/Stream";
20import * as TestClock from "effect/testing/TestClock";
21import * as EffectAcpErrors from "effect-acp/errors";
22import type * as EffectAcpSchema from "effect-acp/compat";
23​
24import * as BackgroundPolicy from "../background/BackgroundPolicy.ts";
25import * as ServerConfig from "../config.ts";
26import * as ServerSettings from "../serverSettings.ts";
27import * as ProviderHostLive from "./ProviderHostLive.ts";
28import * as ServerSecretStore from "../auth/ServerSecretStore.ts";
29import type * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime";
30import type { ServerProvider } from "@t3tools/contracts";
31import {
32 buildAntigravityModelsFromSession,
33 makeAntigravityProvider,
34} from "./AntigravityProvider.ts";
35import { mergeProviderSnapshot } from "./ProviderRegistry.ts";
36​
37const decodeSettings = Schema.decodeSync(AntigravitySettings);
38const instanceId = ProviderInstanceId.make("antigravity-test");
39const driver = ProviderDriverKind.make("antigravity");
40​
41const initializeResult = {
42 protocolVersion: 1,
43 agentCapabilities: {
44 loadSession: true,
45 promptCapabilities: { image: true, audio: true, embeddedContext: true },
46 sessionCapabilities: { list: {}, resume: {} },
47 },
48 authMethods: [{ id: "oauth-personal", name: "Log in with Google" }],
49 agentInfo: {
50 name: "antigravity-acp",
51 title: "Google Antigravity",
52 version: "1.5.12",
53 },
54} satisfies EffectAcpSchema.InitializeResponse;
55​
56const modelOptions = [
57 { value: "gemini-3.8-flash-high", name: "Gemini 3.8 Flash (High)" },
58 { value: "gemini-3.8-flash-medium", name: "Gemini 3.8 Flash (Medium)" },
59 { value: "gemini-3.8-flash-low", name: "Gemini 3.8 Flash (Low)" },
60 { value: "gemini-3.7-flash-high", name: "Gemini 3.7 Flash (High)" },
61 { value: "gemini-3.7-flash-medium", name: "Gemini 3.7 Flash (Medium)" },
62 { value: "gemini-3.7-flash-low", name: "Gemini 3.7 Flash (Low)" },
63 { value: "gemini-3.6-flash-high", name: "Gemini 3.6 Flash (High)" },
64 { value: "gemini-3.6-flash-medium", name: "Gemini 3.6 Flash (Medium)" },
65 { value: "gemini-3.6-flash-low", name: "Gemini 3.6 Flash (Low)" },
66 { value: "gemini-pro-agent", name: "Gemini 3.1 Pro (High)" },
67 { value: "gemini-3.1-pro-low", name: "Gemini 3.1 Pro (Low)" },
68];
69​
70const modelConfig = {
71 id: "model",
72 name: "Model",
73 category: "model",
74 type: "select",
75 currentValue: "gemini-3.7-flash-high",
76 options: modelOptions,
77} satisfies EffectAcpSchema.SessionConfigOption;
78​
79const sessionSetupResult = {
80 sessionId: "session-1",
81 models: {
82 currentModelId: "gemini-3.7-flash-high",
83 availableModels: modelOptions.map((option) => ({ modelId: option.value, name: option.name })),
84 },
85 configOptions: [
86 modelConfig,
87 {
88 id: "mode",
89 name: "Session Mode",
90 category: "mode",
91 type: "select",
92 currentValue: "default",
93 options: [
94 { value: "default", name: "Default" },
95 { value: "yolo", name: "YOLO" },
96 ],
97 },
98 ],
99} satisfies EffectAcpSchema.NewSessionResponse;
100​
101const started = {
102 sessionId: "session-1",
103 initializeResult,
104 sessionSetupResult,
105 modelConfigId: "model",
106} satisfies AcpSessionRuntime.AcpSessionRuntimeStartResult;
107​
108const commands = [
109 { name: "plan", description: "Create a plan", input: { type: "text", hint: "What to plan" } },
110 { name: "logout", description: "Sign out of Google" },
111] satisfies ReadonlyArray<EffectAcpSchema.AvailableCommand>;
112​
113const expectedCommands = [
114 { name: "plan", description: "Create a plan", input: { hint: "What to plan" } },
115 { name: "logout", description: "Sign out of Google" },
116];
117​
118const makeLayerTest = (runBackgroundWork: boolean) =>
119 ProviderHostLive.layer.pipe(
120 Layer.provideMerge(
121 Layer.mock(BackgroundPolicy.BackgroundPolicy)({
122 shouldRunScopeWork: () => Effect.succeed(runBackgroundWork),
123 }),
124 ),
125 Layer.provideMerge(ServerSettings.layerTest()),
126 Layer.provideMerge(ServerSecretStore.layer),
127 Layer.provide(
128 ServerConfig.layerTest(process.cwd(), { prefix: "t3-antigravity-provider-test-" }).pipe(
129 Layer.provideMerge(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)),
130 ),
131 ),
132 );
133const layerTest = makeLayerTest(false);
134​
135type ProbeError = EffectAcpErrors.AcpError | ProviderSetupError;
136​
137const makeHarness = Effect.fn("makeAntigravityProviderHarness")(function* (
138 options: {
139 readonly auth?: { readonly type: string; readonly label: string };
140 readonly enabled?: boolean;
141 readonly safe?: boolean;
142 readonly probeUsage?: Effect.Effect<ServerProviderUsageLimits>;
143 readonly rememberedRuntimeModes?: ReadonlyArray<RuntimeMode>;
144 } = {},
145) {
146 const savedRuntimeModes = yield* Ref.make<ReadonlyArray<ReadonlyArray<RuntimeMode>>>([]);
147 const initialProbe = yield* Deferred.make<EffectAcpSchema.InitializeResponse, ProbeError>();
148 const probeCalls = yield* Ref.make(0);
149 const safetyCalls = yield* Ref.make(0);
150 const probe = yield* Ref.make<Effect.Effect<EffectAcpSchema.InitializeResponse, ProbeError>>(
151 Deferred.await(initialProbe),
152 );
153 const safety = yield* Ref.make<Effect.Effect<boolean>>(Effect.succeed(options.safe ?? true));
154 const provider = yield* makeAntigravityProvider(
155 decodeSettings({ enabled: options.enabled ?? true, customModels: ["do-not-seed-me"] }),
156 {
157 stampIdentity: (snapshot) => Effect.succeed({ ...snapshot, instanceId, driver }),
158 ...(options.auth ? { auth: options.auth } : {}),
159 ...(options.probeUsage ? { probeUsage: options.probeUsage } : {}),
160 ...(options.rememberedRuntimeModes
161 ? { rememberedRuntimeModes: options.rememberedRuntimeModes }
162 : {}),
163 rememberRuntimeModes: (modes) => Ref.update(savedRuntimeModes, (saved) => [...saved, modes]),
164 probe: Ref.update(probeCalls, (count) => count + 1).pipe(
165 Effect.andThen(Ref.get(probe)),
166 Effect.flatten,
167 ),
168 supportsTextGeneration: Ref.update(safetyCalls, (count) => count + 1).pipe(
169 Effect.andThen(Ref.get(safety)),
170 Effect.flatten,
171 ),
172 },
173 );
174 const initialUpdate = yield* Stream.toPull(
175 provider.snapshot.streamChanges.pipe(
176 Stream.filter((snapshot) => snapshot.installed || snapshot.status === "error"),
177 ),
178 );
179 const initialize = Deferred.succeed(initialProbe, initializeResult).pipe(
180 Effect.andThen(initialUpdate),
181 Effect.asVoid,
182 );
183 // Subscribe before the trigger; yield the returned pull to await the publish.
184 const nextPublish = (predicate: (snapshot: ServerProvider) => boolean) =>
185 Stream.toPull(provider.snapshot.streamChanges.pipe(Stream.filter(predicate))).pipe(
186 Effect.map((pull) => pull.pipe(Effect.map((snapshots) => snapshots[0]))),
187 );
188 return {
189 provider,
190 probe,
191 probeCalls,
192 safety,
193 safetyCalls,
194 initialProbe,
195 initialUpdate,
196 initialize,
197 nextPublish,
198 savedRuntimeModes,
199 };
200});
201​
202describe("Antigravity model catalog", () => {
203 it("uses legacy session models only when model config is absent", () => {
204 const fromLegacy = buildAntigravityModelsFromSession({
205 models: sessionSetupResult.models,
206 });
207 expect(fromLegacy).toEqual(buildAntigravityModelsFromSession(sessionSetupResult));
208 expect(
209 buildAntigravityModelsFromSession({
210 ...sessionSetupResult,
211 configOptions: [{ ...modelConfig, options: [] }],
212 }),
213 ).toEqual([]);
214 });
215​
216 it("flattens native option groups without combining distinct model IDs", () => {
217 const models = buildAntigravityModelsFromSession({
218 configOptions: [
219 {
220 ...modelConfig,
221 currentValue: "gemini-pro-agent",
222 options: [
223 { groupId: "Flash", name: "Flash", options: [modelOptions[3]!, modelOptions[4]!] },
224 { groupId: "Pro", name: "Pro", options: [modelOptions[9]!, modelOptions[3]!] },
225 ],
226 },
227 ],
228 });
229 expect(models.map((model) => model.slug)).toEqual([
230 "gemini-3.7-flash-high",
231 "gemini-3.7-flash-medium",
232 "gemini-pro-agent",
233 ]);
234 expect(models.find((model) => model.isDefault)?.slug).toBe("gemini-pro-agent");
235 expect(models.find((model) => model.aliases?.includes(ANTIGRAVITY_DEFAULT_MODEL))?.slug).toBe(
236 "gemini-pro-agent",
237 );
238 });
239​
240 it("labels models that share a display name with their IDs", () => {
241 const models = buildAntigravityModelsFromSession({
242 configOptions: [
243 {
244 ...modelConfig,
245 currentValue: "gemini-3.8-flash",
246 options: [
247 { value: "gemini-3.8-flash", name: "Gemini 3.8 Flash" },
248 { value: "gemini-3.8-flash-preview", name: "Gemini 3.8 Flash" },
249 ],
250 },
251 ],
252 });
253 expect(models.map((model) => model.name)).toEqual([
254 "Gemini 3.8 Flash",
255 "Gemini 3.8 Flash (gemini-3.8-flash-preview)",
256 ]);
257 });
258​
259 it("offers each model only the thinking levels it reported when selected", () => {
260 const thinking = (currentValue: string) =>
261 ({
262 id: "thinking_level",
263 name: "Thinking Level",
264 category: "thought_level",
265 type: "select",
266 currentValue,
267 options: [
268 { value: "low", name: "Low" },
269 { value: "high", name: "High" },
270 ],
271 }) satisfies EffectAcpSchema.SessionConfigOption;
272 const models = buildAntigravityModelsFromSession(
273 {
274 configOptions: [
275 {
276 ...modelConfig,
277 currentValue: "gemini",
278 options: [
279 { value: "gemini", name: "Gemini" },
280 { value: "claude", name: "Claude" },
281 { value: "plain", name: "Plain" },
282 { value: "unseen", name: "Unseen" },
283 ],
284 },
285 thinking("high"),
286 ],
287 },
288 new Map([
289 ["claude", thinking("low")],
290 ["plain", null],
291 ]),
292 );
293 const thinkingOf = (slug: string) =>
294 models.find((model) => model.slug === slug)?.capabilities?.optionDescriptors?.[0];
295​
296 expect(thinkingOf("gemini")).toMatchObject({ id: "thinking_level", currentValue: "high" });
297 expect(thinkingOf("claude")).toMatchObject({ id: "thinking_level", currentValue: "low" });
298 expect(thinkingOf("plain")).toBeUndefined();
299 expect(thinkingOf("unseen")).toBeUndefined();
300 });
301​
302 it("keeps each model's probed thinking levels after a restart observes only the active model", () => {
303 const thinking = (levels: ReadonlyArray<string>) =>
304 ({
305 id: "thinking_level",
306 name: "Thinking Level",
307 category: "thought_level",
308 type: "select",
309 currentValue: "low",
310 options: levels.map((value) => ({ value, name: value })),
311 }) satisfies EffectAcpSchema.SessionConfigOption;
312 const deep = thinking(["low", "medium", "high", "xhigh"]);
313 const models = {
314 ...modelConfig,
315 currentValue: "neon",
316 options: [
317 { value: "neon", name: "Neon" },
318 { value: "carbon", name: "Carbon" },
319 { value: "fixed", name: "Fixed effort" },
320 ],
321 } satisfies EffectAcpSchema.SessionConfigOption;
322 const setup = { configOptions: [models, deep] };
323 const provider = {
324 instanceId,
325 driver,
326 status: "ready",
327 enabled: true,
328 installed: true,
329 version: null,
330 auth: { status: "authenticated" },
331 checkedAt: "2026-11-23T00:00:00.000Z",
332 slashCommands: [],
333 skills: [],
334 } as const;
335 // Sign-in or Refresh models walks every model, so each reports its own levels.
336 const probed = {
337 ...provider,
338 models: buildAntigravityModelsFromSession(
339 setup,
340 new Map([
341 ["carbon", thinking(["low", "medium", "high"])],
342 ["fixed", null],
343 ]),
344 ),
345 } satisfies ServerProvider;
346 // After a restart the provider has observed only the session's model.
347 const restarted = {
348 ...provider,
349 checkedAt: "2026-11-23T01:00:00.000Z",
350 models: buildAntigravityModelsFromSession(setup, new Map([["neon", deep]])),
351 } satisfies ServerProvider;
352​
353 const merged = mergeProviderSnapshot(probed, restarted);
354 const levelsOf = (slug: string) => {
355 const descriptor = merged.models.find((model) => model.slug === slug)?.capabilities
356 ?.optionDescriptors?.[0];
357 return descriptor?.type === "select" ? descriptor.options.map((option) => option.id) : [];
358 };
359​
360 expect(levelsOf("neon")).toEqual(["low", "medium", "high", "xhigh"]);
361 expect(levelsOf("carbon")).toEqual(["low", "medium", "high"]);
362 expect(levelsOf("fixed")).toEqual([]);
363 });
364});
365​
366it.layer(layerTest)("Antigravity provider snapshots", (it) => {
367 it.effect("does not probe or run helper safety checks while disabled", () =>
368 Effect.gen(function* () {
369 const harness = yield* makeHarness({ enabled: false });
370 const snapshot = yield* harness.provider.snapshot.refresh;
371 expect(snapshot).toMatchObject({
372 enabled: false,
373 installed: false,
374 status: "disabled",
375 auth: { status: "unknown" },
376 models: [],
377 setup: { canAuthenticate: true, canInstall: true },
378 showInteractionModeToggle: false,
379 supportsConversationRollback: true,
380 supportsTextGeneration: false,
381 });
382 expect(yield* Ref.get(harness.probeCalls)).toBe(0);
383 expect(yield* Ref.get(harness.safetyCalls)).toBe(0);
384 }),
385 );
386​
387 it.effect("treats initialize as installation proof, not account or model discovery", () =>
388 Effect.gen(function* () {
389 for (const auth of [
390 undefined,
391 { type: "oauth-personal", label: "Google account" },
392 { type: "oauth-business", label: "Gemini Enterprise" },
393 { type: "gemini-api-key", label: "Gemini API key" },
394 { type: "agent-platform", label: "Agent Platform" },
395 ]) {
396 const harness = yield* makeHarness(auth ? { auth } : {});
397 expect(yield* harness.provider.snapshot.getSnapshot).toMatchObject({
398 installed: false,
399 status: "warning",
400 auth: { status: "unknown" },
401 models: [],
402 });
403 yield* harness.initialize;
404 const snapshot = yield* harness.provider.snapshot.getSnapshot;
405 expect(snapshot).toMatchObject({
406 installed: true,
407 status: "warning",
408 version: "1.5.12",
409 auth: { status: "unknown", ...(auth ? { type: auth.type } : {}) },
410 message:
411 auth?.type === "gemini-api-key" || auth?.type === "agent-platform"
412 ? `Antigravity is installed. Connect with ${auth.label} to load models.`
413 : "Antigravity is installed. Google account access is not checked yet.",
414 models: [],
415 });
416 expect(yield* Ref.get(harness.probeCalls)).toBe(1);
417 }
418 }),
419 );
420​
421 it.effect("offers Auto only while the signed-in session advertises agy's own Auto", () =>
422 Effect.gen(function* () {
423 const harness = yield* makeHarness();
424 yield* harness.initialize;
425 const supportedModes = harness.provider.snapshot.getSnapshot.pipe(
426 Effect.map((snapshot) => snapshot.supportedRuntimeModes),
427 );
428 const withoutAuto = ["approval-required", "auto-accept-edits", "full-access"];
429 const startedWithAuto = {
430 ...started,
431 sessionSetupResult: {
432 ...sessionSetupResult,
433 modes: {
434 currentModeId: "default",
435 availableModes: [
436 { id: "default", name: "Default" },
437 { id: "auto", name: "Auto" },
438 ],
439 },
440 },
441 };
442 expect(yield* supportedModes).toEqual(withoutAuto);
443 yield* harness.provider.onSessionStarted(startedWithAuto);
444 expect(yield* supportedModes).toEqual([
445 "approval-required",
446 "auto-accept-edits",
447 "auto",
448 "full-access",
449 ]);
450 yield* harness.provider.onSessionStarted(started);
451 expect(yield* supportedModes).toEqual(withoutAuto);
452 yield* harness.provider.onSessionStarted(startedWithAuto);
453 yield* harness.provider.onSignedOut;
454 expect(yield* supportedModes).toEqual(withoutAuto);
455 const withAuto: ReadonlyArray<RuntimeMode> = [
456 "approval-required",
457 "auto-accept-edits",
458 "auto",
459 "full-access",
460 ];
461 expect(yield* Ref.get(harness.savedRuntimeModes)).toEqual([
462 withAuto,
463 withoutAuto,
464 withAuto,
465 withoutAuto,
466 ]);
467​
468 // A restart offers what the last session advertised before any session starts.
469 const restarted = yield* makeHarness({ rememberedRuntimeModes: withAuto });
470 yield* restarted.initialize;
471 expect(yield* restarted.provider.snapshot.getSnapshot).toMatchObject({
472 supportedRuntimeModes: withAuto,
473 });
474 }),
475 );
476​
477 it.effect("publishes session metadata and native commands without another health probe", () =>
478 Effect.gen(function* () {
479 const harness = yield* makeHarness();
480 yield* harness.initialize;
481 const nextReady = yield* Stream.toPull(
482 harness.provider.snapshot.streamChanges.pipe(
483 Stream.filter(
484 (snapshot) =>
485 snapshot.auth.status === "authenticated" && snapshot.slashCommands.length > 0,
486 ),
487 ),
488 );
489 yield* harness.provider.onSessionStarted(started, "/workspace");
490 yield* harness.provider.onAvailableCommands(commands, "/workspace");
491 const [snapshot] = yield* nextReady;
492 expect(snapshot).toMatchObject({
493 status: "ready",
494 auth: { status: "authenticated", type: "oauth-personal" },
495 supportsTextGeneration: true,
496 });
497 expect(snapshot.models).toEqual(buildAntigravityModelsFromSession(sessionSetupResult));
498 expect(snapshot.slashCommands).toEqual(expectedCommands);
499 expect((yield* harness.provider.snapshotForCwd("/workspace")).slashCommands).toEqual(
500 expectedCommands,
501 );
502 expect(yield* Ref.get(harness.probeCalls)).toBe(1);
503 }),
504 );
505​
506 it.effect("keeps a workspace's native commands when the catalog reports its own", () =>
507 Effect.gen(function* () {
508 const harness = yield* makeHarness();
509 yield* harness.initialize;
510 yield* harness.provider.onSessionStarted(started, "/workspace");
511 yield* harness.provider.onAvailableCommands(commands, "/workspace");
512 // The catalog probe runs in a scratch directory and reports no cwd.
513 yield* harness.provider.onAvailableCommands(commands.slice(1));
514 expect((yield* harness.provider.snapshotForCwd("/workspace")).slashCommands).toEqual(
515 expectedCommands,
516 );
517 expect((yield* harness.provider.snapshot.getSnapshot).slashCommands).toEqual(
518 expectedCommands.slice(1),
519 );
520 }),
521 );
522​
523 it.effect("clears all account metadata on sign-out and authentication failure", () =>
524 Effect.gen(function* () {
525 const auth = { type: "gemini-api-key", label: "Gemini API key" };
526 const harness = yield* makeHarness({ auth });
527 yield* harness.initialize;
528 for (const clear of [harness.provider.onSignedOut, harness.provider.onAuthRequired]) {
529 yield* harness.provider.onSessionStarted(started, "/workspace");
530 yield* harness.provider.onAvailableCommands(commands, "/workspace");
531 yield* clear;
532 expect(yield* harness.provider.snapshot.getSnapshot).toMatchObject({
533 installed: true,
534 status: "warning",
535 auth: { status: "unauthenticated", type: auth.type, label: auth.label },
536 message: "Connect with Gemini API key to use Antigravity and load models.",
537 models: [],
538 slashCommands: [],
539 skills: [],
540 workspaceSnapshots: [],
541 supportsTextGeneration: false,
542 });
543 yield* harness.provider.onAvailableCommands(commands, "/workspace");
544 yield* harness.provider.onConfigOptionsUpdated([modelConfig]);
545 expect((yield* harness.provider.snapshotForCwd("/workspace")).slashCommands).toEqual([]);
546 expect((yield* harness.provider.snapshot.getSnapshot).models).toEqual([]);
547 }
548 const refreshed = yield* harness.provider.snapshot.refresh;
549 expect(refreshed.auth).toEqual({
550 status: "unauthenticated",
551 type: auth.type,
552 label: auth.label,
553 });
554 expect(refreshed.message).toBe(
555 "Connect with Gemini API key to use Antigravity and load models.",
556 );
557 expect(refreshed.supportsTextGeneration).toBe(false);
558 }),
559 );
560​
561 it.effect("replaces live model choices and accepts an empty catalog", () =>
562 Effect.gen(function* () {
563 const harness = yield* makeHarness();
564 yield* harness.initialize;
565 yield* harness.provider.onSessionStarted(started, "/workspace");
566 yield* harness.provider.onAvailableCommands(commands, "/workspace");
567 const before = yield* harness.provider.snapshot.getSnapshot;
568 const configOptions = [
569 {
570 ...modelConfig,
571 currentValue: "gemini-3.8-flash-high",
572 options: modelOptions.slice(0, 3),
573 },
574 ];
575 const nextSnapshot = yield* Stream.toPull(
576 harness.provider.snapshot.streamChanges.pipe(
577 Stream.filter((snapshot) => snapshot.models.length === 3),
578 ),
579 );
580 yield* harness.provider.onConfigOptionsUpdated(configOptions);
581 expect((yield* nextSnapshot)[0]).toMatchObject({
582 models: buildAntigravityModelsFromSession({ configOptions }),
583 auth: before.auth,
584 workspaceSnapshots: before.workspaceSnapshots,
585 slashCommands: expectedCommands,
586 });
587 yield* harness.provider.onConfigOptionsUpdated([]);
588 expect((yield* harness.provider.snapshot.getSnapshot).models).toEqual([]);
589 }),
590 );
591​
592 it.effect("does not guess a version before a custom launcher's first handshake", () =>
593 Effect.gen(function* () {
594 const harness = yield* makeHarness();
595 yield* Deferred.succeed(harness.initialProbe, {
596 ...initializeResult,
597 agentInfo: { ...initializeResult.agentInfo, version: "unknown" },
598 });
599 yield* harness.initialUpdate;
600 expect((yield* harness.provider.snapshot.getSnapshot).version).toBeNull();
601 }),
602 );
603​
604 it.effect("does not replace a handshake version with an unknown custom-launcher probe", () =>
605 Effect.gen(function* () {
606 const harness = yield* makeHarness();
607 yield* harness.initialize;
608 yield* harness.provider.onSessionStarted({
609 ...started,
610 initializeResult: {
611 ...initializeResult,
612 agentInfo: { ...initializeResult.agentInfo, version: "1.5.13" },
613 },
614 });
615 yield* Ref.set(
616 harness.probe,
617 Effect.succeed({
618 ...initializeResult,
619 agentInfo: { ...initializeResult.agentInfo, version: "unknown" },
620 }),
621 );
622 expect((yield* harness.provider.snapshot.refresh).version).toBe("1.5.13");
623 }),
624 );
625​
626 it.effect("replaces one account's catalog instead of combining accounts", () =>
627 Effect.gen(function* () {
628 const harness = yield* makeHarness();
629 yield* harness.initialize;
630 yield* harness.provider.onSessionStarted(started);
631 yield* harness.provider.onSignedOut;
632 yield* harness.provider.onSessionStarted({
633 ...started,
634 sessionSetupResult: {
635 sessionId: "new-account-session",
636 configOptions: [
637 { ...modelConfig, currentValue: "gemini-pro-agent", options: [modelOptions[9]!] },
638 ],
639 },
640 });
641 expect(
642 (yield* harness.provider.snapshot.getSnapshot).models.map((model) => model.slug),
643 ).toEqual(["gemini-pro-agent"]);
644 }),
645 );
646​
647 it.effect("retains known account metadata when a local health check fails", () =>
648 Effect.gen(function* () {
649 const harness = yield* makeHarness();
650 yield* harness.initialize;
651 yield* harness.provider.onSessionStarted(started, "/workspace");
652 yield* harness.provider.onAvailableCommands(commands, "/workspace");
653 yield* Ref.set(
654 harness.probe,
655 Effect.fail(EffectAcpErrors.AcpRequestError.internalError("probe failed")),
656 );
657 const snapshot = yield* harness.provider.snapshot.refresh;
658 expect(snapshot).toMatchObject({
659 installed: true,
660 status: "error",
661 auth: { status: "authenticated" },
662 });
663 expect(snapshot.models).toEqual(buildAntigravityModelsFromSession(sessionSetupResult));
664 expect(snapshot.slashCommands).toEqual(expectedCommands);
665 expect(snapshot.workspaceSnapshots?.[0]?.cwd).toBe("/workspace");
666 }),
667 );
668​
669 it.effect("distinguishes missing executables from a failed installed executable", () =>
670 Effect.gen(function* () {
671 const harness = yield* makeHarness();
672 yield* harness.initialize;
673 const failures = [
674 {
675 error: new EffectAcpErrors.AcpSpawnError({ cause: { code: "ENOENT" } }),
676 installed: false,
677 },
678 {
679 error: new EffectAcpErrors.AcpSpawnError({ cause: { code: "EACCES" } }),
680 installed: true,
681 },
682 {
683 error: new ProviderSetupError({
684 instanceId,
685 operation: "resolve",
686 detail: "Antigravity is not installed.",
687 }),
688 installed: false,
689 },
690 {
691 error: new ProviderSetupError({
692 instanceId,
693 operation: "resolve",
694 detail:
695 "The managed Antigravity runtime changed on disk. Reinstall it in Antigravity setup.",
696 }),
697 installed: false,
698 },
699 ];
700 for (const { error, installed } of failures) {
701 yield* harness.provider.onSessionStarted(started, "/workspace");
702 yield* harness.provider.onAvailableCommands(commands, "/workspace");
703 yield* Ref.set(harness.probe, Effect.fail(error));
704 const snapshot = yield* harness.provider.snapshot.refresh;
705 expect(snapshot).toMatchObject({
706 installed,
707 status: "error",
708 auth: { status: "authenticated" },
709 });
710 expect(snapshot.models).toHaveLength(installed ? 11 : 0);
711 expect(snapshot.slashCommands).toHaveLength(installed ? 2 : 0);
712 expect(snapshot.workspaceSnapshots).toHaveLength(installed ? 1 : 0);
713 expect(snapshot.supportsTextGeneration).toBe(installed);
714 }
715 }),
716 );
717​
718 it.effect("does not let an old health result restore a signed-out account", () =>
719 Effect.gen(function* () {
720 const harness = yield* makeHarness();
721 yield* harness.initialize;
722 yield* harness.provider.onSessionStarted(started);
723 const releaseProbe = yield* Deferred.make<EffectAcpSchema.InitializeResponse>();
724 const probeEntered = yield* Deferred.make<void>();
725 yield* Ref.set(
726 harness.probe,
727 Deferred.succeed(probeEntered, undefined).pipe(
728 Effect.andThen(Deferred.await(releaseProbe)),
729 ),
730 );
731 const refresh = yield* harness.provider.snapshot.refresh.pipe(Effect.forkChild);
732 yield* Deferred.await(probeEntered);
733 yield* harness.provider.onSignedOut;
734 yield* Deferred.succeed(releaseProbe, initializeResult);
735 const snapshot = yield* Fiber.join(refresh);
736 expect(snapshot).toMatchObject({
737 auth: { status: "unauthenticated" },
738 models: [],
739 supportsTextGeneration: false,
740 });
741 }),
742 );
743​
744 it.effect("exposes helper support only when the supplied safety check allows it", () =>
745 Effect.gen(function* () {
746 const harness = yield* makeHarness({ safe: false });
747 yield* harness.initialize;
748 yield* harness.provider.onSessionStarted(started);
749 expect((yield* harness.provider.snapshot.getSnapshot).supportsTextGeneration).toBe(false);
750 yield* Ref.set(harness.safety, Effect.succeed(true));
751 yield* harness.provider.snapshot.refresh;
752 expect((yield* harness.provider.snapshot.getSnapshot).supportsTextGeneration).toBe(true);
753 }),
754 );
755​
756 it.effect("keeps discovered workspace skills through session and command updates", () =>
757 Effect.gen(function* () {
758 const harness = yield* makeHarness();
759 yield* harness.initialize;
760 const skills = [
761 {
762 name: "deploy",
763 description: "Ship it",
764 path: "/workspace/.agent/skills/deploy",
765 enabled: true,
766 },
767 ];
768 const discovered = yield* harness.provider.snapshotForCwd("/workspace", skills);
769 expect(discovered.skills).toEqual(skills);
770 yield* harness.provider.onSessionStarted(started, "/workspace");
771 yield* harness.provider.onAvailableCommands(commands, "/workspace");
772 const after = yield* harness.provider.snapshot.getSnapshot;
773 expect(after.workspaceSnapshots?.find((entry) => entry.cwd === "/workspace")?.skills).toEqual(
774 skills,
775 );
776 expect((yield* harness.provider.snapshotForCwd("/workspace")).skills).toEqual(skills);
777​
778 const rescanned = [
779 ...skills,
780 { name: "review", path: "/workspace/.agent/skills/review", enabled: true },
781 ];
782 yield* harness.provider.snapshotForCwd("/workspace", rescanned);
783 yield* harness.provider.onSessionStarted(started, "/workspace");
784 expect(
785 (yield* harness.provider.snapshot.getSnapshot).workspaceSnapshots?.find(
786 (entry) => entry.cwd === "/workspace",
787 )?.skills,
788 ).toEqual(rescanned);
789 }),
790 );
791​
792 it.effect("bounds workspace metadata without starting sessions for workspace lookup", () =>
793 Effect.gen(function* () {
794 const harness = yield* makeHarness();
795 yield* harness.initialize;
796 yield* harness.provider.onSessionStarted(started);
797 for (let index = 0; index < 35; index++) {
798 yield* harness.provider.onAvailableCommands(commands, `/workspace-${index}`);
799 }
800 const snapshot = yield* harness.provider.snapshotForCwd("/workspace-34");
801 expect(snapshot.workspaceSnapshots).toHaveLength(32);
802 expect(snapshot.workspaceSnapshots?.[0]?.cwd).toBe("/workspace-3");
803 expect(snapshot.slashCommands).toEqual(expectedCommands);
804 expect(yield* Ref.get(harness.probeCalls)).toBe(1);
805 }),
806 );
807​
808 it.effect(
809 "publishes limits, retains a successful read on failure, and clears them on sign-out",
810 () =>
811 Effect.gen(function* () {
812 const limits: ServerProviderUsageLimits = {
813 checkedAt: "2026-10-09T12:00:00.000Z",
814 windows: [
815 {
816 id: "3p-weekly",
817 kind: "weekly",
818 label: "Claude & GPT (shared) · Weekly",
819 usedPercent: 75,
820 },
821 ],
822 };
823 const usage = yield* Ref.make(limits);
824 const harness = yield* makeHarness({ probeUsage: Ref.get(usage) });
825 const published = yield* harness.nextPublish((snapshot) => !!snapshot.usageLimits);
826 yield* harness.initialize;
827 expect((yield* published)?.usageLimits).toEqual(limits);
828 // The second health check is the one the failed background read triggers.
829 const checks = yield* Ref.make(0);
830 const failedReadApplied = yield* Deferred.make<void>();
831 yield* Ref.set(
832 harness.probe,
833 Ref.updateAndGet(checks, (count) => count + 1).pipe(
834 Effect.tap((count) =>
835 count === 2 ? Deferred.succeed(failedReadApplied, undefined) : Effect.void,
836 ),
837 Effect.as(initializeResult),
838 ),
839 );
840 yield* Ref.set(usage, {
841 checkedAt: "2026-10-09T12:01:00.000Z",
842 windows: [],
843 unavailable: { reason: "probeFailed" },
844 });
845 yield* harness.provider.snapshot.refresh;
846 yield* Deferred.await(failedReadApplied);
847 expect((yield* harness.provider.snapshot.getSnapshot).usageLimits).toEqual(limits);
848 yield* harness.provider.onSignedOut;
849 expect((yield* harness.provider.snapshot.getSnapshot).usageLimits).toBeUndefined();
850 yield* Ref.set(usage, {
851 checkedAt: "2026-10-09T12:02:00.000Z",
852 windows: [],
853 unavailable: { reason: "unsupported" },
854 });
855 const unsupported = yield* harness.nextPublish(
856 (snapshot) => snapshot.usageLimits?.unavailable?.reason === "unsupported",
857 );
858 yield* harness.provider.snapshot.refresh;
859 expect((yield* unsupported)?.usageLimits?.windows).toEqual([]);
860 }),
861 );
862​
863 it.effect("a quota read finishing after sign-out cannot restore account limits", () =>
864 Effect.gen(function* () {
865 const readStarted = yield* Deferred.make<void>();
866 const readResult = yield* Deferred.make<ServerProviderUsageLimits>();
867 const usage = yield* Ref.make<Effect.Effect<ServerProviderUsageLimits>>(
868 Effect.succeed({ checkedAt: "2026-10-09T12:00:00.000Z", windows: [] }),
869 );
870 const harness = yield* makeHarness({ probeUsage: Ref.get(usage).pipe(Effect.flatten) });
871 yield* harness.initialize;
872 yield* Ref.set(harness.probe, Effect.succeed(initializeResult));
873 yield* Ref.set(
874 usage,
875 Deferred.succeed(readStarted, undefined).pipe(Effect.andThen(Deferred.await(readResult))),
876 );
877 const refresh = yield* harness.provider.snapshot.refresh.pipe(Effect.forkChild);
878 yield* Deferred.await(readStarted);
879 yield* harness.provider.onSignedOut;
880 yield* Deferred.succeed(readResult, {
881 checkedAt: "2026-10-09T12:01:00.000Z",
882 windows: [{ id: "gemini-5h", kind: "session", label: "Gemini · 5-hour", usedPercent: 10 }],
883 });
884 yield* Fiber.join(refresh);
885 expect((yield* harness.provider.snapshot.getSnapshot).usageLimits).toBeUndefined();
886 }),
887 );
888​
889 it.effect("reports ready and starts sessions while one shared quota read is pending", () =>
890 Effect.gen(function* () {
891 const reads = yield* Ref.make(0);
892 const readStarted = yield* Deferred.make<void>();
893 const readResult = yield* Deferred.make<ServerProviderUsageLimits>();
894 const harness = yield* makeHarness({
895 probeUsage: Ref.update(reads, (count) => count + 1).pipe(
896 Effect.andThen(Deferred.succeed(readStarted, undefined)),
897 Effect.andThen(Deferred.await(readResult)),
898 ),
899 });
900 const published = yield* harness.nextPublish((snapshot) => !!snapshot.usageLimits);
901 yield* harness.initialize;
902 yield* Deferred.await(readStarted);
903 yield* harness.provider.onSessionStarted(started, "/workspace");
904 yield* harness.provider.onSessionStarted(started, "/other");
905 const ready = yield* harness.provider.snapshot.getSnapshot;
906 expect(ready).toMatchObject({ status: "ready", auth: { status: "authenticated" } });
907 expect(ready.usageLimits).toBeUndefined();
908 expect(yield* Ref.get(reads)).toBe(1);
909 const limits = {
910 checkedAt: "2026-10-09T12:00:00.000Z",
911 windows: [{ id: "gemini-5h", kind: "session", label: "Gemini · 5-hour", usedPercent: 10 }],
912 } satisfies ServerProviderUsageLimits;
913 yield* Deferred.succeed(readResult, limits);
914 expect((yield* published)?.usageLimits).toEqual(limits);
915 }),
916 );
917​
918 it.effect("a quota read for the previous account is dropped after a new sign-in", () =>
919 Effect.gen(function* () {
920 const oldReadStarted = yield* Deferred.make<void>();
921 const newLimits = {
922 checkedAt: "2026-10-09T12:01:00.000Z",
923 windows: [{ id: "3p-weekly", kind: "weekly", label: "Weekly", usedPercent: 40 }],
924 } satisfies ServerProviderUsageLimits;
925 const usage = yield* Ref.make<Effect.Effect<ServerProviderUsageLimits>>(
926 Deferred.succeed(oldReadStarted, undefined).pipe(Effect.andThen(Effect.never)),
927 );
928 const harness = yield* makeHarness({ probeUsage: Ref.get(usage).pipe(Effect.flatten) });
929 const published = yield* harness.nextPublish((snapshot) => !!snapshot.usageLimits);
930 yield* harness.initialize;
931 yield* Deferred.await(oldReadStarted);
932 yield* Ref.set(usage, Effect.succeed(newLimits));
933 yield* harness.provider.onSignedIn;
934 yield* harness.provider.onSessionStarted(started);
935 expect((yield* published)?.usageLimits).toEqual(newLimits);
936 // Switching again must not republish the previous account's limits, even if the read fails.
937 const failed = {
938 checkedAt: "2026-10-09T12:02:00.000Z",
939 windows: [],
940 unavailable: { reason: "probeFailed" },
941 } satisfies ServerProviderUsageLimits;
942 yield* Ref.set(usage, Effect.succeed(failed));
943 const republished = yield* harness.nextPublish(
944 (snapshot) => snapshot.usageLimits?.unavailable?.reason === "probeFailed",
945 );
946 yield* harness.provider.onSignedIn;
947 expect((yield* harness.provider.snapshot.getSnapshot).usageLimits).toBeUndefined();
948 yield* harness.provider.onSessionStarted(started);
949 expect((yield* republished)?.usageLimits).toEqual(failed);
950 }),
951 );
952});
953​
954it.layer(makeLayerTest(true))("Antigravity periodic health checks", (it) => {
955 it.effect("rechecks a ready provider after one failed periodic check before publishing it", () =>
956 Effect.gen(function* () {
957 const harness = yield* makeHarness();
958 yield* harness.initialize;
959 yield* harness.provider.onSessionStarted(started, "/workspace");
960 expect((yield* harness.provider.snapshot.getSnapshot).status).toBe("ready");
961 const published = yield* Ref.make<ReadonlyArray<ServerProvider>>([]);
962 yield* harness.provider.snapshot.streamChanges.pipe(
963 Stream.runForEach((snapshot) => Ref.update(published, (all) => [...all, snapshot])),
964 Effect.forkChild,
965 );
966 yield* Effect.yieldNow;
967 yield* Ref.set(
968 harness.probe,
969 Effect.fail(EffectAcpErrors.AcpRequestError.internalError("probe failed")),
970 );
971​
972 yield* TestClock.adjust("5 minutes");
973​
974 expect((yield* harness.provider.snapshot.getSnapshot).status).toBe("ready");
975 expect((yield* Ref.get(published)).map((snapshot) => snapshot.status)).not.toContain("error");
976​
977 yield* Ref.set(harness.probe, Effect.succeed(initializeResult));
978 yield* TestClock.adjust("30 seconds");
979 const failProbe = yield* Deferred.make<void>();
980 yield* Ref.set(
981 harness.probe,
982 Deferred.await(failProbe).pipe(
983 Effect.andThen(
984 Effect.fail(EffectAcpErrors.AcpRequestError.internalError("probe failed")),
985 ),
986 ),
987 );
988 yield* TestClock.adjust("5 minutes");
989 yield* harness.provider.onSignedOut;
990 yield* Deferred.succeed(failProbe, undefined);
991 yield* TestClock.adjust("30 seconds");
992​
993 const auth = (yield* Ref.get(published)).map((snapshot) => snapshot.auth.status);
994 expect(auth.slice(auth.indexOf("unauthenticated"))).not.toContain("authenticated");
995 expect(auth.at(-1)).toBe("unauthenticated");
996 }),
997 );
998});