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