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

AntigravityProvider.test.ts

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