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