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

AntigravityProvider.test.ts

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