The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import type { EnvironmentId } from "@t3tools/contracts"; |
| 2 | import { AtomRegistry } from "effect/reactivity"; |
| 3 | import { describe, expect, it } from "vite-plus/test"; |
| 4 | |
| 5 | import { createScratchProjectActions } from "./useScratchProject"; |
| 6 | |
| 7 | const local = "local" as EnvironmentId; |
| 8 | const remote = "remote" as EnvironmentId; |
| 9 | const other = "other" as EnvironmentId; |
| 10 | |
| 11 | function scratchEnvironment(environmentId: EnvironmentId, scratchWorkspaceRoot: string | null) { |
| 12 | return { |
| 13 | environmentId, |
| 14 | connection: { phase: "connected" }, |
| 15 | serverConfig: { scratchWorkspaceRoot }, |
| 16 | } as never; |
| 17 | } |
| 18 | |
| 19 | function 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 | |
| 37 | describe("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 | }); |