Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

projectClones.test.ts

64 lines2.5 KB

1import { EnvironmentId, ProjectId, type ProjectCloneSnapshot } from "@t3tools/contracts";
2import { AsyncResult, Atom, AtomRegistry } from "effect/reactivity";
3import { expect, it, vi } from "vite-plus/test";
4​
5vi.mock("./atom-registry", async () => {
6 const { AtomRegistry } = await import("effect/reactivity");
7 return { appAtomRegistry: AtomRegistry.make() };
8});
9​
10vi.mock("./sourceControl", async () => {
11 const { AsyncResult, Atom } = await import("effect/reactivity");
12 const clones = Atom.make(AsyncResult.success<ReadonlyArray<ProjectCloneSnapshot>>([]));
13 return { sourceControlEnvironment: { projectClones: () => clones } };
14});
15​
16vi.mock("./server", () => ({ serverEnvironment: {} }));
17​
18import { appAtomRegistry } from "./atom-registry";
19import { waitForHandoffClone } from "./projectClones";
20import { sourceControlEnvironment } from "./sourceControl";
21​
22it("stops waiting when a tracked clone disappears", async () => {
23 const environmentId = EnvironmentId.make("box");
24 const projectId = ProjectId.make("project");
25 const atom = sourceControlEnvironment.projectClones({ environmentId, input: {} });
26 const registry: AtomRegistry.AtomRegistry = appAtomRegistry;
27 const snapshot: ProjectCloneSnapshot = {
28 projectId,
29 remoteUrl: "https://example.com/repo.git",
30 destinationPath: "/checkout",
31 repository: null,
32 phase: "running",
33 stage: "connecting",
34 percent: null,
35 detail: null,
36 error: null,
37 startedAt: "2026-01-01T00:00:00.000Z",
38 endedAt: null,
39 sequence: 1,
40 };
41 const result = waitForHandoffClone(environmentId, projectId);
42 expect(await Promise.race([result, Promise.resolve("pending")])).toBe("pending");
43 registry.set(
44 atom as Atom.Writable<AsyncResult.AsyncResult<ReadonlyArray<ProjectCloneSnapshot>>>,
45 AsyncResult.success([snapshot]),
46 );
47 registry.set(
48 atom as Atom.Writable<AsyncResult.AsyncResult<ReadonlyArray<ProjectCloneSnapshot>>>,
49 AsyncResult.success([]),
50 );
51 expect(await Promise.race([result, Promise.resolve("pending")])).toBeNull();
52});
53​
54it("ends the wait when the first fresh snapshot has already lost the clone", async () => {
55 const environmentId = EnvironmentId.make("box");
56 const projectId = ProjectId.make("missing");
57 const atom = sourceControlEnvironment.projectClones({ environmentId, input: {} });
58 const result = waitForHandoffClone(environmentId, projectId);
59 appAtomRegistry.set(
60 atom as Atom.Writable<AsyncResult.AsyncResult<ReadonlyArray<ProjectCloneSnapshot>>>,
61 AsyncResult.success([]),
62 );
63 expect(await Promise.race([result, Promise.resolve("pending")])).toBeNull();
64});