rootWorkspaceShellTarget.test.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import { describe, expect, it } from "vitest";
  2. import { resolveRootWorkspaceShellTarget } from "@/root/rootWorkspaceShellTarget.js";
  3. const remoteWorkspaceIdentity = "remote:ssh:124.223.19.106:22:ubuntu:/home/ubuntu/workspace";
  4. const remoteWorkspaceTab = {
  5. workspacePath: "/home/ubuntu/workspace",
  6. workspaceIdentity: remoteWorkspaceIdentity,
  7. remoteSessionId: "remote-session-1",
  8. };
  9. describe("resolveRootWorkspaceShellTarget", () => {
  10. it("uses the active workspace tab verbatim", () => {
  11. const target = resolveRootWorkspaceShellTarget({
  12. activeWorkspaceTab: remoteWorkspaceTab,
  13. activeWorkspacePath: remoteWorkspaceTab.workspacePath,
  14. activeWorkspaceIdentity: remoteWorkspaceIdentity,
  15. workspaceTabs: [remoteWorkspaceTab],
  16. });
  17. expect(target).toEqual({
  18. workspaceShellPath: "/home/ubuntu/workspace",
  19. workspaceIdentity: remoteWorkspaceIdentity,
  20. workspaceRemoteSessionId: "remote-session-1",
  21. });
  22. });
  23. it("keeps the covered remote workspace tab's identity and remote session while settings is active", () => {
  24. const target = resolveRootWorkspaceShellTarget({
  25. activeWorkspaceTab: null,
  26. activeWorkspacePath: remoteWorkspaceTab.workspacePath,
  27. activeWorkspaceIdentity: remoteWorkspaceIdentity,
  28. workspaceTabs: [{ workspacePath: "D:\\zcode\\other-local" }, remoteWorkspaceTab],
  29. });
  30. // Settings 覆盖 workspace 时,外壳目标必须与被覆盖的 workspace tab 完全一致;
  31. // 丢掉 remoteSessionId 会让通知 hook 以 __base__ 键再建一条 sessions-index 订阅并顶掉侧栏订阅。
  32. expect(target).toEqual({
  33. workspaceShellPath: "/home/ubuntu/workspace",
  34. workspaceIdentity: remoteWorkspaceIdentity,
  35. workspaceRemoteSessionId: "remote-session-1",
  36. });
  37. });
  38. it("matches the covered tab by workspace identity, not by path alone", () => {
  39. const target = resolveRootWorkspaceShellTarget({
  40. activeWorkspaceTab: null,
  41. activeWorkspacePath: "/home/ubuntu/workspace",
  42. activeWorkspaceIdentity: remoteWorkspaceIdentity,
  43. workspaceTabs: [
  44. {
  45. workspacePath: "/home/ubuntu/workspace",
  46. workspaceIdentity: "remote:wsl:default:ubuntu:/home/ubuntu/workspace",
  47. remoteSessionId: "remote-session-wsl",
  48. },
  49. remoteWorkspaceTab,
  50. ],
  51. });
  52. expect(target.workspaceRemoteSessionId).toBe("remote-session-1");
  53. });
  54. it("stays without a remote session when the covered remote tab is not connected", () => {
  55. const target = resolveRootWorkspaceShellTarget({
  56. activeWorkspaceTab: null,
  57. activeWorkspacePath: remoteWorkspaceTab.workspacePath,
  58. activeWorkspaceIdentity: remoteWorkspaceIdentity,
  59. workspaceTabs: [
  60. {
  61. workspacePath: remoteWorkspaceTab.workspacePath,
  62. workspaceIdentity: remoteWorkspaceIdentity,
  63. },
  64. ],
  65. });
  66. expect(target).toEqual({
  67. workspaceShellPath: "/home/ubuntu/workspace",
  68. workspaceIdentity: remoteWorkspaceIdentity,
  69. workspaceRemoteSessionId: undefined,
  70. });
  71. });
  72. it("stays without a remote session when the covered workspace tab is already closed", () => {
  73. const target = resolveRootWorkspaceShellTarget({
  74. activeWorkspaceTab: null,
  75. activeWorkspacePath: remoteWorkspaceTab.workspacePath,
  76. activeWorkspaceIdentity: remoteWorkspaceIdentity,
  77. workspaceTabs: [],
  78. });
  79. expect(target).toEqual({
  80. workspaceShellPath: "/home/ubuntu/workspace",
  81. workspaceIdentity: remoteWorkspaceIdentity,
  82. workspaceRemoteSessionId: undefined,
  83. });
  84. });
  85. it("keeps a local workspace local while settings is active", () => {
  86. const target = resolveRootWorkspaceShellTarget({
  87. activeWorkspaceTab: null,
  88. activeWorkspacePath: "D:\\zcode\\workspace",
  89. activeWorkspaceIdentity: null,
  90. workspaceTabs: [{ workspacePath: "D:\\zcode\\workspace" }, remoteWorkspaceTab],
  91. });
  92. expect(target).toEqual({
  93. workspaceShellPath: "D:\\zcode\\workspace",
  94. workspaceIdentity: undefined,
  95. workspaceRemoteSessionId: undefined,
  96. });
  97. });
  98. });