useRootPlatformEffects.test.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. import { describe, expect, it } from "vitest";
  2. import {
  3. buildConnectedRemoteWorkspaceSessionTargets,
  4. buildWebRemoteControlWorkspaceTargets,
  5. shouldPublishCompleteWorkspaceSnapshot,
  6. } from "@/root/rootPlatformWorkspaceSync.js";
  7. import type { WindowTabState } from "@/store/tabStore.js";
  8. function createWorkspaceTab(
  9. overrides: Partial<Extract<WindowTabState, { kind: "workspace" }>> = {},
  10. ): Extract<WindowTabState, { kind: "workspace" }> {
  11. return {
  12. id: overrides.id ?? "tab-1",
  13. kind: "workspace",
  14. label: overrides.label ?? "demo",
  15. workspacePath: overrides.workspacePath ?? "/workspace/demo",
  16. workspaceIdentity: overrides.workspaceIdentity,
  17. workspacePurpose: overrides.workspacePurpose,
  18. remoteSessionId: overrides.remoteSessionId,
  19. remoteTarget: overrides.remoteTarget,
  20. };
  21. }
  22. describe("buildWebRemoteControlWorkspaceTargets", () => {
  23. it("preserves conversation purpose for mobile task navigation", () => {
  24. expect(
  25. buildWebRemoteControlWorkspaceTargets({
  26. tabs: [
  27. createWorkspaceTab({
  28. id: "conversation",
  29. label: "default",
  30. workspacePath: "/Users/demo/.zcode/workspace/default",
  31. workspacePurpose: "conversation",
  32. }),
  33. ],
  34. }),
  35. ).toEqual([
  36. {
  37. workspacePath: "/Users/demo/.zcode/workspace/default",
  38. label: "default",
  39. kind: "local",
  40. workspacePurpose: "conversation",
  41. },
  42. ]);
  43. });
  44. it("syncs disconnected errors and reconnecting state by workspace identity", () => {
  45. expect(
  46. buildWebRemoteControlWorkspaceTargets({
  47. tabs: [
  48. createWorkspaceTab({
  49. id: "remote-1",
  50. label: "Remote App",
  51. workspacePath: "/workspace/remote",
  52. workspaceIdentity: "remote:ssh:dev:/workspace/remote",
  53. remoteTarget: { kind: "ssh", host: "dev", username: "root" },
  54. }),
  55. createWorkspaceTab({
  56. id: "remote-2",
  57. label: "Reconnecting App",
  58. workspacePath: "/workspace/reconnecting",
  59. workspaceIdentity: "remote:ssh:dev:/workspace/reconnecting",
  60. remoteTarget: { kind: "ssh", host: "dev", username: "root" },
  61. }),
  62. createWorkspaceTab({
  63. id: "local-1",
  64. label: "Local App",
  65. workspacePath: "/workspace/local",
  66. }),
  67. ],
  68. reconnectingRemoteWorkspaceKeys: [
  69. "remote:ssh:dev:/workspace/reconnecting",
  70. ],
  71. remoteWorkspaceErrorByWorkspaceKey: {
  72. "remote:ssh:dev:/workspace/remote": "ssh closed",
  73. },
  74. }),
  75. ).toEqual([
  76. {
  77. workspacePath: "/workspace/remote",
  78. label: "Remote App",
  79. kind: "remote",
  80. connectionState: "disconnected",
  81. workspaceIdentity: "remote:ssh:dev:/workspace/remote",
  82. lastConnectionError: "ssh closed",
  83. },
  84. {
  85. workspacePath: "/workspace/reconnecting",
  86. label: "Reconnecting App",
  87. kind: "remote",
  88. connectionState: "reconnecting",
  89. workspaceIdentity: "remote:ssh:dev:/workspace/reconnecting",
  90. },
  91. {
  92. workspacePath: "/workspace/local",
  93. label: "Local App",
  94. kind: "local",
  95. },
  96. ]);
  97. });
  98. });
  99. describe("buildConnectedRemoteWorkspaceSessionTargets", () => {
  100. it("returns only connected remote tabs with workspace identity", () => {
  101. expect(
  102. buildConnectedRemoteWorkspaceSessionTargets({
  103. tabs: [
  104. createWorkspaceTab({
  105. id: "remote-connected",
  106. label: "Remote Connected",
  107. workspacePath: "/root",
  108. workspaceIdentity: "remote:docker:zcode-ssh-container:/root",
  109. remoteSessionId: "remote-session-1",
  110. remoteTarget: { kind: "docker", container: "zcode-ssh-container" },
  111. }),
  112. createWorkspaceTab({
  113. id: "remote-placeholder",
  114. label: "Remote Placeholder",
  115. workspacePath: "/workspace/disconnected",
  116. workspaceIdentity: "remote:ssh:dev:/workspace/disconnected",
  117. remoteTarget: { kind: "ssh", host: "dev", username: "root" },
  118. }),
  119. createWorkspaceTab({
  120. id: "local",
  121. label: "Local",
  122. workspacePath: "/workspace/local",
  123. }),
  124. ],
  125. }),
  126. ).toEqual([
  127. {
  128. workspacePath: "/root",
  129. label: "Remote Connected",
  130. kind: "remote",
  131. connectionState: "connected",
  132. workspaceIdentity: "remote:docker:zcode-ssh-container:/root",
  133. remoteSessionId: "remote-session-1",
  134. },
  135. ]);
  136. });
  137. });
  138. describe("shouldPublishCompleteWorkspaceSnapshot", () => {
  139. it("does not publish the renderer-only active-first projection", () => {
  140. expect(shouldPublishCompleteWorkspaceSnapshot(false)).toBe(false);
  141. expect(shouldPublishCompleteWorkspaceSnapshot(true)).toBe(true);
  142. });
  143. });