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

new-task-context-presentation.test.ts

107 lines3.4 KB

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