Open History to see the last commit
1import type { EnvironmentShellSummary } from "@t3tools/client-runtime/state/shell";
2import {
3 BearerConnectionProfile,
4 BearerConnectionTarget,
5} from "@t3tools/client-runtime/connection";
6import { EnvironmentId } from "@t3tools/contracts";
7import { describe, expect, it } from "@effect/vitest";
8import * as Option from "effect/Option";
9
10import { projectWorkspaceState } from "./workspaceModel";
11import { projectEnvironmentConnectionSummary as projectWorkspaceEnvironment } from "@t3tools/client-runtime/state/presentation";
12import type { EnvironmentPresentation } from "./environments";
13
14const ENVIRONMENT_ID = EnvironmentId.make("environment-1");
15
16function environment(
17 phase: EnvironmentPresentation["connection"]["phase"],
18): EnvironmentPresentation {
19 const connectionId = `bearer:${ENVIRONMENT_ID}`;
20 return {
21 environmentId: ENVIRONMENT_ID,
22 label: "Julius's MacBook Pro",
23 displayUrl: "https://environment.example.test",
24 relayManaged: false,
25 entry: {
26 target: new BearerConnectionTarget({
27 environmentId: ENVIRONMENT_ID,
28 label: "Julius's MacBook Pro",
29 connectionId,
30 }),
31 profile: Option.some(
32 new BearerConnectionProfile({
33 connectionId,
34 environmentId: ENVIRONMENT_ID,
35 label: "Julius's MacBook Pro",
36 httpBaseUrl: "https://environment.example.test",
37 wsBaseUrl: "wss://environment.example.test",
38 }),
39 ),
40 enabled: true,
41 },
42 connection: {
43 phase,
44 error: phase === "error" ? "Connection failed." : null,
45 traceId: phase === "error" ? "trace-1" : null,
46 },
47 serverConfig: null,
48 };
49}
50
51const EMPTY_SHELL_SUMMARY: EnvironmentShellSummary = {
52 hasSnapshot: false,
53 hasSynchronizingShell: false,
54 firstError: null,
55};
56
57const CACHED_SHELL_SUMMARY: EnvironmentShellSummary = {
58 ...EMPTY_SHELL_SUMMARY,
59 hasSnapshot: true,
60 hasSynchronizingShell: true,
61};
62
63describe("mobile workspace projection", () => {
64 it("reports offline before stale connected presentations", () => {
65 const environments = [projectWorkspaceEnvironment(ENVIRONMENT_ID, environment("connected"))];
66 const state = projectWorkspaceState({
67 isReady: true,
68 networkStatus: "offline",
69 environments,
70 shellSummary: EMPTY_SHELL_SUMMARY,
71 hasSyncingConnectedEnvironment: false,
72 });
73
74 expect(state.connectionState).toBe("offline");
75 expect(state.networkStatus).toBe("offline");
76 expect(state.hasReadyEnvironment).toBe(false);
77 });
78
79 it("keeps retained snapshots visible while reconnecting without claiming readiness", () => {
80 const environments = [projectWorkspaceEnvironment(ENVIRONMENT_ID, environment("reconnecting"))];
81 const state = projectWorkspaceState({
82 isReady: true,
83 networkStatus: "online",
84 environments,
85 shellSummary: CACHED_SHELL_SUMMARY,
86 hasSyncingConnectedEnvironment: false,
87 });
88
89 expect(state.hasLoadedShellSnapshot).toBe(true);
90 expect(state.hasPendingShellSnapshot).toBe(true);
91 expect(state.hasSyncingConnectedEnvironment).toBe(false);
92 expect(state.hasReadyEnvironment).toBe(false);
93 expect(state.connectionState).toBe("reconnecting");
94 });
95});