workspacePurpose.test.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { describe, expect, it } from "vitest";
  2. import {
  3. getWorkspacePurpose,
  4. partitionWorkspaceTabsByPurpose,
  5. } from "@/lib/workspacePurpose.js";
  6. import type { WorkspaceTabState } from "@/store/tabStore.js";
  7. function tab(
  8. id: string,
  9. workspacePath: string,
  10. workspacePurpose?: "project" | "conversation",
  11. ): WorkspaceTabState {
  12. return {
  13. id,
  14. kind: "workspace",
  15. label: id,
  16. workspacePath,
  17. ...(workspacePurpose ? { workspacePurpose } : {}),
  18. };
  19. }
  20. describe("workspace purpose", () => {
  21. it("defaults legacy workspaces to project", () => {
  22. expect(getWorkspacePurpose({ workspacePath: "/tmp/legacy" })).toBe(
  23. "project",
  24. );
  25. });
  26. it("keeps conversation targets in all task scopes while excluding them from project rows", () => {
  27. const conversation = tab(
  28. "conversation",
  29. "/tmp/.zcode/workspace/default",
  30. "conversation",
  31. );
  32. const project = tab("project", "/tmp/project", "project");
  33. const legacyProject = tab("legacy", "/tmp/legacy");
  34. expect(
  35. partitionWorkspaceTabsByPurpose([conversation, project, legacyProject]),
  36. ).toEqual({
  37. allTaskWorkspaceTabs: [conversation, project, legacyProject],
  38. conversationWorkspaceTabs: [conversation],
  39. projectWorkspaceTabs: [project, legacyProject],
  40. });
  41. });
  42. it("keeps a conversation task scope when there are no project tabs", () => {
  43. const conversation = tab(
  44. "conversation",
  45. "/tmp/.zcode/workspace/default",
  46. "conversation",
  47. );
  48. expect(partitionWorkspaceTabsByPurpose([conversation])).toEqual({
  49. allTaskWorkspaceTabs: [conversation],
  50. conversationWorkspaceTabs: [conversation],
  51. projectWorkspaceTabs: [],
  52. });
  53. });
  54. });