useRootPlatformEffects.test.ts 4.5 KB

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