@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 99 lines 3.62 KB
Raw
1 import { describe, expect, it } from "@effect/vitest";
2 import {
3 PrimaryConnectionTarget,
4 type EnvironmentPresentation,
5 type NetworkStatus,
6 } from "@t3tools/client-runtime/connection";
7 import type { EnvironmentCatalogState } from "@t3tools/client-runtime/state/connections";
8 import type { EnvironmentShellSummary } from "@t3tools/client-runtime/state/shell";
9 import { EnvironmentId, type ServerConfig } from "@t3tools/contracts";
10 import * as Option from "effect/Option";
11 import { Atom, AtomRegistry } from "effect/reactivity";
12
13 import { createWorkspaceConnectionAtoms } from "./workspace-connection-atoms";
14 import { projectWorkspaceState } from "./workspaceModel";
15 import { projectEnvironmentConnectionSummary as projectWorkspaceEnvironment } from "@t3tools/client-runtime/state/presentation";
16
17 const ID = EnvironmentId.make("environment-1");
18 function presentation(): EnvironmentPresentation {
19 return {
20 entry: {
21 target: new PrimaryConnectionTarget({
22 environmentId: ID,
23 label: "Mac",
24 httpBaseUrl: "https://example.test",
25 wsBaseUrl: "wss://example.test",
26 }),
27 enabled: true,
28 profile: Option.none(),
29 },
30 connection: { phase: "connected", error: null, traceId: null },
31 serverConfig: null,
32 refusedRouteIds: [],
33 };
34 }
35 function harness() {
36 const source = Atom.make<EnvironmentPresentation | null>(presentation());
37 const catalog = Atom.make<EnvironmentCatalogState>({
38 isReady: true,
39 entries: new Map([[ID, presentation().entry]]),
40 });
41 const network = Atom.make<NetworkStatus>("online");
42 const atoms = createWorkspaceConnectionAtoms({
43 catalogValueAtom: catalog,
44 networkStatusValueAtom: network,
45 presentationAtom: () => source,
46 });
47 const registry = AtomRegistry.make();
48 return { source, catalog, network, registry, ...atoms };
49 }
50
51 describe("workspace connection subscriptions", () => {
52 it("keeps connection consumers stable across shell and provider updates", () => {
53 const h = harness();
54 const shell = Atom.make<EnvironmentShellSummary>({
55 hasSnapshot: true,
56 hasSynchronizingShell: false,
57 firstError: null,
58 });
59 const broadState = Atom.make((get) =>
60 projectWorkspaceState({
61 isReady: get(h.catalog).isReady,
62 networkStatus: get(h.network),
63 environments: [projectWorkspaceEnvironment(ID, get(h.source)!)],
64 shellSummary: get(shell),
65 hasSyncingConnectedEnvironment: false,
66 }),
67 );
68 const initial = h.registry.get(h.stateAtom);
69 const initialEnvironments = h.registry.get(h.environmentsAtom);
70 let broadChanges = 0;
71 let connectionChanges = 0;
72 const stopBroad = h.registry.subscribe(broadState, () => broadChanges++);
73 const stopNarrow = h.registry.subscribe(h.stateAtom, () => connectionChanges++);
74 try {
75 for (let index = 0; index < 20; index++) {
76 h.registry.set(shell, {
77 ...h.registry.get(shell),
78 hasSynchronizingShell: index % 2 === 0,
79 });
80 h.registry.get(broadState);
81 h.registry.get(h.stateAtom);
82 }
83 expect(broadChanges).toBe(20);
84 expect(connectionChanges).toBe(0);
85 for (let index = 0; index < 4; index++) {
86 const config = { cwd: `/workspace-${index}` } as ServerConfig;
87 h.registry.set(h.source, { ...presentation(), serverConfig: config });
88 expect(h.registry.get(h.source)?.serverConfig).toBe(config);
89 expect(h.registry.get(h.stateAtom)).toBe(initial);
90 expect(h.registry.get(h.environmentsAtom)).toBe(initialEnvironments);
91 }
92 expect(connectionChanges).toBe(0);
93 } finally {
94 stopBroad();
95 stopNarrow();
96 h.registry.dispose();
97 }
98 });
99 });