sourceServerWorkspaceService.test.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import { describe, expect, it, vi } from "vitest";
  2. import { createSourceServerWorkspaceService } from "#src/source-server-workspace/sourceServerWorkspaceService.js";
  3. describe("createSourceServerWorkspaceService", () => {
  4. it("publishes a resolved canonical mapping before returning it to the caller", async () => {
  5. const order: string[] = [];
  6. const onResolved = vi.fn(() => {
  7. order.push("registered");
  8. });
  9. const service = createSourceServerWorkspaceService(
  10. {
  11. resolveCanonicalWorkspaceKey: vi.fn(async () => ({
  12. canonicalKey: "remote:ssh:host:22:user:/workspace",
  13. mergedKeys: [],
  14. })),
  15. getFailedPathCount: vi.fn(async () => 0),
  16. getAbandonedPathCount: vi.fn(async () => 0),
  17. },
  18. { onResolved },
  19. );
  20. const result = await service.resolveWorkspace({
  21. workspacePath: "/workspace",
  22. legacyRouteHint: "remote:ssh:host:22:user:/workspace",
  23. });
  24. order.push("returned");
  25. expect(onResolved).toHaveBeenCalledWith({
  26. workspacePath: "/workspace",
  27. canonicalWorkspaceKey: "remote:ssh:host:22:user:/workspace",
  28. });
  29. expect(order).toEqual(["registered", "returned"]);
  30. expect(result.canonicalWorkspaceKey).toBe("remote:ssh:host:22:user:/workspace");
  31. });
  32. });