The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | import { EnvironmentId, ThreadId } from "@t3tools/contracts"; |
| 3 | |
| 4 | import { |
| 5 | resolveTerminalOpenLocation, |
| 6 | stagePendingTerminalLaunch, |
| 7 | takePendingTerminalLaunch, |
| 8 | } from "./terminalLaunchContext"; |
| 9 | |
| 10 | describe("resolveTerminalOpenLocation", () => { |
| 11 | it("preserves the running terminal snapshot cwd when attaching to an existing session", () => { |
| 12 | expect( |
| 13 | resolveTerminalOpenLocation({ |
| 14 | terminalLocation: null, |
| 15 | activeSessionLocation: { |
| 16 | cwd: "/repo/worktrees/feature", |
| 17 | worktreePath: "/repo/worktrees/feature", |
| 18 | }, |
| 19 | workspaceRoot: "/repo/root", |
| 20 | threadShellWorktreePath: null, |
| 21 | threadDetailWorktreePath: "/repo/worktrees/other", |
| 22 | }), |
| 23 | ).toEqual({ |
| 24 | cwd: "/repo/worktrees/feature", |
| 25 | worktreePath: "/repo/worktrees/feature", |
| 26 | }); |
| 27 | }); |
| 28 | |
| 29 | it("preserves checkout cwd and identity from the selected terminal or active session", () => { |
| 30 | const checkout = { cwd: "/repo/root/packages/app", worktreePath: null }; |
| 31 | const threadLocation = { |
| 32 | workspaceRoot: "/repo/root", |
| 33 | threadShellWorktreePath: "/repo/worktrees/feature", |
| 34 | threadDetailWorktreePath: "/repo/worktrees/feature", |
| 35 | }; |
| 36 | |
| 37 | expect( |
| 38 | resolveTerminalOpenLocation({ |
| 39 | ...threadLocation, |
| 40 | terminalLocation: checkout, |
| 41 | activeSessionLocation: { |
| 42 | cwd: "/repo/worktrees/other", |
| 43 | worktreePath: "/repo/worktrees/other", |
| 44 | }, |
| 45 | }), |
| 46 | ).toEqual(checkout); |
| 47 | |
| 48 | expect( |
| 49 | resolveTerminalOpenLocation({ |
| 50 | ...threadLocation, |
| 51 | terminalLocation: null, |
| 52 | activeSessionLocation: checkout, |
| 53 | }), |
| 54 | ).toEqual(checkout); |
| 55 | }); |
| 56 | }); |
| 57 | |
| 58 | describe("pending terminal launches", () => { |
| 59 | it("stages and consumes launch details for a specific terminal target", () => { |
| 60 | const target = { |
| 61 | environmentId: EnvironmentId.make("env-1"), |
| 62 | threadId: ThreadId.make("thread-1"), |
| 63 | terminalId: "term-2", |
| 64 | }; |
| 65 | |
| 66 | stagePendingTerminalLaunch({ |
| 67 | target, |
| 68 | launch: { |
| 69 | cwd: "/repo/worktrees/feature", |
| 70 | worktreePath: "/repo/worktrees/feature", |
| 71 | env: { FOO: "bar" }, |
| 72 | initialInput: "pnpm dev\r", |
| 73 | }, |
| 74 | }); |
| 75 | |
| 76 | expect(takePendingTerminalLaunch(target)).toEqual({ |
| 77 | cwd: "/repo/worktrees/feature", |
| 78 | worktreePath: "/repo/worktrees/feature", |
| 79 | env: { FOO: "bar" }, |
| 80 | initialInput: "pnpm dev\r", |
| 81 | }); |
| 82 | expect(takePendingTerminalLaunch(target)).toBeNull(); |
| 83 | }); |
| 84 | }); |