Open History to see the last commit
1import type { EnvironmentId } from "@t3tools/contracts";
2import { AtomRegistry } from "effect/reactivity";
3import { describe, expect, it } from "vite-plus/test";
4
5import { createScratchProjectActions } from "./useScratchProject";
6
7const local = "local" as EnvironmentId;
8const remote = "remote" as EnvironmentId;
9const other = "other" as EnvironmentId;
10
11function scratchEnvironment(environmentId: EnvironmentId, scratchWorkspaceRoot: string | null) {
12 return {
13 environmentId,
14 connection: { phase: "connected" },
15 serverConfig: { scratchWorkspaceRoot },
16 } as never;
17}
18
19function actions(
20 primary: EnvironmentId | null,
21 localRoot: string | null,
22 remoteRoot: string | null = "/remote/scratch",
23) {
24 const environments = [
25 scratchEnvironment(local, localRoot),
26 scratchEnvironment(remote, remoteRoot),
27 scratchEnvironment(other, "/other/scratch"),
28 ];
29 return createScratchProjectActions({
30 environments: () => environments,
31 primaryEnvironmentId: () => primary,
32 registry: AtomRegistry.make(),
33 handleNewThread: async () => null,
34 });
35}
36
37describe("scratchEnvironmentId", () => {
38 it("prefers the primary environment over the one on screen", () => {
39 expect(actions(local, "/local/scratch").scratchEnvironmentId(remote)).toBe(local);
40 expect(actions(local, "/local/scratch").scratchEnvironmentId(null)).toBe(local);
41 });
42
43 it("falls back when the primary environment offers no scratch root", () => {
44 expect(actions(local, null).scratchEnvironmentId(remote)).toBe(remote);
45 expect(actions(null, null).scratchEnvironmentId(remote)).toBe(remote);
46 expect(actions(null, null, null).scratchEnvironmentId(remote)).toBe(other);
47 expect(actions(local, null).scratchEnvironmentId(null)).toBeNull();
48 });
49});