remoteProjectIdentityPreparation.test.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { expect, it, vi } from "vitest";
  2. import type { IProjectService } from "#src/project/contract.js";
  3. import { bindRemoteProjectIdentities } from "#src/project/index.js";
  4. it("prepares empty remote project roots before publishing the tree, deduplicating task directories", async () => {
  5. const tree = {
  6. projects: [
  7. { roots: [{ rootPath: "/empty" }, { rootPath: "/shared" }] },
  8. { roots: [{ rootPath: "/shared" }] },
  9. ],
  10. tasks: [
  11. { taskId: "one", workspacePath: "/shared" },
  12. { taskId: "two", workspacePath: "/history" },
  13. ],
  14. };
  15. const resolve = vi.fn(async (path: string) => `stable:${path}`);
  16. const service = bindRemoteProjectIdentities(
  17. { readTree: async () => tree } as unknown as IProjectService,
  18. resolve,
  19. );
  20. const result = await service.readTree();
  21. expect(new Set(resolve.mock.calls.map(([path]) => path))).toEqual(
  22. new Set(["/empty", "/shared", "/history"]),
  23. );
  24. expect(resolve).toHaveBeenCalledTimes(3);
  25. expect(result.projects).toBe(tree.projects);
  26. expect(result.tasks.map((task) => task.workspaceIdentity)).toEqual([
  27. "stable:/shared",
  28. "stable:/history",
  29. ]);
  30. });
  31. it("does not publish an empty remote project when identity preparation fails", async () => {
  32. const service = bindRemoteProjectIdentities(
  33. {
  34. readTree: async () => ({ projects: [{ roots: [{ rootPath: "/empty" }] }], tasks: [] }),
  35. } as unknown as IProjectService,
  36. async () => {
  37. throw new Error("identity preparation failed");
  38. },
  39. );
  40. await expect(service.readTree()).rejects.toThrow("identity preparation failed");
  41. });