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

new-task-context-presentation.test.ts

90 lines2.9 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import {
4 resolveNewTaskBranchWorktreePath,
5 resolveNewTaskLocalWorkspaceSelection,
6 resolveNewTaskWorkspaceSelection,
7} from "./new-task-context-presentation";
8​
9describe("resolveNewTaskWorkspaceSelection", () => {
10 const fallback = { mode: "worktree", branch: null, worktreePath: null } as const;
11​
12 it("falls back to the current checkout when a non-git project defaults to worktree", () => {
13 expect(
14 resolveNewTaskWorkspaceSelection({ selection: undefined, fallback, isGitRepo: false }),
15 ).toEqual({ mode: "local", branch: null, worktreePath: null });
16 });
17​
18 it.each(["local", "worktree"] as const)(
19 "clears stale %s selections for non-git projects",
20 (mode) => {
21 expect(
22 resolveNewTaskWorkspaceSelection({
23 selection: {
24 mode,
25 branch: "main",
26 worktreePath: "/old-worktree",
27 startFromOrigin: true,
28 pullRequestReference: "https://github.com/acme/repo/pull/123",
29 },
30 fallback,
31 isGitRepo: false,
32 }),
33 ).toEqual({ mode: "local", branch: null, worktreePath: null });
34 },
35 );
36​
37 // regression: #21404 use current checkout for non-git projects
38 it("preserves the selection and defaults for git projects", () => {
39 const selection = { mode: "local", branch: "feature", worktreePath: "/worktree" } as const;
40 expect(resolveNewTaskWorkspaceSelection({ selection, fallback, isGitRepo: true })).toBe(
41 selection,
42 );
43 expect(
44 resolveNewTaskWorkspaceSelection({ selection: undefined, fallback, isGitRepo: true }),
45 ).toBe(fallback);
46 });
47});
48​
49describe("resolveNewTaskLocalWorkspaceSelection", () => {
50 it("waits for refs instead of carrying a worktree base into Current checkout", () => {
51 expect(
52 resolveNewTaskLocalWorkspaceSelection({
53 branches: [],
54 projectCwd: "/repo",
55 }),
56 ).toEqual({
57 branch: null,
58 worktreePath: null,
59 awaitsCurrentBranch: true,
60 });
61 });
62​
63 it("carries the worktree path when the current branch lives in another worktree", () => {
64 expect(
65 resolveNewTaskLocalWorkspaceSelection({
66 branches: [
67 { name: "feature/split", current: true, worktreePath: "/repo/.t3/worktrees/split" },
68 { name: "main", current: false, worktreePath: "/repo" },
69 ],
70 projectCwd: "/repo",
71 }),
72 ).toEqual({
73 branch: "feature/split",
74 worktreePath: "/repo/.t3/worktrees/split",
75 awaitsCurrentBranch: false,
76 });
77 });
78});
79​
80describe("resolveNewTaskBranchWorktreePath", () => {
81 it("does not reuse an existing worktree while creating a new one", () => {
82 expect(
83 resolveNewTaskBranchWorktreePath({
84 workspaceMode: "worktree",
85 projectCwd: "/repo",
86 branchWorktreePath: "/repo/.t3/worktrees/feature",
87 }),
88 ).toBeNull();
89 });
90});