automationWorkspaceOptions.test.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { describe, expect, it } from "vitest";
  2. import {
  3. findAutomationWorkspaceOptionByKey,
  4. reconcileAutomationWorkspaceSelectionKey,
  5. resolveAutomationWorkspaceSelectionKey,
  6. } from "@/settings/automationWorkspaceOptions.js";
  7. describe("automation project selection", () => {
  8. it("uses project identity for overlapping cwd, without changing workspace identity", () => {
  9. const options = [
  10. { projectId: "a", hostId: "local", workspacePath: "/same", label: "A" },
  11. { projectId: "b", hostId: "local", workspacePath: "/same", label: "B" },
  12. ];
  13. const key = resolveAutomationWorkspaceSelectionKey(options[1]!);
  14. expect(key).not.toBe(resolveAutomationWorkspaceSelectionKey(options[0]!));
  15. expect(findAutomationWorkspaceOptionByKey(options, key)).toBe(options[1]);
  16. expect(options[1]!.workspacePath).toBe("/same");
  17. expect(reconcileAutomationWorkspaceSelectionKey(options, key)).toBe(key);
  18. });
  19. it("无有效项目时选择收敛为 null,不回退到默认或 conversation workspace", () => {
  20. expect(
  21. reconcileAutomationWorkspaceSelectionKey([], "/app/default", {
  22. workspacePath: "/app/default",
  23. }),
  24. ).toBeNull();
  25. });
  26. it("候选恢复后优先选择有效默认项目,并保留仍有效的当前项目", () => {
  27. const options = [
  28. { workspacePath: "/repo/first", label: "first" },
  29. {
  30. workspacePath: "/repo",
  31. workspaceIdentity: "remote:ssh:b:/repo",
  32. label: "remote-b",
  33. },
  34. ];
  35. expect(
  36. reconcileAutomationWorkspaceSelectionKey(options, null, {
  37. workspacePath: "/repo",
  38. workspaceIdentity: "remote:ssh:b:/repo",
  39. }),
  40. ).toBe("remote:ssh:b:/repo");
  41. expect(
  42. reconcileAutomationWorkspaceSelectionKey(options, "/repo/first", {
  43. workspacePath: "/repo",
  44. workspaceIdentity: "remote:ssh:b:/repo",
  45. }),
  46. ).toBe("/repo/first");
  47. });
  48. });