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

terminalLaunchContext.test.ts

130 lines3.9 KB

1import { describe, expect, it } from "vite-plus/test";
2import { EnvironmentId, ThreadId } from "@t3tools/contracts";
3​
4import {
5 peekPendingTerminalLaunch,
6 resolvePreferredThreadWorktreePath,
7 resolveTerminalOpenLocation,
8 stagePendingTerminalLaunch,
9 takePendingTerminalLaunch,
10} from "./terminalLaunchContext";
11​
12describe("resolvePreferredThreadWorktreePath", () => {
13 it("prefers thread detail worktree paths over thread shell paths", () => {
14 expect(
15 resolvePreferredThreadWorktreePath({
16 threadShellWorktreePath: "/repo/root",
17 threadDetailWorktreePath: "/repo/worktrees/feature",
18 }),
19 ).toBe("/repo/worktrees/feature");
20 });
21​
22 it("falls back to the thread shell worktree path when detail is unavailable", () => {
23 expect(
24 resolvePreferredThreadWorktreePath({
25 threadShellWorktreePath: "/repo/worktrees/feature",
26 threadDetailWorktreePath: null,
27 }),
28 ).toBe("/repo/worktrees/feature");
29 });
30});
31​
32describe("resolveTerminalOpenLocation", () => {
33 it("uses the thread detail worktree path before the workspace root for a fresh mobile open", () => {
34 expect(
35 resolveTerminalOpenLocation({
36 terminalLocation: null,
37 activeSessionLocation: null,
38 workspaceRoot: "/repo/root",
39 threadShellWorktreePath: null,
40 threadDetailWorktreePath: "/repo/worktrees/feature",
41 }),
42 ).toEqual({
43 cwd: "/repo/worktrees/feature",
44 worktreePath: "/repo/worktrees/feature",
45 });
46 });
47​
48 it("preserves the running terminal snapshot cwd when attaching to an existing session", () => {
49 expect(
50 resolveTerminalOpenLocation({
51 terminalLocation: null,
52 activeSessionLocation: {
53 cwd: "/repo/worktrees/feature",
54 worktreePath: "/repo/worktrees/feature",
55 },
56 workspaceRoot: "/repo/root",
57 threadShellWorktreePath: null,
58 threadDetailWorktreePath: "/repo/worktrees/other",
59 }),
60 ).toEqual({
61 cwd: "/repo/worktrees/feature",
62 worktreePath: "/repo/worktrees/feature",
63 });
64 });
65});
66​
67describe("pending terminal launches", () => {
68 it("stages and consumes launch details for a specific terminal target", () => {
69 const target = {
70 environmentId: EnvironmentId.make("env-1"),
71 threadId: ThreadId.make("thread-1"),
72 terminalId: "term-2",
73 };
74​
75 stagePendingTerminalLaunch({
76 target,
77 launch: {
78 cwd: "/repo/worktrees/feature",
79 worktreePath: "/repo/worktrees/feature",
80 env: { FOO: "bar" },
81 initialInput: "pnpm dev\r",
82 },
83 });
84​
85 expect(peekPendingTerminalLaunch(target)).toEqual({
86 cwd: "/repo/worktrees/feature",
87 worktreePath: "/repo/worktrees/feature",
88 env: { FOO: "bar" },
89 initialInput: "pnpm dev\r",
90 });
91 expect(takePendingTerminalLaunch(target)).toEqual({
92 cwd: "/repo/worktrees/feature",
93 worktreePath: "/repo/worktrees/feature",
94 env: { FOO: "bar" },
95 initialInput: "pnpm dev\r",
96 });
97 expect(peekPendingTerminalLaunch(target)).toBeNull();
98 });
99​
100 it("keeps pending launches isolated per terminal target", () => {
101 const primaryTarget = {
102 environmentId: EnvironmentId.make("env-1"),
103 threadId: ThreadId.make("thread-1"),
104 terminalId: "term-2",
105 };
106 const otherTarget = {
107 environmentId: EnvironmentId.make("env-1"),
108 threadId: ThreadId.make("thread-1"),
109 terminalId: "term-3",
110 };
111​
112 stagePendingTerminalLaunch({
113 target: primaryTarget,
114 launch: {
115 cwd: "/repo/root",
116 worktreePath: null,
117 initialInput: "pnpm i\r",
118 },
119 });
120​
121 expect(peekPendingTerminalLaunch(otherTarget)).toBeNull();
122 expect(takePendingTerminalLaunch(otherTarget)).toBeNull();
123 expect(takePendingTerminalLaunch(primaryTarget)).toEqual({
124 cwd: "/repo/root",
125 worktreePath: null,
126 env: undefined,
127 initialInput: "pnpm i\r",
128 });
129 });
130});