automationProjectOptions.test.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import { describe, expect, it } from "vitest";
  2. import type { WorkspaceTabState } from "@/store/tabStore.js";
  3. import {
  4. isRemoteAutomationWorkspace,
  5. resolveAutomationProjectOptions,
  6. } from "@/hooks/useAutomationProjectOptions.js";
  7. function workspaceTab(
  8. overrides: Partial<WorkspaceTabState> & Pick<WorkspaceTabState, "id" | "workspacePath">,
  9. ): WorkspaceTabState {
  10. return {
  11. kind: "workspace",
  12. label: "",
  13. ...overrides,
  14. };
  15. }
  16. describe("automation project boundaries", () => {
  17. it("只保留可用项目并使用路径 basename 作为缺省名称", () => {
  18. expect(
  19. resolveAutomationProjectOptions([
  20. workspaceTab({ id: "local-a", workspacePath: "/repo/local-a", label: "Local A" }),
  21. workspaceTab({
  22. id: "missing",
  23. workspacePath: "/repo/missing",
  24. availability: "unavailable-local-directory",
  25. }),
  26. ]),
  27. ).toEqual([{ workspacePath: "/repo/local-a", label: "Local A" }]);
  28. expect(
  29. resolveAutomationProjectOptions([
  30. workspaceTab({ id: "windows", workspacePath: "C:\\repo\\local-b" }),
  31. ]),
  32. ).toEqual([{ workspacePath: "C:\\repo\\local-b", label: "local-b" }]);
  33. });
  34. it("定时任务把多个 conversation backing workspace 合并为一个逻辑无项目选项", () => {
  35. const tabs = [
  36. workspaceTab({
  37. id: "conversation-default",
  38. workspacePath: "/Users/test/.zcode/workspace/default",
  39. workspacePurpose: "conversation",
  40. }),
  41. workspaceTab({
  42. id: "conversation-test-default",
  43. workspacePath: "/private/tmp/test/.zcode/workspace/default",
  44. workspacePurpose: "conversation",
  45. }),
  46. workspaceTab({
  47. id: "project",
  48. workspacePath: "/repo/project",
  49. workspacePurpose: "project",
  50. }),
  51. ];
  52. expect(resolveAutomationProjectOptions(tabs)).toEqual([
  53. { workspacePath: "/repo/project", label: "project" },
  54. ]);
  55. expect(
  56. resolveAutomationProjectOptions(tabs, {
  57. includeConversationWorkspace: true,
  58. }),
  59. ).toEqual([
  60. {
  61. workspacePath: "/Users/test/.zcode/workspace/default",
  62. label: "default",
  63. workspacePurpose: "conversation",
  64. },
  65. { workspacePath: "/repo/project", label: "project" },
  66. ]);
  67. });
  68. it("识别所有远端 workspace 身份信号", () => {
  69. expect(
  70. isRemoteAutomationWorkspace(
  71. workspaceTab({
  72. id: "ssh",
  73. workspacePath: "/repo",
  74. remoteSessionId: "remote-session",
  75. }),
  76. ),
  77. ).toBe(true);
  78. expect(
  79. isRemoteAutomationWorkspace(
  80. workspaceTab({
  81. id: "identity",
  82. workspacePath: "/repo",
  83. workspaceIdentity: "ssh://host/repo",
  84. }),
  85. ),
  86. ).toBe(true);
  87. expect(
  88. isRemoteAutomationWorkspace(
  89. workspaceTab({ id: "local", workspacePath: "/repo/local" }),
  90. ),
  91. ).toBe(false);
  92. });
  93. });