Open History to see the last commit
1import type { EnvironmentShellSummary } from "@v12/client-runtime/state/shell";
2import { BearerConnectionProfile, BearerConnectionTarget } from "@v12/client-runtime/connection";
3import { EnvironmentId } from "@v12/contracts";
4import { describe, expect, it } from "@effect/vitest";
5import * as Option from "effect/Option";
6
7import { projectWorkspaceEnvironment, projectWorkspaceState } from "./workspaceModel";
8import type { EnvironmentPresentation } from "./environments";
9
10const ENVIRONMENT_ID = EnvironmentId.make("environment-1");
11
12function environment(
13 phase: EnvironmentPresentation["connection"]["phase"],
14): EnvironmentPresentation {
15 const connectionId = `bearer:${ENVIRONMENT_ID}`;
16 return {
17 environmentId: ENVIRONMENT_ID,
18 label: "Julius's MacBook Pro",
19 displayUrl: "https://environment.example.test",
20 relayManaged: false,
21 entry: {
22 target: new BearerConnectionTarget({
23 environmentId: ENVIRONMENT_ID,
24 label: "Julius's MacBook Pro",
25 connectionId,
26 }),
27 profile: Option.some(
28 new BearerConnectionProfile({
29 connectionId,
30 environmentId: ENVIRONMENT_ID,
31 label: "Julius's MacBook Pro",
32 httpBaseUrl: "https://environment.example.test",
33 wsBaseUrl: "wss://environment.example.test",
34 }),
35 ),
36 },
37 connection: {
38 phase,
39 error: phase === "error" ? "Connection failed." : null,
40 traceId: phase === "error" ? "trace-1" : null,
41 },
42 serverConfig: null,
43 };
44}
45
46const EMPTY_SHELL_SUMMARY: EnvironmentShellSummary = {
47 hasSnapshot: false,
48 hasSynchronizingShell: false,
49 hasCachedShell: false,
50 hasLiveShell: false,
51 firstError: null,
52 latestSnapshotUpdatedAt: null,
53};
54
55const CACHED_SHELL_SUMMARY: EnvironmentShellSummary = {
56 ...EMPTY_SHELL_SUMMARY,
57 hasSnapshot: true,
58 hasSynchronizingShell: true,
59 hasCachedShell: true,
60 latestSnapshotUpdatedAt: "2026-06-07T00:00:00.000Z",
61};
62
63describe("mobile workspace projection", () => {
64 it("preserves explicit offline state without presenting it as a connection error", () => {
65 const projected = projectWorkspaceEnvironment(environment("offline"));
66
67 expect(projected.connectionState).toBe("offline");
68 expect(projected.connectionError).toBeNull();
69 });
70
71 it("reports offline before stale connected presentations", () => {
72 const environments = [projectWorkspaceEnvironment(environment("connected"))];
73 const state = projectWorkspaceState({
74 isReady: true,
75 networkStatus: "offline",
76 environments,
77 shellSummary: EMPTY_SHELL_SUMMARY,
78 });
79
80 expect(state.connectionState).toBe("offline");
81 expect(state.networkStatus).toBe("offline");
82 expect(state.hasReadyEnvironment).toBe(false);
83 });
84
85 it("projects reconnecting environments dynamically from active phases", () => {
86 const environments = [
87 projectWorkspaceEnvironment(environment("reconnecting")),
88 projectWorkspaceEnvironment({
89 ...environment("connected"),
90 environmentId: EnvironmentId.make("environment-2"),
91 }),
92 ];
93 const state = projectWorkspaceState({
94 isReady: true,
95 networkStatus: "online",
96 environments,
97 shellSummary: EMPTY_SHELL_SUMMARY,
98 });
99
100 expect(state.connectingEnvironments).toHaveLength(1);
101 expect(state.connectingEnvironments[0]?.connectionState).toBe("reconnecting");
102 expect(state.hasConnectingEnvironment).toBe(true);
103 expect(state.hasReadyEnvironment).toBe(true);
104 });
105
106 it("keeps retained snapshots visible while reconnecting without claiming readiness", () => {
107 const environments = [projectWorkspaceEnvironment(environment("reconnecting"))];
108 const state = projectWorkspaceState({
109 isReady: true,
110 networkStatus: "online",
111 environments,
112 shellSummary: CACHED_SHELL_SUMMARY,
113 });
114
115 expect(state.hasLoadedShellSnapshot).toBe(true);
116 expect(state.hasPendingShellSnapshot).toBe(true);
117 expect(state.hasReadyEnvironment).toBe(false);
118 expect(state.connectionState).toBe("reconnecting");
119 });
120});