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

ProviderInstanceRegistryLive.test.ts

633 lines25.1 KB

1import * as CodexResetCredit from "./codexResetCredit.ts";
2/**
3 * Multi-instance validation slices for `ProviderInstanceRegistryLive`.
4 *
5 * Two axes of the driver/registry refactor are exercised here:
6 *
7 * 1. **Same driver, many instances** — the "multi-instance codex slice"
8 * describe block below configures two independent `codex` instances and
9 * asserts each gets its own closures and identity. This is the
10 * multi-codex capability the refactor exists to unlock.
11 *
12 * 2. **Many drivers, one registry** — the "all drivers slice" describe
13 * block below configures one instance of every shipped driver
14 * (`codex`, `claudeAgent`, `cursor`, `grok`, `opencode`) in a single
15 * `ProviderInstanceConfigMap` and asserts the registry boots them all
16 * without cross-contamination. This proves the driver SPI is uniform
17 * across every provider — any driver plugs into the registry through
18 * the same `ProviderDriver` value contract.
19 *
20 * Every instance in these tests is configured with `enabled: false` so the
21 * provider-status checks short-circuit to pending/disabled snapshots
22 * without trying to spawn real `codex` / `claude` / `agent` / `grok` / `opencode`
23 * binaries. That keeps the assertions focused on registry routing
24 * behaviour rather than the runtime details of each provider.
25 */
26import { describe, expect, it } from "@effect/vitest";
27import * as NodeServices from "@effect/platform-node/NodeServices";
28import {
29 type ClaudeSettings,
30 type CodexSettings,
31 type CursorSettings,
32 type GrokSettings,
33 type OpenCodeSettings,
34 ProviderDriverKind,
35 type ProviderInstanceConfigMap,
36 ProviderInstanceId,
37} from "@t3tools/contracts";
38import { isHostWindows } from "@t3tools/shared/hostProcess";
39import * as DateTime from "effect/DateTime";
40import * as Effect from "effect/Effect";
41import * as FileSystem from "effect/FileSystem";
42import * as Layer from "effect/Layer";
43import * as Path from "effect/Path";
44import * as Stream from "effect/Stream";
45import { HttpClient, HttpClientResponse } from "effect/unstable/http";
46​
47import * as BackgroundPolicy from "../../background/BackgroundPolicy.ts";
48import { AntigravityInstallation } from "../AntigravityInstallation.ts";
49import { ServerConfig } from "../../config.ts";
50import { expandHomePath } from "../../pathExpansion.ts";
51import { ServerSettingsService } from "../../serverSettings.ts";
52import { ClaudeDriver, type ClaudeDriverEnv } from "../Drivers/ClaudeDriver.ts";
53import { CodexDriver, type CodexDriverEnv } from "../Drivers/CodexDriver.ts";
54import { CursorDriver, type CursorDriverEnv } from "../Drivers/CursorDriver.ts";
55import { GrokDriver, type GrokDriverEnv } from "../Drivers/GrokDriver.ts";
56import { OpenCodeDriver, type OpenCodeDriverEnv } from "../Drivers/OpenCodeDriver.ts";
57import * as ModelManifest from "../ModelManifest.ts";
58import { OpenCodeRuntimeLive } from "../opencodeRuntime.ts";
59import { NoOpProviderEventLoggers, ProviderEventLoggers } from "./ProviderEventLoggers.ts";
60import { makeProviderInstanceRegistry } from "./ProviderInstanceRegistryLive.ts";
61import { ProviderOrchestrationAdapterInfrastructureLive } from "./ProviderOrchestrationAdapterInfrastructure.ts";
62​
63const TestHttpClientLive = Layer.succeed(
64 HttpClient.HttpClient,
65 HttpClient.make((request) =>
66 Effect.succeed(HttpClientResponse.fromWeb(request, Response.json({ version: "0.0.0" }))),
67 ),
68);
69​
70const TEST_EPOCH = DateTime.makeUnsafe("1970-01-01T00:00:00.000Z");
71​
72const BackgroundPolicyAlwaysRunLayer = Layer.mock(BackgroundPolicy.BackgroundPolicy)({
73 reportClientActivity: () => Effect.void,
74 removeRpcClient: () => Effect.void,
75 reportHostPowerState: () => Effect.void,
76 snapshot: Effect.succeed({
77 hostPower: {
78 source: "unknown",
79 idle: "unknown",
80 idleSeconds: null,
81 locked: "unknown",
82 suspended: false,
83 onBattery: "unknown",
84 lowPowerMode: "unknown",
85 thermalState: "unknown",
86 stale: true,
87 updatedAt: TEST_EPOCH,
88 },
89 leases: [],
90 activeForegroundLeaseCount: 0,
91 activeScopeKeys: [],
92 shouldRunOpportunisticWork: true,
93 updatedAt: TEST_EPOCH,
94 }),
95 streamChanges: Stream.empty,
96 hasDemand: () => Effect.succeed(true),
97 shouldRunScopeWork: () => Effect.succeed(true),
98 shouldRunOpportunisticWork: Effect.succeed(true),
99});
100​
101const makeCodexConfig = (overrides: Partial<CodexSettings>): CodexSettings => ({
102 enabled: false,
103 binaryPath: "codex",
104 homePath: "",
105 shadowHomePath: "",
106 launchArgs: "",
107 customModels: [],
108 ...overrides,
109});
110​
111const makeClaudeConfig = (overrides: Partial<ClaudeSettings>): ClaudeSettings => ({
112 enabled: false,
113 binaryPath: "claude",
114 homePath: "",
115 customModels: [],
116 launchArgs: "",
117 autoCompactWindow: "",
118 ...overrides,
119});
120​
121const makeCursorConfig = (overrides: Partial<CursorSettings>): CursorSettings => ({
122 enabled: false,
123 customModels: [],
124 ...overrides,
125});
126​
127const makeGrokConfig = (overrides: Partial<GrokSettings>): GrokSettings => ({
128 enabled: false,
129 binaryPath: "grok",
130 customModels: [],
131 ...overrides,
132});
133​
134const makeOpenCodeConfig = (overrides: Partial<OpenCodeSettings>): OpenCodeSettings => ({
135 enabled: false,
136 binaryPath: "opencode",
137 serverUrl: "",
138 serverPassword: "",
139 customModels: [],
140 ...overrides,
141});
142​
143const makeTildeProviderFixtures = Effect.fn(
144 "ProviderInstanceRegistryLive.test.makeTildeProviderFixtures",
145)(function* () {
146 const fileSystem = yield* FileSystem.FileSystem;
147 const path = yield* Path.Path;
148 const homePath = expandHomePath("~");
149 const fixtureDir = yield* fileSystem.makeTempDirectoryScoped({
150 directory: homePath,
151 prefix: ".t3-provider-path-test-",
152 });
153 const codexPath = path.join(fixtureDir, "codex");
154 const claudePath = path.join(fixtureDir, "claude");
155 const claudeHomePath = path.join(fixtureDir, "claude-home");
156 const codexScriptPath = path.join(fixtureDir, "codex-script.json");
157 const codexFixtureDir = path.join(import.meta.dirname, "../testFixtures");
158​
159 yield* fileSystem.copyFile(path.join(codexFixtureDir, "codexCollabMockPeer.sh"), codexPath);
160 yield* fileSystem.copyFile(
161 path.join(codexFixtureDir, "codexCollabMockPeer.mjs"),
162 path.join(fixtureDir, "codexCollabMockPeer.mjs"),
163 );
164 yield* fileSystem.copyFile(
165 path.join(codexFixtureDir, "codexMultiAgentWire.json"),
166 path.join(fixtureDir, "codexMultiAgentWire.json"),
167 );
168 yield* fileSystem.writeFileString(
169 codexScriptPath,
170 // @effect-diagnostics-next-line preferSchemaOverJson:off - fixed script document read by the external Codex mock peer.
171 JSON.stringify({ rootThreadId: "probe-thread", notifications: [] }),
172 );
173 yield* fileSystem.chmod(codexPath, 0o755);
174​
175 yield* fileSystem.writeFileString(
176 claudePath,
177 [
178 "#!/usr/bin/env node",
179 'import * as NodeReadline from "node:readline";',
180 'if (process.argv.includes("--version")) {',
181 ' process.stdout.write("claude 2.1.219\\n");',
182 " process.exit(0);",
183 "}",
184 "const lines = NodeReadline.createInterface({ input: process.stdin });",
185 'lines.on("line", (line) => {',
186 " const message = JSON.parse(line);",
187 ' if (message.type !== "control_request" || message.request?.subtype !== "initialize") return;',
188 " process.stdout.write(JSON.stringify({",
189 ' type: "control_response",',
190 " response: {",
191 ' subtype: "success",',
192 " request_id: message.request_id,",
193 " response: {",
194 " commands: [], agents: [], models: [],",
195 ' output_style: "default", available_output_styles: ["default"],',
196 ' account: { email: "test@example.com", subscriptionType: "pro", tokenSource: "oauth" },',
197 " },",
198 " },",
199 ' }) + "\\n");',
200 "});",
201 "setInterval(() => {}, 1_000);",
202 "",
203 ].join("\n"),
204 );
205 yield* fileSystem.chmod(claudePath, 0o755);
206 yield* fileSystem.makeDirectory(claudeHomePath);
207​
208 const asTildePath = (filePath: string) => `~/${path.relative(homePath, filePath)}`;
209 return {
210 codexBinaryPath: asTildePath(codexPath),
211 claudeBinaryPath: asTildePath(claudePath),
212 claudeHomePath,
213 codexScriptPath,
214 };
215});
216​
217describe("ProviderInstanceRegistryLive — multi-instance codex slice", () => {
218 // `ServerConfig.layerTest` needs `FileSystem` to materialize its scratch
219 // directory. `Layer.merge` just unions requirements, so we have to push
220 // `NodeServices.layer` through `Layer.provideMerge` to satisfy that
221 // dependency while still surfacing NodeServices to the test body (the
222 // codex driver's `create` yields `ChildProcessSpawner` directly).
223 const baseLayer = ServerConfig.layerTest(process.cwd(), {
224 prefix: "provider-instance-registry-test",
225 }).pipe(
226 Layer.provideMerge(NodeServices.layer),
227 Layer.provideMerge(BackgroundPolicyAlwaysRunLayer),
228 Layer.provideMerge(ServerSettingsService.layerTest()),
229 Layer.provideMerge(TestHttpClientLive),
230 Layer.provideMerge(ServerSettingsService.layerTest()),
231 Layer.provideMerge(Layer.succeed(ProviderEventLoggers, NoOpProviderEventLoggers)),
232 Layer.provideMerge(ModelManifest.layerTest),
233 Layer.provideMerge(CodexResetCredit.layerTest),
234 );
235 const testLayer = ProviderOrchestrationAdapterInfrastructureLive.pipe(
236 Layer.provideMerge(baseLayer),
237 );
238​
239 it.live("boots two independent codex instances from a ProviderInstanceConfigMap", () =>
240 Effect.gen(function* () {
241 const personalId = ProviderInstanceId.make("codex_personal");
242 const workId = ProviderInstanceId.make("codex_work");
243 const codexDriverKind = ProviderDriverKind.make("codex");
244​
245 const configMap: ProviderInstanceConfigMap = {
246 [personalId]: {
247 driver: codexDriverKind,
248 displayName: "Codex (personal)",
249 enabled: false,
250 config: makeCodexConfig({
251 binaryPath: "/opt/codex-personal/bin/codex",
252 homePath: "/home/julius/.codex_personal",
253 customModels: ["personal-preview"],
254 }),
255 },
256 [workId]: {
257 driver: codexDriverKind,
258 displayName: "Codex (work)",
259 enabled: false,
260 config: makeCodexConfig({
261 binaryPath: "/opt/codex-work/bin/codex",
262 homePath: "/home/julius/.codex",
263 customModels: ["work-preview"],
264 }),
265 },
266 };
267​
268 const { registry } = yield* makeProviderInstanceRegistry<CodexDriverEnv>({
269 drivers: [CodexDriver],
270 configMap,
271 });
272​
273 const instances = yield* registry.listInstances;
274 expect(instances.map((instance) => instance.instanceId).toSorted()).toEqual(
275 [personalId, workId].toSorted(),
276 );
277 expect(instances.every((instance) => instance.driverKind === codexDriverKind)).toBe(true);
278 expect(instances.map((instance) => instance.displayName).toSorted()).toEqual(
279 ["Codex (personal)", "Codex (work)"].toSorted(),
280 );
281​
282 // Each instance must be retrievable by id and carry its *own* closures.
283 const personal = yield* registry.getInstance(personalId);
284 const work = yield* registry.getInstance(workId);
285 expect(personal).toBeDefined();
286 expect(work).toBeDefined();
287 expect(personal!.orchestrationAdapter).not.toBe(work!.orchestrationAdapter);
288 expect(personal!.textGeneration).not.toBe(work!.textGeneration);
289 expect(personal!.snapshot).not.toBe(work!.snapshot);
290​
291 // Snapshots identify themselves by instanceId + driver — this is
292 // what makes per-instance routing distinguishable downstream.
293 const personalSnapshot = yield* personal!.snapshot.getSnapshot;
294 expect(personalSnapshot.instanceId).toBe(personalId);
295 expect(personalSnapshot.driver).toBe(codexDriverKind);
296 expect(personalSnapshot.enabled).toBe(false);
297 // The layout resolves the configured home through the host Path.
298 const path = yield* Path.Path;
299 expect(personalSnapshot.continuation?.groupKey).toBe(
300 `codex:home:${path.resolve("/home/julius/.codex_personal")}`,
301 );
302​
303 const workSnapshot = yield* work!.snapshot.getSnapshot;
304 expect(workSnapshot.instanceId).toBe(workId);
305 expect(workSnapshot.driver).toBe(codexDriverKind);
306 expect(workSnapshot.enabled).toBe(false);
307 expect(workSnapshot.continuation?.groupKey).toBe(
308 `codex:home:${path.resolve("/home/julius/.codex")}`,
309 );
310​
311 // Nothing goes to the unavailable bucket — both drivers are registered.
312 const unavailable = yield* registry.listUnavailable;
313 expect(unavailable).toEqual([]);
314 }).pipe(Effect.provide(testLayer)),
315 );
316​
317 it.live("treats an explicit in-config enabled:false as disabling despite the envelope", () =>
318 Effect.gen(function* () {
319 // Old settings files can carry both flags with conflicting values.
320 // The explicit false must win so a user's disable is never undone.
321 const staleId = ProviderInstanceId.make("codex_stale");
322 const configMap: ProviderInstanceConfigMap = {
323 [staleId]: {
324 driver: ProviderDriverKind.make("codex"),
325 enabled: true,
326 config: makeCodexConfig({ enabled: false }),
327 },
328 };
329​
330 const { registry } = yield* makeProviderInstanceRegistry({
331 drivers: [CodexDriver],
332 configMap,
333 });
334​
335 const instance = yield* registry.getInstance(staleId);
336 expect(instance).toBeDefined();
337 expect(instance!.enabled).toBe(false);
338 const snapshot = yield* instance!.snapshot.getSnapshot;
339 expect(snapshot.enabled).toBe(false);
340 }).pipe(Effect.provide(testLayer)),
341 );
342​
343 it.live("runs Codex and Claude readiness probes from configured tilde paths", () =>
344 Effect.gen(function* () {
345 if (yield* isHostWindows) return;
346​
347 const fixtures = yield* makeTildeProviderFixtures();
348​
349 const codexId = ProviderInstanceId.make("codex_tilde");
350 const claudeId = ProviderInstanceId.make("claude_tilde");
351 const configMap: ProviderInstanceConfigMap = {
352 [codexId]: {
353 driver: ProviderDriverKind.make("codex"),
354 enabled: true,
355 environment: [
356 {
357 name: "T3_CODEX_COLLAB_SCRIPT",
358 value: fixtures.codexScriptPath,
359 sensitive: false,
360 },
361 ],
362 config: makeCodexConfig({ enabled: true, binaryPath: fixtures.codexBinaryPath }),
363 },
364 [claudeId]: {
365 driver: ProviderDriverKind.make("claudeAgent"),
366 enabled: true,
367 config: makeClaudeConfig({
368 enabled: true,
369 binaryPath: fixtures.claudeBinaryPath,
370 homePath: fixtures.claudeHomePath,
371 }),
372 },
373 };
374​
375 const { registry } = yield* makeProviderInstanceRegistry<CodexDriverEnv | ClaudeDriverEnv>({
376 drivers: [CodexDriver, ClaudeDriver],
377 configMap,
378 });
379 const codex = yield* registry.getInstance(codexId);
380 const claude = yield* registry.getInstance(claudeId);
381 expect(codex).toBeDefined();
382 expect(claude).toBeDefined();
383​
384 const [codexSnapshot, claudeSnapshot] = yield* Effect.all(
385 [codex!.snapshot.refresh, claude!.snapshot.refresh],
386 { concurrency: "unbounded" },
387 );
388 expect(codexSnapshot).toMatchObject({ status: "ready", installed: true, version: "0.0.0" });
389 expect(claudeSnapshot).toMatchObject({
390 status: "ready",
391 installed: true,
392 version: "2.1.219",
393 });
394 }).pipe(Effect.provide(testLayer)),
395 );
396​
397 it.live(
398 "shadows instances whose driver is not registered in this build without failing boot",
399 () =>
400 Effect.gen(function* () {
401 const codexId = ProviderInstanceId.make("codex_main");
402 const ghostId = ProviderInstanceId.make("ghost_main");
403​
404 const configMap: ProviderInstanceConfigMap = {
405 [codexId]: {
406 driver: ProviderDriverKind.make("codex"),
407 enabled: false,
408 config: makeCodexConfig({}),
409 },
410 [ghostId]: {
411 driver: ProviderDriverKind.make("ghostDriver"),
412 displayName: "A fork-only driver we don't ship",
413 enabled: false,
414 config: { arbitrary: "payload", preserved: true },
415 },
416 };
417​
418 const { registry } = yield* makeProviderInstanceRegistry<CodexDriverEnv>({
419 drivers: [CodexDriver],
420 configMap,
421 });
422​
423 const instances = yield* registry.listInstances;
424 expect(instances).toHaveLength(1);
425 expect(instances[0]!.instanceId).toBe(codexId);
426​
427 const unavailable = yield* registry.listUnavailable;
428 expect(unavailable).toHaveLength(1);
429 const ghost = unavailable[0]!;
430 expect(ghost.instanceId).toBe(ghostId);
431 expect(ghost.driver).toBe("ghostDriver");
432 expect(ghost.availability).toBe("unavailable");
433 expect(ghost.unavailableReason).toMatch(/ghostDriver/);
434 }).pipe(Effect.provide(testLayer)),
435 );
436});
437​
438describe("ProviderInstanceRegistryLive — all drivers slice", () => {
439 // All drivers need `NodeServices` (ChildProcessSpawner + FileSystem +
440 // Path). `OpenCodeDriver.create` additionally yields `OpenCodeRuntime`
441 // at construction time, so we wire `OpenCodeRuntimeLive` into the stack.
442 // `OpenCodeRuntimeLive` bundles its own `NetService.layer` via
443 // `Layer.provide`, so the only external requirement it still exposes is
444 // `ChildProcessSpawner` — resolved here by piping it through
445 // `provideMerge(NodeServices.layer)`.
446 //
447 // The nested `provideMerge`s read bottom-up: `NodeServices.layer`
448 // provides `OpenCodeRuntimeLive`'s deps while keeping its own outputs
449 // surfaced; that merged layer then provides `ServerConfig.layerTest`'s
450 // `FileSystem` dep while keeping everything else surfaced to the test.
451 const infraLayer = OpenCodeRuntimeLive.pipe(Layer.provideMerge(NodeServices.layer));
452 const baseLayer = AntigravityInstallation.layer.pipe(
453 Layer.provideMerge(
454 ServerConfig.layerTest(process.cwd(), {
455 prefix: "provider-instance-registry-all-drivers-test",
456 }),
457 ),
458 Layer.provideMerge(infraLayer),
459 Layer.provideMerge(BackgroundPolicyAlwaysRunLayer),
460 Layer.provideMerge(ServerSettingsService.layerTest()),
461 Layer.provideMerge(TestHttpClientLive),
462 Layer.provideMerge(ServerSettingsService.layerTest()),
463 Layer.provideMerge(Layer.succeed(ProviderEventLoggers, NoOpProviderEventLoggers)),
464 Layer.provideMerge(ModelManifest.layerTest),
465 Layer.provideMerge(CodexResetCredit.layerTest),
466 );
467 const testLayer = ProviderOrchestrationAdapterInfrastructureLive.pipe(
468 Layer.provideMerge(baseLayer),
469 );
470​
471 it.live("boots one instance of every shipped driver from a single config map", () =>
472 Effect.gen(function* () {
473 const codexId = ProviderInstanceId.make("codex_default");
474 const claudeId = ProviderInstanceId.make("claude_default");
475 const cursorId = ProviderInstanceId.make("cursor_default");
476 const grokId = ProviderInstanceId.make("grok_default");
477 const openCodeId = ProviderInstanceId.make("opencode_default");
478​
479 const codexDriverKind = ProviderDriverKind.make("codex");
480 const claudeDriverKind = ProviderDriverKind.make("claudeAgent");
481 const cursorDriverKind = ProviderDriverKind.make("cursor");
482 const grokDriverKind = ProviderDriverKind.make("grok");
483 const openCodeDriverKind = ProviderDriverKind.make("opencode");
484​
485 const configMap: ProviderInstanceConfigMap = {
486 [codexId]: {
487 driver: codexDriverKind,
488 displayName: "Codex",
489 enabled: false,
490 config: makeCodexConfig({ homePath: "/home/julius/.codex" }),
491 },
492 [claudeId]: {
493 driver: claudeDriverKind,
494 displayName: "Claude",
495 enabled: false,
496 config: makeClaudeConfig({
497 homePath: "/home/julius/.claude-work",
498 launchArgs: "--verbose",
499 }),
500 },
501 [cursorId]: {
502 driver: cursorDriverKind,
503 displayName: "Cursor",
504 enabled: false,
505 config: makeCursorConfig({}),
506 },
507 [grokId]: {
508 driver: grokDriverKind,
509 displayName: "Grok",
510 enabled: false,
511 config: makeGrokConfig({}),
512 },
513 [openCodeId]: {
514 driver: openCodeDriverKind,
515 displayName: "OpenCode",
516 enabled: false,
517 config: makeOpenCodeConfig({}),
518 },
519 };
520​
521 const { registry } = yield* makeProviderInstanceRegistry<
522 CodexDriverEnv | ClaudeDriverEnv | CursorDriverEnv | GrokDriverEnv | OpenCodeDriverEnv
523 >({
524 drivers: [CodexDriver, ClaudeDriver, CursorDriver, GrokDriver, OpenCodeDriver],
525 configMap,
526 });
527​
528 // Every configured instance must materialize — none downgraded to a
529 // shadow snapshot, because every driver in the map is registered.
530 const unavailable = yield* registry.listUnavailable;
531 expect(unavailable).toEqual([]);
532​
533 const instances = yield* registry.listInstances;
534 expect(instances).toHaveLength(5);
535 expect(instances.map((instance) => instance.instanceId).toSorted()).toEqual(
536 [codexId, claudeId, cursorId, grokId, openCodeId].toSorted(),
537 );
538​
539 // Instance lookup by id resolves each instance to its own bundle —
540 // this is how rest-of-server routes turn/session calls in the new
541 // model. Each driver's bundle carries its advertised `driverKind`.
542 const codex = yield* registry.getInstance(codexId);
543 const claude = yield* registry.getInstance(claudeId);
544 const cursor = yield* registry.getInstance(cursorId);
545 const grok = yield* registry.getInstance(grokId);
546 const openCode = yield* registry.getInstance(openCodeId);
547 expect(codex?.driverKind).toBe(codexDriverKind);
548 expect(claude?.driverKind).toBe(claudeDriverKind);
549 expect(cursor?.driverKind).toBe(cursorDriverKind);
550 expect(grok?.driverKind).toBe(grokDriverKind);
551 expect(openCode?.driverKind).toBe(openCodeDriverKind);
552 expect(codex?.displayName).toBe("Codex");
553 expect(claude?.displayName).toBe("Claude");
554 expect(cursor?.displayName).toBe("Cursor");
555 expect(grok?.displayName).toBe("Grok");
556 expect(openCode?.displayName).toBe("OpenCode");
557​
558 // Every instance owns its own set of closures — no sharing across
559 // drivers. `orchestrationAdapter` / `textGeneration` / `snapshot` are all
560 // distinct references even when two instances happen to share a
561 // trait (e.g. Cursor + others all use a stub-or-real
562 // `textGeneration`; they must still be different object values).
563 const adapters = [
564 codex!.orchestrationAdapter,
565 claude!.orchestrationAdapter,
566 cursor!.orchestrationAdapter,
567 grok!.orchestrationAdapter,
568 openCode!.orchestrationAdapter,
569 ];
570 expect(new Set(adapters).size).toBe(adapters.length);
571 const textGenerations = [
572 codex!.textGeneration,
573 claude!.textGeneration,
574 cursor!.textGeneration,
575 grok!.textGeneration,
576 openCode!.textGeneration,
577 ];
578 expect(new Set(textGenerations).size).toBe(textGenerations.length);
579 const snapshots = [
580 codex!.snapshot,
581 claude!.snapshot,
582 cursor!.snapshot,
583 grok!.snapshot,
584 openCode!.snapshot,
585 ];
586 expect(new Set(snapshots).size).toBe(snapshots.length);
587​
588 // Snapshots identify themselves by `instanceId` + `driver` so
589 // downstream aggregation in `ProviderRegistry` can tell instances
590 // apart even when two share a driver. With `enabled: false`, the
591 // check short-circuits and we get a disabled/pending snapshot back
592 // — that's enough signal to validate the stamping wrapper without
593 // spawning real binaries.
594 const codexSnapshot = yield* codex!.snapshot.getSnapshot;
595 expect(codexSnapshot.instanceId).toBe(codexId);
596 expect(codexSnapshot.driver).toBe(codexDriverKind);
597 expect(codexSnapshot.enabled).toBe(false);
598 expect(codexSnapshot.continuation?.groupKey).toBe(
599 `codex:home:${(yield* Path.Path).resolve("/home/julius/.codex")}`,
600 );
601​
602 const claudeSnapshot = yield* claude!.snapshot.getSnapshot;
603 expect(claudeSnapshot.instanceId).toBe(claudeId);
604 expect(claudeSnapshot.driver).toBe(claudeDriverKind);
605 expect(claudeSnapshot.enabled).toBe(false);
606 expect(claudeSnapshot.continuation?.groupKey).toBe(
607 `claude:home:${(yield* Path.Path).resolve("/home/julius/.claude-work")}`,
608 );
609​
610 const cursorSnapshot = yield* cursor!.snapshot.getSnapshot;
611 expect(cursorSnapshot.instanceId).toBe(cursorId);
612 expect(cursorSnapshot.driver).toBe(cursorDriverKind);
613 expect(cursorSnapshot.enabled).toBe(false);
614 expect(cursorSnapshot.continuation?.groupKey).toBe(
615 `${cursorDriverKind}:instance:${cursorId}`,
616 );
617​
618 const grokSnapshot = yield* grok!.snapshot.getSnapshot;
619 expect(grokSnapshot.instanceId).toBe(grokId);
620 expect(grokSnapshot.driver).toBe(grokDriverKind);
621 expect(grokSnapshot.enabled).toBe(false);
622 expect(grokSnapshot.continuation?.groupKey).toBe(`${grokDriverKind}:instance:${grokId}`);
623​
624 const openCodeSnapshot = yield* openCode!.snapshot.getSnapshot;
625 expect(openCodeSnapshot.instanceId).toBe(openCodeId);
626 expect(openCodeSnapshot.driver).toBe(openCodeDriverKind);
627 expect(openCodeSnapshot.enabled).toBe(false);
628 expect(openCodeSnapshot.continuation?.groupKey).toBe(
629 `${openCodeDriverKind}:instance:${openCodeId}`,
630 );
631 }).pipe(Effect.provide(testLayer)),
632 );
633});