- Main store: replace useReducer with Zustand; pure state transition functions (syncServerReadModel, markThreadVisited, setError, etc.) called via store methods. Persist via subscribe. - Terminal store: single store keyed by threadId; replace dispatchTerminalAction with direct methods (setTerminalOpen, setTerminalHeight, splitTerminal, newTerminal, setActiveTerminal, closeTerminal, setTerminalActivity). Pure reduceThreadTerminalState used internally. - Update all consumers to call dispatch.method(...) and terminal store methods. Fix store tests to use markThreadUnread pure fn. - Fix Fragment import in store.ts; fix unused get param for lint. Made-with: Cursor
101 lines
3.4 KiB
TypeScript
101 lines
3.4 KiB
TypeScript
import { ProjectId, ThreadId } from "@t3tools/contracts";
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
import type { Thread } from "./types";
|
|
import { formatWorktreePathForDisplay, getOrphanedWorktreePathForThread } from "./worktreeCleanup";
|
|
|
|
function makeThread(overrides: Partial<Thread> = {}): Thread {
|
|
return {
|
|
id: ThreadId.makeUnsafe("thread-1"),
|
|
codexThreadId: null,
|
|
projectId: ProjectId.makeUnsafe("project-1"),
|
|
title: "Thread",
|
|
model: "gpt-5.3-codex",
|
|
session: null,
|
|
messages: [],
|
|
turnDiffSummaries: [],
|
|
activities: [],
|
|
error: null,
|
|
createdAt: "2026-02-13T00:00:00.000Z",
|
|
latestTurn: null,
|
|
branch: null,
|
|
worktreePath: null,
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
describe("getOrphanedWorktreePathForThread", () => {
|
|
it("returns null when the target thread does not exist", () => {
|
|
const result = getOrphanedWorktreePathForThread([], ThreadId.makeUnsafe("missing-thread"));
|
|
expect(result).toBeNull();
|
|
});
|
|
|
|
it("returns null when the target thread has no worktree", () => {
|
|
const threads = [makeThread()];
|
|
const result = getOrphanedWorktreePathForThread(threads, ThreadId.makeUnsafe("thread-1"));
|
|
expect(result).toBeNull();
|
|
});
|
|
|
|
it("returns the path when no other thread links to that worktree", () => {
|
|
const threads = [makeThread({ worktreePath: "/tmp/repo/worktrees/feature-a" })];
|
|
const result = getOrphanedWorktreePathForThread(threads, ThreadId.makeUnsafe("thread-1"));
|
|
expect(result).toBe("/tmp/repo/worktrees/feature-a");
|
|
});
|
|
|
|
it("returns null when another thread links to the same worktree", () => {
|
|
const threads = [
|
|
makeThread({
|
|
id: ThreadId.makeUnsafe("thread-1"),
|
|
worktreePath: "/tmp/repo/worktrees/feature-a",
|
|
}),
|
|
makeThread({
|
|
id: ThreadId.makeUnsafe("thread-2"),
|
|
worktreePath: "/tmp/repo/worktrees/feature-a",
|
|
}),
|
|
];
|
|
const result = getOrphanedWorktreePathForThread(threads, ThreadId.makeUnsafe("thread-1"));
|
|
expect(result).toBeNull();
|
|
});
|
|
|
|
it("ignores threads linked to different worktrees", () => {
|
|
const threads = [
|
|
makeThread({
|
|
id: ThreadId.makeUnsafe("thread-1"),
|
|
worktreePath: "/tmp/repo/worktrees/feature-a",
|
|
}),
|
|
makeThread({
|
|
id: ThreadId.makeUnsafe("thread-2"),
|
|
worktreePath: "/tmp/repo/worktrees/feature-b",
|
|
}),
|
|
];
|
|
const result = getOrphanedWorktreePathForThread(threads, ThreadId.makeUnsafe("thread-1"));
|
|
expect(result).toBe("/tmp/repo/worktrees/feature-a");
|
|
});
|
|
});
|
|
|
|
describe("formatWorktreePathForDisplay", () => {
|
|
it("shows only the last path segment for unix-like paths", () => {
|
|
const result = formatWorktreePathForDisplay(
|
|
"/Users/julius/.t3/worktrees/t3code-mvp/t3code-4e609bb8",
|
|
);
|
|
expect(result).toBe("t3code-4e609bb8");
|
|
});
|
|
|
|
it("normalizes windows separators before selecting the final segment", () => {
|
|
const result = formatWorktreePathForDisplay(
|
|
"C:\\Users\\julius\\.t3\\worktrees\\t3code-mvp\\t3code-4e609bb8",
|
|
);
|
|
expect(result).toBe("t3code-4e609bb8");
|
|
});
|
|
|
|
it("uses the final segment even when outside ~/.t3/worktrees", () => {
|
|
const result = formatWorktreePathForDisplay("/tmp/custom-worktrees/my-worktree");
|
|
expect(result).toBe("my-worktree");
|
|
});
|
|
|
|
it("ignores trailing slashes", () => {
|
|
const result = formatWorktreePathForDisplay("/tmp/custom-worktrees/my-worktree/");
|
|
expect(result).toBe("my-worktree");
|
|
});
|
|
});
|