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

AntigravityProvider.test.ts

1,079 lines41.1 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 isProviderWorkspaceSnapshotPending,
8 ProviderDriverKind,
9 ProviderInstanceId,
10 ProviderSetupError,
11 type RuntimeMode,
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 rememberedRuntimeModes?: ReadonlyArray<RuntimeMode>;
143 } = {},
144) {
145 const savedRuntimeModes = yield* Ref.make<ReadonlyArray<ReadonlyArray<RuntimeMode>>>([]);
146 const initialProbe = yield* Deferred.make<EffectAcpSchema.InitializeResponse, ProbeError>();
147 const probeCalls = yield* Ref.make(0);
148 const safetyCalls = yield* Ref.make(0);
149 const probe = yield* Ref.make<Effect.Effect<EffectAcpSchema.InitializeResponse, ProbeError>>(
150 Deferred.await(initialProbe),
151 );
152 const safety = yield* Ref.make<Effect.Effect<boolean>>(Effect.succeed(options.safe ?? true));
153 const provider = yield* makeAntigravityProvider(
154 decodeSettings({ enabled: options.enabled ?? true, customModels: ["do-not-seed-me"] }),
155 {
156 stampIdentity: (snapshot) => Effect.succeed({ ...snapshot, instanceId, driver }),
157 ...(options.auth ? { auth: options.auth } : {}),
158 ...(options.rememberedRuntimeModes
159 ? { rememberedRuntimeModes: options.rememberedRuntimeModes }
160 : {}),
161 rememberRuntimeModes: (modes) => Ref.update(savedRuntimeModes, (saved) => [...saved, modes]),
162 probe: Ref.update(probeCalls, (count) => count + 1).pipe(
163 Effect.andThen(Ref.get(probe)),
164 Effect.flatten,
165 ),
166 supportsTextGeneration: Ref.update(safetyCalls, (count) => count + 1).pipe(
167 Effect.andThen(Ref.get(safety)),
168 Effect.flatten,
169 ),
170 },
171 );
172 const initialUpdate = yield* Stream.toPull(
173 provider.snapshot.streamChanges.pipe(
174 Stream.filter((snapshot) => snapshot.installed || snapshot.status === "error"),
175 ),
176 );
177 const initialize = Deferred.succeed(initialProbe, initializeResult).pipe(
178 Effect.andThen(initialUpdate),
179 Effect.asVoid,
180 );
181 // Subscribe before the trigger; yield the returned pull to await the publish.
182 const nextPublish = (predicate: (snapshot: ServerProvider) => boolean) =>
183 Stream.toPull(provider.snapshot.streamChanges.pipe(Stream.filter(predicate))).pipe(
184 Effect.map((pull) => pull.pipe(Effect.map((snapshots) => snapshots[0]))),
185 );
186 return {
187 provider,
188 probe,
189 probeCalls,
190 safety,
191 safetyCalls,
192 initialProbe,
193 initialUpdate,
194 initialize,
195 nextPublish,
196 savedRuntimeModes,
197 };
198});
199​
200describe("Antigravity model catalog", () => {
201 it("uses legacy session models only when model config is absent", () => {
202 const fromLegacy = buildAntigravityModelsFromSession({
203 models: sessionSetupResult.models,
204 });
205 expect(fromLegacy).toEqual(buildAntigravityModelsFromSession(sessionSetupResult));
206 expect(
207 buildAntigravityModelsFromSession({
208 ...sessionSetupResult,
209 configOptions: [{ ...modelConfig, options: [] }],
210 }),
211 ).toEqual([]);
212 });
213​
214 it("flattens native option groups without combining distinct model IDs", () => {
215 const models = buildAntigravityModelsFromSession({
216 configOptions: [
217 {
218 ...modelConfig,
219 currentValue: "gemini-pro-agent",
220 options: [
221 { groupId: "Flash", name: "Flash", options: [modelOptions[3]!, modelOptions[4]!] },
222 { groupId: "Pro", name: "Pro", options: [modelOptions[9]!, modelOptions[3]!] },
223 ],
224 },
225 ],
226 });
227 expect(models.map((model) => model.slug)).toEqual([
228 "gemini-3.7-flash-high",
229 "gemini-3.7-flash-medium",
230 "gemini-pro-agent",
231 ]);
232 expect(models.find((model) => model.isDefault)?.slug).toBe("gemini-pro-agent");
233 expect(models.find((model) => model.aliases?.includes(ANTIGRAVITY_DEFAULT_MODEL))?.slug).toBe(
234 "gemini-pro-agent",
235 );
236 });
237​
238 it("labels models that share a display name with their IDs", () => {
239 const models = buildAntigravityModelsFromSession({
240 configOptions: [
241 {
242 ...modelConfig,
243 currentValue: "gemini-3.8-flash",
244 options: [
245 { value: "gemini-3.8-flash", name: "Gemini 3.8 Flash" },
246 { value: "gemini-3.8-flash-preview", name: "Gemini 3.8 Flash" },
247 ],
248 },
249 ],
250 });
251 expect(models.map((model) => model.name)).toEqual([
252 "Gemini 3.8 Flash",
253 "Gemini 3.8 Flash (gemini-3.8-flash-preview)",
254 ]);
255 });
256​
257 it("offers each model only the thinking levels it reported when selected", () => {
258 const thinking = (currentValue: string) =>
259 ({
260 id: "thinking_level",
261 name: "Thinking Level",
262 category: "thought_level",
263 type: "select",
264 currentValue,
265 options: [
266 { value: "low", name: "Low" },
267 { value: "high", name: "High" },
268 ],
269 }) satisfies EffectAcpSchema.SessionConfigOption;
270 const models = buildAntigravityModelsFromSession(
271 {
272 configOptions: [
273 {
274 ...modelConfig,
275 currentValue: "gemini",
276 options: [
277 { value: "gemini", name: "Gemini" },
278 { value: "claude", name: "Claude" },
279 { value: "plain", name: "Plain" },
280 { value: "unseen", name: "Unseen" },
281 ],
282 },
283 thinking("high"),
284 ],
285 },
286 new Map([
287 ["claude", thinking("low")],
288 ["plain", null],
289 ]),
290 );
291 const thinkingOf = (slug: string) =>
292 models.find((model) => model.slug === slug)?.capabilities?.optionDescriptors?.[0];
293​
294 expect(thinkingOf("gemini")).toMatchObject({ id: "thinking_level", currentValue: "high" });
295 expect(thinkingOf("claude")).toMatchObject({ id: "thinking_level", currentValue: "low" });
296 expect(thinkingOf("plain")).toBeUndefined();
297 expect(thinkingOf("unseen")).toBeUndefined();
298 });
299​
300 it("keeps each model's probed thinking levels after a restart observes only the active model", () => {
301 const thinking = (levels: ReadonlyArray<string>) =>
302 ({
303 id: "thinking_level",
304 name: "Thinking Level",
305 category: "thought_level",
306 type: "select",
307 currentValue: "low",
308 options: levels.map((value) => ({ value, name: value })),
309 }) satisfies EffectAcpSchema.SessionConfigOption;
310 const deep = thinking(["low", "medium", "high", "xhigh"]);
311 const models = {
312 ...modelConfig,
313 currentValue: "neon",
314 options: [
315 { value: "neon", name: "Neon" },
316 { value: "carbon", name: "Carbon" },
317 { value: "fixed", name: "Fixed effort" },
318 ],
319 } satisfies EffectAcpSchema.SessionConfigOption;
320 const setup = { configOptions: [models, deep] };
321 const provider = {
322 instanceId,
323 driver,
324 status: "ready",
325 enabled: true,
326 installed: true,
327 version: null,
328 auth: { status: "authenticated" },
329 checkedAt: "2026-11-23T00:00:00.000Z",
330 slashCommands: [],
331 skills: [],
332 } as const;
333 // Sign-in or Refresh models walks every model, so each reports its own levels.
334 const probed = {
335 ...provider,
336 models: buildAntigravityModelsFromSession(
337 setup,
338 new Map([
339 ["carbon", thinking(["low", "medium", "high"])],
340 ["fixed", null],
341 ]),
342 ),
343 } satisfies ServerProvider;
344 // After a restart the provider has observed only the session's model.
345 const restarted = {
346 ...provider,
347 checkedAt: "2026-11-23T01:00:00.000Z",
348 models: buildAntigravityModelsFromSession(setup, new Map([["neon", deep]])),
349 } satisfies ServerProvider;
350​
351 const merged = mergeProviderSnapshot(probed, restarted);
352 const levelsOf = (slug: string) => {
353 const descriptor = merged.models.find((model) => model.slug === slug)?.capabilities
354 ?.optionDescriptors?.[0];
355 return descriptor?.type === "select" ? descriptor.options.map((option) => option.id) : [];
356 };
357​
358 expect(levelsOf("neon")).toEqual(["low", "medium", "high", "xhigh"]);
359 expect(levelsOf("carbon")).toEqual(["low", "medium", "high"]);
360 expect(levelsOf("fixed")).toEqual([]);
361 });
362});
363​
364it.layer(layerTest)("Antigravity provider snapshots", (it) => {
365 it.effect("does not probe or run helper safety checks while disabled", () =>
366 Effect.gen(function* () {
367 const harness = yield* makeHarness({ enabled: false });
368 const snapshot = yield* harness.provider.snapshot.refresh;
369 expect(snapshot).toMatchObject({
370 enabled: false,
371 installed: false,
372 status: "disabled",
373 auth: { status: "unknown" },
374 models: [],
375 setup: { canAuthenticate: true, canInstall: true },
376 showInteractionModeToggle: false,
377 supportsConversationRollback: true,
378 supportsTextGeneration: false,
379 });
380 expect(yield* Ref.get(harness.probeCalls)).toBe(0);
381 expect(yield* Ref.get(harness.safetyCalls)).toBe(0);
382 }),
383 );
384​
385 it.effect("treats initialize as installation proof, not account or model discovery", () =>
386 Effect.gen(function* () {
387 for (const auth of [
388 undefined,
389 { type: "oauth-personal", label: "Google account" },
390 { type: "oauth-business", label: "Gemini Enterprise" },
391 { type: "gemini-api-key", label: "Gemini API key" },
392 { type: "agent-platform", label: "Agent Platform" },
393 ]) {
394 const harness = yield* makeHarness(auth ? { auth } : {});
395 expect(yield* harness.provider.snapshot.getSnapshot).toMatchObject({
396 installed: false,
397 status: "warning",
398 auth: { status: "unknown" },
399 models: [],
400 });
401 yield* harness.initialize;
402 const snapshot = yield* harness.provider.snapshot.getSnapshot;
403 expect(snapshot).toMatchObject({
404 installed: true,
405 status: "warning",
406 version: "1.5.12",
407 auth: { status: "unknown", ...(auth ? { type: auth.type } : {}) },
408 message:
409 auth?.type === "gemini-api-key" || auth?.type === "agent-platform"
410 ? `Antigravity is installed. Connect with ${auth.label} to load models.`
411 : "Antigravity is installed. Google account access is not checked yet.",
412 models: [],
413 });
414 expect(yield* Ref.get(harness.probeCalls)).toBe(1);
415 }
416 }),
417 );
418​
419 it.effect("offers Auto only while the signed-in session advertises agy's own Auto", () =>
420 Effect.gen(function* () {
421 const harness = yield* makeHarness();
422 yield* harness.initialize;
423 const supportedModes = harness.provider.snapshot.getSnapshot.pipe(
424 Effect.map((snapshot) => snapshot.supportedRuntimeModes),
425 );
426 const withoutAuto = ["approval-required", "auto-accept-edits", "full-access"];
427 const startedWithAuto = {
428 ...started,
429 sessionSetupResult: {
430 ...sessionSetupResult,
431 modes: {
432 currentModeId: "default",
433 availableModes: [
434 { id: "default", name: "Default" },
435 { id: "auto", name: "Auto" },
436 ],
437 },
438 },
439 };
440 expect(yield* supportedModes).toEqual(withoutAuto);
441 yield* harness.provider.onSessionStarted(startedWithAuto);
442 expect(yield* supportedModes).toEqual([
443 "approval-required",
444 "auto-accept-edits",
445 "auto",
446 "full-access",
447 ]);
448 yield* harness.provider.onSessionStarted(started);
449 expect(yield* supportedModes).toEqual(withoutAuto);
450 yield* harness.provider.onSessionStarted(startedWithAuto);
451 yield* harness.provider.onSignedOut;
452 expect(yield* supportedModes).toEqual(withoutAuto);
453 const withAuto: ReadonlyArray<RuntimeMode> = [
454 "approval-required",
455 "auto-accept-edits",
456 "auto",
457 "full-access",
458 ];
459 expect(yield* Ref.get(harness.savedRuntimeModes)).toEqual([
460 withAuto,
461 withoutAuto,
462 withAuto,
463 withoutAuto,
464 ]);
465​
466 // A restart offers what the last session advertised before any session starts.
467 const restarted = yield* makeHarness({ rememberedRuntimeModes: withAuto });
468 yield* restarted.initialize;
469 expect(yield* restarted.provider.snapshot.getSnapshot).toMatchObject({
470 supportedRuntimeModes: withAuto,
471 });
472 }),
473 );
474​
475 it.effect("publishes session metadata and native commands without another health probe", () =>
476 Effect.gen(function* () {
477 const harness = yield* makeHarness();
478 yield* harness.initialize;
479 const nextReady = yield* Stream.toPull(
480 harness.provider.snapshot.streamChanges.pipe(
481 Stream.filter(
482 (snapshot) =>
483 snapshot.auth.status === "authenticated" && snapshot.slashCommands.length > 0,
484 ),
485 ),
486 );
487 yield* harness.provider.onSessionStarted(started, "/workspace");
488 yield* harness.provider.onAvailableCommands(commands, "/workspace");
489 const [snapshot] = yield* nextReady;
490 expect(snapshot).toMatchObject({
491 status: "ready",
492 auth: { status: "authenticated", type: "oauth-personal" },
493 supportsTextGeneration: true,
494 });
495 expect(snapshot.models).toEqual(buildAntigravityModelsFromSession(sessionSetupResult));
496 expect(snapshot.slashCommands).toEqual(expectedCommands);
497 expect((yield* harness.provider.snapshotForCwd("/workspace")).slashCommands).toEqual(
498 expectedCommands,
499 );
500 expect(yield* Ref.get(harness.probeCalls)).toBe(1);
501 }),
502 );
503​
504 it.effect("keeps a workspace's native commands when the catalog reports its own", () =>
505 Effect.gen(function* () {
506 const harness = yield* makeHarness();
507 yield* harness.initialize;
508 yield* harness.provider.onSessionStarted(started, "/workspace");
509 yield* harness.provider.onAvailableCommands(commands, "/workspace");
510 // The catalog probe runs in a scratch directory and reports no cwd.
511 yield* harness.provider.onAvailableCommands(commands.slice(1));
512 expect((yield* harness.provider.snapshotForCwd("/workspace")).slashCommands).toEqual(
513 expectedCommands,
514 );
515 expect((yield* harness.provider.snapshot.getSnapshot).slashCommands).toEqual(
516 expectedCommands.slice(1),
517 );
518 }),
519 );
520​
521 it.effect("clears all account metadata on sign-out and authentication failure", () =>
522 Effect.gen(function* () {
523 const auth = { type: "gemini-api-key", label: "Gemini API key" };
524 const harness = yield* makeHarness({ auth });
525 yield* harness.initialize;
526 for (const clear of [harness.provider.onSignedOut, harness.provider.onAuthRequired]) {
527 yield* harness.provider.onSessionStarted(started, "/workspace");
528 yield* harness.provider.onAvailableCommands(commands, "/workspace");
529 yield* clear;
530 expect(yield* harness.provider.snapshot.getSnapshot).toMatchObject({
531 installed: true,
532 status: "warning",
533 auth: { status: "unauthenticated", type: auth.type, label: auth.label },
534 message: "Connect with Gemini API key to use Antigravity and load models.",
535 models: [],
536 slashCommands: [],
537 skills: [],
538 workspaceSnapshots: [],
539 supportsTextGeneration: false,
540 });
541 yield* harness.provider.onAvailableCommands(commands, "/workspace");
542 yield* harness.provider.onConfigOptionsUpdated([modelConfig]);
543 expect((yield* harness.provider.snapshotForCwd("/workspace")).slashCommands).toEqual([]);
544 expect((yield* harness.provider.snapshot.getSnapshot).models).toEqual([]);
545 }
546 const refreshed = yield* harness.provider.snapshot.refresh;
547 expect(refreshed.auth).toEqual({
548 status: "unauthenticated",
549 type: auth.type,
550 label: auth.label,
551 });
552 expect(refreshed.message).toBe(
553 "Connect with Gemini API key to use Antigravity and load models.",
554 );
555 expect(refreshed.supportsTextGeneration).toBe(false);
556 }),
557 );
558​
559 it.effect("replaces live model choices and accepts an empty catalog", () =>
560 Effect.gen(function* () {
561 const harness = yield* makeHarness();
562 yield* harness.initialize;
563 yield* harness.provider.onSessionStarted(started, "/workspace");
564 yield* harness.provider.onAvailableCommands(commands, "/workspace");
565 const before = yield* harness.provider.snapshot.getSnapshot;
566 const configOptions = [
567 {
568 ...modelConfig,
569 currentValue: "gemini-3.8-flash-high",
570 options: modelOptions.slice(0, 3),
571 },
572 ];
573 const nextSnapshot = yield* Stream.toPull(
574 harness.provider.snapshot.streamChanges.pipe(
575 Stream.filter((snapshot) => snapshot.models.length === 3),
576 ),
577 );
578 yield* harness.provider.onConfigOptionsUpdated(configOptions);
579 expect((yield* nextSnapshot)[0]).toMatchObject({
580 models: buildAntigravityModelsFromSession({ configOptions }),
581 auth: before.auth,
582 workspaceSnapshots: before.workspaceSnapshots,
583 slashCommands: expectedCommands,
584 });
585 yield* harness.provider.onConfigOptionsUpdated([]);
586 expect((yield* harness.provider.snapshot.getSnapshot).models).toEqual([]);
587 }),
588 );
589​
590 it.effect(
591 "does not let live session thinking-level or model changes overwrite catalog defaults",
592 () =>
593 Effect.gen(function* () {
594 const harness = yield* makeHarness();
595 yield* harness.initialize;
596 const thinking = (
597 currentValue: string,
598 levels: ReadonlyArray<string> = ["low", "medium", "high", "xhigh"],
599 ) =>
600 ({
601 id: "thought_level",
602 name: "Thinking Level",
603 category: "thought_level",
604 type: "select",
605 currentValue,
606 options: levels.map((value) => ({ value, name: value })),
607 }) satisfies EffectAcpSchema.SessionConfigOption;
608 const catalogModels = {
609 ...modelConfig,
610 currentValue: "neon",
611 options: [
612 { value: "neon", name: "Neon" },
613 { value: "carbon", name: "Carbon" },
614 ],
615 } satisfies EffectAcpSchema.SessionConfigOption;
616 yield* harness.provider.onSessionStarted(
617 {
618 ...started,
619 sessionSetupResult: {
620 sessionId: "session-fresh",
621 configOptions: [catalogModels, thinking("high")],
622 },
623 },
624 "/workspace",
625 );
626​
627 // A live chat session setting thought_level=xhigh must not pollute the catalog default.
628 yield* harness.provider.onConfigOptionsUpdated([catalogModels, thinking("xhigh")]);
629 // A live chat session switching to another model with a custom level must neither move
630 // isDefault nor overwrite cached thinking defaults for that model.
631 const switchedToCarbon = {
632 ...catalogModels,
633 currentValue: "carbon",
634 } satisfies EffectAcpSchema.SessionConfigOption;
635 yield* harness.provider.onConfigOptionsUpdated([
636 switchedToCarbon,
637 thinking("low", ["low", "medium", "high"]),
638 ]);
639​
640 const snapshot = yield* harness.provider.snapshot.getSnapshot;
641 const neon = snapshot.models.find((model) => model.slug === "neon");
642 const carbon = snapshot.models.find((model) => model.slug === "carbon");
643 expect(neon?.isDefault).toBe(true);
644 expect(neon?.aliases).toContain(ANTIGRAVITY_DEFAULT_MODEL);
645 expect(neon?.capabilities?.optionDescriptors?.[0]).toMatchObject({
646 id: "thought_level",
647 currentValue: "high",
648 });
649 expect(carbon?.isDefault).toBeUndefined();
650 expect(carbon?.capabilities?.optionDescriptors).toEqual([]);
651​
652 // Updating an observed model's choices keeps its recorded default while still offered,
653 // and falls back if the agent removes that default.
654 yield* harness.provider.onConfigOptionsUpdated([
655 catalogModels,
656 thinking("max", ["low", "medium", "high", "xhigh", "max"]),
657 ]);
658 const expanded = (yield* harness.provider.snapshot.getSnapshot).models.find(
659 (model) => model.slug === "neon",
660 )?.capabilities?.optionDescriptors?.[0];
661 expect(expanded).toMatchObject({
662 id: "thought_level",
663 currentValue: "high",
664 options: [
665 { id: "low" },
666 { id: "medium" },
667 { id: "high" },
668 { id: "xhigh" },
669 { id: "max" },
670 ],
671 });
672​
673 yield* harness.provider.onConfigOptionsUpdated([
674 catalogModels,
675 thinking("medium", ["low", "medium"]),
676 ]);
677 const narrowed = (yield* harness.provider.snapshot.getSnapshot).models.find(
678 (model) => model.slug === "neon",
679 )?.capabilities?.optionDescriptors?.[0];
680 expect(narrowed).toMatchObject({
681 id: "thought_level",
682 currentValue: "medium",
683 options: [{ id: "low" }, { id: "medium" }],
684 });
685​
686 // A catalog probe records each model's default level and keeps the default model intact.
687 yield* harness.provider.onConfigOptionsUpdated(
688 [switchedToCarbon, thinking("medium", ["low", "medium", "high"])],
689 { fromCatalogProbe: true },
690 );
691 const probed = yield* harness.provider.snapshot.getSnapshot;
692 expect(probed.models.find((model) => model.slug === "neon")?.isDefault).toBe(true);
693 expect(
694 probed.models.find((model) => model.slug === "carbon")?.capabilities
695 ?.optionDescriptors?.[0],
696 ).toMatchObject({ id: "thought_level", currentValue: "medium" });
697​
698 // After a restart, resuming a session on another model at xhigh leaves unobserved
699 // models and default identity unset so the registry retains the cached defaults.
700 const restarted = yield* makeHarness();
701 yield* restarted.initialize;
702 yield* restarted.provider.onSessionStarted(
703 {
704 ...started,
705 sessionSetupResult: {
706 sessionId: "session-resumed",
707 configOptions: [switchedToCarbon, thinking("xhigh")],
708 },
709 },
710 "/workspace",
711 { resumed: true },
712 );
713 const merged = mergeProviderSnapshot(
714 probed,
715 yield* restarted.provider.snapshot.getSnapshot,
716 );
717 const mergedNeon = merged.models.find((model) => model.slug === "neon");
718 const mergedCarbon = merged.models.find((model) => model.slug === "carbon");
719 expect(mergedNeon?.isDefault).toBe(true);
720 expect(mergedNeon?.aliases).toContain(ANTIGRAVITY_DEFAULT_MODEL);
721 expect(mergedNeon?.capabilities?.optionDescriptors?.[0]).toMatchObject({
722 id: "thought_level",
723 currentValue: "medium",
724 });
725 expect(mergedCarbon?.isDefault).toBeUndefined();
726 expect(mergedCarbon?.aliases).toBeUndefined();
727 expect(mergedCarbon?.capabilities?.optionDescriptors?.[0]).toMatchObject({
728 id: "thought_level",
729 currentValue: "medium",
730 });
731​
732 // A later authoritative session start replaces the cached default model.
733 yield* restarted.provider.onSessionStarted(
734 {
735 ...started,
736 sessionSetupResult: {
737 sessionId: "session-fresh-after-restart",
738 configOptions: [switchedToCarbon, thinking("low", ["low", "medium", "high"])],
739 },
740 },
741 "/workspace",
742 );
743 const updatedAfterFresh = mergeProviderSnapshot(
744 merged,
745 yield* restarted.provider.snapshot.getSnapshot,
746 );
747 expect(updatedAfterFresh.models.find((model) => model.slug === "neon")?.isDefault).toBe(
748 undefined,
749 );
750 expect(updatedAfterFresh.models.find((model) => model.slug === "carbon")?.isDefault).toBe(
751 true,
752 );
753 expect(
754 updatedAfterFresh.models.find((model) => model.slug === "carbon")?.aliases,
755 ).toContain(ANTIGRAVITY_DEFAULT_MODEL);
756 }),
757 );
758​
759 it.effect("does not guess a version before a custom launcher's first handshake", () =>
760 Effect.gen(function* () {
761 const harness = yield* makeHarness();
762 yield* Deferred.succeed(harness.initialProbe, {
763 ...initializeResult,
764 agentInfo: { ...initializeResult.agentInfo, version: "unknown" },
765 });
766 yield* harness.initialUpdate;
767 expect((yield* harness.provider.snapshot.getSnapshot).version).toBeNull();
768 }),
769 );
770​
771 it.effect("does not replace a handshake version with an unknown custom-launcher probe", () =>
772 Effect.gen(function* () {
773 const harness = yield* makeHarness();
774 yield* harness.initialize;
775 yield* harness.provider.onSessionStarted({
776 ...started,
777 initializeResult: {
778 ...initializeResult,
779 agentInfo: { ...initializeResult.agentInfo, version: "1.5.13" },
780 },
781 });
782 yield* Ref.set(
783 harness.probe,
784 Effect.succeed({
785 ...initializeResult,
786 agentInfo: { ...initializeResult.agentInfo, version: "unknown" },
787 }),
788 );
789 expect((yield* harness.provider.snapshot.refresh).version).toBe("1.5.13");
790 }),
791 );
792​
793 it.effect("replaces one account's catalog instead of combining accounts", () =>
794 Effect.gen(function* () {
795 const harness = yield* makeHarness();
796 yield* harness.initialize;
797 yield* harness.provider.onSessionStarted(started);
798 yield* harness.provider.onSignedOut;
799 yield* harness.provider.onSessionStarted({
800 ...started,
801 sessionSetupResult: {
802 sessionId: "new-account-session",
803 configOptions: [
804 { ...modelConfig, currentValue: "gemini-pro-agent", options: [modelOptions[9]!] },
805 ],
806 },
807 });
808 expect(
809 (yield* harness.provider.snapshot.getSnapshot).models.map((model) => model.slug),
810 ).toEqual(["gemini-pro-agent"]);
811 }),
812 );
813​
814 it.effect("retains known account metadata when a local health check fails", () =>
815 Effect.gen(function* () {
816 const harness = yield* makeHarness();
817 yield* harness.initialize;
818 yield* harness.provider.onSessionStarted(started, "/workspace");
819 yield* harness.provider.onAvailableCommands(commands, "/workspace");
820 yield* Ref.set(
821 harness.probe,
822 Effect.fail(EffectAcpErrors.AcpRequestError.internalError("probe failed")),
823 );
824 const snapshot = yield* harness.provider.snapshot.refresh;
825 expect(snapshot).toMatchObject({
826 installed: true,
827 status: "error",
828 auth: { status: "authenticated" },
829 });
830 expect(snapshot.models).toEqual(buildAntigravityModelsFromSession(sessionSetupResult));
831 expect(snapshot.slashCommands).toEqual(expectedCommands);
832 expect(snapshot.workspaceSnapshots?.[0]?.cwd).toBe("/workspace");
833 }),
834 );
835​
836 it.effect("distinguishes missing executables from a failed installed executable", () =>
837 Effect.gen(function* () {
838 const harness = yield* makeHarness();
839 yield* harness.initialize;
840 const failures = [
841 {
842 error: new EffectAcpErrors.AcpSpawnError({ cause: { code: "ENOENT" } }),
843 installed: false,
844 },
845 {
846 error: new EffectAcpErrors.AcpSpawnError({ cause: { code: "EACCES" } }),
847 installed: true,
848 },
849 {
850 error: new ProviderSetupError({
851 instanceId,
852 operation: "resolve",
853 detail: "Antigravity is not installed.",
854 }),
855 installed: false,
856 },
857 {
858 error: new ProviderSetupError({
859 instanceId,
860 operation: "resolve",
861 detail:
862 "The managed Antigravity runtime changed on disk. Reinstall it in Antigravity setup.",
863 }),
864 installed: false,
865 },
866 ];
867 for (const { error, installed } of failures) {
868 yield* harness.provider.onSessionStarted(started, "/workspace");
869 yield* harness.provider.onAvailableCommands(commands, "/workspace");
870 yield* Ref.set(harness.probe, Effect.fail(error));
871 const snapshot = yield* harness.provider.snapshot.refresh;
872 expect(snapshot).toMatchObject({
873 installed,
874 status: "error",
875 auth: { status: "authenticated" },
876 });
877 expect(snapshot.models).toHaveLength(installed ? 11 : 0);
878 expect(snapshot.slashCommands).toHaveLength(installed ? 2 : 0);
879 expect(snapshot.workspaceSnapshots).toHaveLength(installed ? 1 : 0);
880 expect(snapshot.supportsTextGeneration).toBe(installed);
881 }
882 }),
883 );
884​
885 it.effect("does not let an old health result restore a signed-out account", () =>
886 Effect.gen(function* () {
887 const harness = yield* makeHarness();
888 yield* harness.initialize;
889 yield* harness.provider.onSessionStarted(started);
890 const releaseProbe = yield* Deferred.make<EffectAcpSchema.InitializeResponse>();
891 const probeEntered = yield* Deferred.make<void>();
892 yield* Ref.set(
893 harness.probe,
894 Deferred.succeed(probeEntered, undefined).pipe(
895 Effect.andThen(Deferred.await(releaseProbe)),
896 ),
897 );
898 const refresh = yield* harness.provider.snapshot.refresh.pipe(Effect.forkChild);
899 yield* Deferred.await(probeEntered);
900 yield* harness.provider.onSignedOut;
901 yield* Deferred.succeed(releaseProbe, initializeResult);
902 const snapshot = yield* Fiber.join(refresh);
903 expect(snapshot).toMatchObject({
904 auth: { status: "unauthenticated" },
905 models: [],
906 supportsTextGeneration: false,
907 });
908 }),
909 );
910​
911 it.effect("exposes helper support only when the supplied safety check allows it", () =>
912 Effect.gen(function* () {
913 const harness = yield* makeHarness({ safe: false });
914 yield* harness.initialize;
915 yield* harness.provider.onSessionStarted(started);
916 expect((yield* harness.provider.snapshot.getSnapshot).supportsTextGeneration).toBe(false);
917 yield* Ref.set(harness.safety, Effect.succeed(true));
918 yield* harness.provider.snapshot.refresh;
919 expect((yield* harness.provider.snapshot.getSnapshot).supportsTextGeneration).toBe(true);
920 }),
921 );
922​
923 it.effect("keeps discovered workspace skills through session and command updates", () =>
924 Effect.gen(function* () {
925 const harness = yield* makeHarness();
926 yield* harness.initialize;
927 const skills = [
928 {
929 name: "deploy",
930 description: "Ship it",
931 path: "/workspace/.agent/skills/deploy",
932 enabled: true,
933 },
934 ];
935 const discovered = yield* harness.provider.snapshotForCwd("/workspace", skills);
936 expect(discovered.skills).toEqual(skills);
937 yield* harness.provider.onSessionStarted(started, "/workspace");
938 yield* harness.provider.onAvailableCommands(commands, "/workspace");
939 const after = yield* harness.provider.snapshot.getSnapshot;
940 expect(after.workspaceSnapshots?.find((entry) => entry.cwd === "/workspace")?.skills).toEqual(
941 skills,
942 );
943 expect((yield* harness.provider.snapshotForCwd("/workspace")).skills).toEqual(skills);
944​
945 const rescanned = [
946 ...skills,
947 { name: "review", path: "/workspace/.agent/skills/review", enabled: true },
948 ];
949 yield* harness.provider.snapshotForCwd("/workspace", rescanned);
950 yield* harness.provider.onSessionStarted(started, "/workspace");
951 expect(
952 (yield* harness.provider.snapshot.getSnapshot).workspaceSnapshots?.find(
953 (entry) => entry.cwd === "/workspace",
954 )?.skills,
955 ).toEqual(rescanned);
956 }),
957 );
958​
959 it.effect("a session in an unscanned folder does not publish its skills as scanned", () =>
960 Effect.gen(function* () {
961 const harness = yield* makeHarness();
962 yield* harness.initialize;
963 const unscanned = () =>
964 Effect.map(harness.provider.snapshot.getSnapshot, (snapshot) => {
965 const entry = snapshot.workspaceSnapshots?.find((item) => item.cwd === "/workspace");
966 // ProviderRegistry skips the skill scan for a current entry that is not pending.
967 return entry === undefined || isProviderWorkspaceSnapshotPending(entry);
968 });
969​
970 yield* harness.provider.onSessionStarted(started, "/workspace");
971 expect(yield* unscanned()).toBe(true);
972 yield* harness.provider.onAvailableCommands(commands, "/workspace");
973 expect(yield* unscanned()).toBe(true);
974 }),
975 );
976​
977 it.effect("a skill scan leaves the folder entry it scanned from unchanged", () =>
978 Effect.gen(function* () {
979 const harness = yield* makeHarness();
980 yield* harness.initialize;
981 yield* harness.provider.onSessionStarted(started, "/workspace");
982 const published = yield* harness.provider.snapshot.getSnapshot;
983 const entryOf = (provider: ServerProvider) =>
984 provider.workspaceSnapshots?.find((entry) => entry.cwd === "/workspace");
985 const skills = [{ name: "deploy", path: "/workspace/.agent/skills/deploy", enabled: true }];
986​
987 yield* harness.provider.snapshotForCwd("/workspace", skills);
988 // ProviderRegistry saves the scan only if the entry it scanned from is still published.
989 const republished = mergeProviderSnapshot(
990 published,
991 yield* harness.provider.snapshot.getSnapshot,
992 );
993 expect(entryOf(republished)).toEqual(entryOf(published));
994 }),
995 );
996​
997 it.effect(
998 "keeps a scanned folder's own commands when another folder reports different ones",
999 () =>
1000 Effect.gen(function* () {
1001 const harness = yield* makeHarness();
1002 yield* harness.initialize;
1003 yield* harness.provider.onAvailableCommands(commands, "/a");
1004 yield* harness.provider.snapshotForCwd("/a", []);
1005 yield* harness.provider.onAvailableCommands(commands.slice(1), "/b");
1006 expect((yield* harness.provider.snapshotForCwd("/a", [])).slashCommands).toEqual(
1007 expectedCommands,
1008 );
1009 yield* harness.provider.onSessionStarted(started, "/a");
1010 expect(
1011 (yield* harness.provider.snapshot.getSnapshot).workspaceSnapshots?.find(
1012 (entry) => entry.cwd === "/a",
1013 )?.slashCommands,
1014 ).toEqual(expectedCommands);
1015 }),
1016 );
1017​
1018 it.effect("bounds workspace metadata without starting sessions for workspace lookup", () =>
1019 Effect.gen(function* () {
1020 const harness = yield* makeHarness();
1021 yield* harness.initialize;
1022 yield* harness.provider.onSessionStarted(started);
1023 for (let index = 0; index < 35; index++) {
1024 yield* harness.provider.onAvailableCommands(commands, `/workspace-${index}`);
1026 const snapshot = yield* harness.provider.snapshotForCwd("/workspace-34");
1027 expect(snapshot.workspaceSnapshots).toHaveLength(32);
1028 expect(snapshot.workspaceSnapshots?.[0]?.cwd).toBe("/workspace-3");
1029 expect(snapshot.slashCommands).toEqual(expectedCommands);
1030 expect(yield* Ref.get(harness.probeCalls)).toBe(1);
1031 }),
1032 );
1033});
1034​
1035it.layer(makeLayerTest(true))("Antigravity periodic health checks", (it) => {
1036 it.effect("rechecks a ready provider after one failed periodic check before publishing it", () =>
1037 Effect.gen(function* () {
1038 const harness = yield* makeHarness();
1039 yield* harness.initialize;
1040 yield* harness.provider.onSessionStarted(started, "/workspace");
1041 expect((yield* harness.provider.snapshot.getSnapshot).status).toBe("ready");
1042 const published = yield* Ref.make<ReadonlyArray<ServerProvider>>([]);
1043 yield* harness.provider.snapshot.streamChanges.pipe(
1044 Stream.runForEach((snapshot) => Ref.update(published, (all) => [...all, snapshot])),
1045 Effect.forkChild,
1046 );
1047 yield* Effect.yieldNow;
1048 yield* Ref.set(
1049 harness.probe,
1050 Effect.fail(EffectAcpErrors.AcpRequestError.internalError("probe failed")),
1051 );
1052​
1053 yield* TestClock.adjust("5 minutes");
1054​
1055 expect((yield* harness.provider.snapshot.getSnapshot).status).toBe("ready");
1056 expect((yield* Ref.get(published)).map((snapshot) => snapshot.status)).not.toContain("error");
1057​
1058 yield* Ref.set(harness.probe, Effect.succeed(initializeResult));
1059 yield* TestClock.adjust("30 seconds");
1060 const failProbe = yield* Deferred.make<void>();
1061 yield* Ref.set(
1062 harness.probe,
1063 Deferred.await(failProbe).pipe(
1064 Effect.andThen(
1065 Effect.fail(EffectAcpErrors.AcpRequestError.internalError("probe failed")),
1066 ),
1067 ),
1068 );
1069 yield* TestClock.adjust("5 minutes");
1070 yield* harness.provider.onSignedOut;
1071 yield* Deferred.succeed(failProbe, undefined);
1072 yield* TestClock.adjust("30 seconds");
1073​
1074 const auth = (yield* Ref.get(published)).map((snapshot) => snapshot.auth.status);
1075 expect(auth.slice(auth.indexOf("unauthenticated"))).not.toContain("authenticated");
1076 expect(auth.at(-1)).toBe("unauthenticated");
1077 }),
1078 );
1079});