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

worktreeCleanup.test.ts

68 lines2.2 KB

1import { EnvironmentId, ProjectId, ProviderInstanceId, ThreadId } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3​
4import { DEFAULT_INTERACTION_MODE, DEFAULT_RUNTIME_MODE, type Thread } from "./types";
5import { makeThreadFixture } from "./test-fixtures";
6import { getOrphanedWorktreePathForThread } from "./worktreeCleanup";
7​
8const localEnvironmentId = EnvironmentId.make("environment-local");
9​
10function makeThread(overrides: Partial<Thread> = {}): Thread {
11 return makeThreadFixture({
12 id: ThreadId.make("thread-1"),
13 environmentId: localEnvironmentId,
14 projectId: ProjectId.make("project-1"),
15 title: "Thread",
16 modelSelection: {
17 instanceId: ProviderInstanceId.make("codex"),
18 model: "gpt-5.3-codex",
19 },
20 runtimeMode: DEFAULT_RUNTIME_MODE,
21 interactionMode: DEFAULT_INTERACTION_MODE,
22 runtime: null,
23 messages: [],
24 proposedPlans: [],
25 createdAt: "2026-02-13T00:00:00.000Z",
26 updatedAt: "2026-02-13T00:00:00.000Z",
27 archivedAt: null,
28 settledOverride: null,
29 settledAt: null,
30 deletedAt: null,
31 latestRun: null,
32 branch: null,
33 worktreePath: null,
34 ...overrides,
35 });
37​
38describe("getOrphanedWorktreePathForThread", () => {
39 it("returns null when another thread links to the same worktree", () => {
40 const threads = [
41 makeThread({
42 id: ThreadId.make("thread-1"),
43 worktreePath: "/tmp/repo/worktrees/feature-a",
44 }),
45 makeThread({
46 id: ThreadId.make("thread-2"),
47 worktreePath: "/tmp/repo/worktrees/feature-a",
48 }),
49 ];
50 const result = getOrphanedWorktreePathForThread(threads, ThreadId.make("thread-1"));
51 expect(result).toBeNull();
52 });
53​
54 it("ignores threads linked to different worktrees", () => {
55 const threads = [
56 makeThread({
57 id: ThreadId.make("thread-1"),
58 worktreePath: "/tmp/repo/worktrees/feature-a",
59 }),
60 makeThread({
61 id: ThreadId.make("thread-2"),
62 worktreePath: "/tmp/repo/worktrees/feature-b",
63 }),
64 ];
65 const result = getOrphanedWorktreePathForThread(threads, ThreadId.make("thread-1"));
66 expect(result).toBe("/tmp/repo/worktrees/feature-a");
67 });
68});