Makes the new sidebar/thread-list testable against existing unupgraded servers by removing every backend dependency of the settled feature: - apps/server, contracts orchestration schemas, and client-runtime command/reducer plumbing revert to main baseline (no thread.settle commands, no settled events/fields, no migration 033) - effectiveSettled() is now archive-based: archivedAt is the explicit settled signal; PR merged/closed and inactivity auto-settle keep working client-side. Blocked work (pending approval/input, live session) still never settles - settle/unsettle actions ride threadEnvironment.archive/unarchive on web and mobile — UI and UX unchanged - Archived threads stay visible as the settled tail: the live shell stream drops archived threads (thread.archived → thread-removed), so both clients merge them back from the archived shell snapshot and refresh it after settle/unsettle/archive actions - Client settings (sidebarV2Enabled, sidebarAutoSettleAfterDays) are kept — they persist client-side only Trade-offs vs the event-sourced model (still on t3code/sidebar-v2-mobile): no activity-driven auto-un-settle for archived threads, and no "keep active" override distinct from unarchiving. Co-Authored-By: Claude Fable 5 <[email protected]>
123 lines
4.2 KiB
TypeScript
123 lines
4.2 KiB
TypeScript
import { EnvironmentId, ProjectId, ProviderInstanceId, ThreadId } from "@t3tools/contracts";
|
|
import { describe, expect, it } from "vite-plus/test";
|
|
|
|
import { DEFAULT_INTERACTION_MODE, DEFAULT_RUNTIME_MODE, type Thread } from "./types";
|
|
import {
|
|
canOfferWorktreeRemoval,
|
|
formatWorktreePathForDisplay,
|
|
getOrphanedWorktreePathForThread,
|
|
} from "./worktreeCleanup";
|
|
|
|
const localEnvironmentId = EnvironmentId.make("environment-local");
|
|
|
|
function makeThread(overrides: Partial<Thread> = {}): Thread {
|
|
return {
|
|
id: ThreadId.make("thread-1"),
|
|
environmentId: localEnvironmentId,
|
|
projectId: ProjectId.make("project-1"),
|
|
title: "Thread",
|
|
modelSelection: {
|
|
instanceId: ProviderInstanceId.make("codex"),
|
|
model: "gpt-5.3-codex",
|
|
},
|
|
runtimeMode: DEFAULT_RUNTIME_MODE,
|
|
interactionMode: DEFAULT_INTERACTION_MODE,
|
|
session: null,
|
|
messages: [],
|
|
checkpoints: [],
|
|
activities: [],
|
|
proposedPlans: [],
|
|
createdAt: "2026-02-13T00:00:00.000Z",
|
|
updatedAt: "2026-02-13T00:00:00.000Z",
|
|
archivedAt: null,
|
|
deletedAt: null,
|
|
latestTurn: null,
|
|
branch: null,
|
|
worktreePath: null,
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
describe("getOrphanedWorktreePathForThread", () => {
|
|
it("returns null when the target thread does not exist", () => {
|
|
const result = getOrphanedWorktreePathForThread([], ThreadId.make("missing-thread"));
|
|
expect(result).toBeNull();
|
|
});
|
|
|
|
it("returns null when the target thread has no worktree", () => {
|
|
const threads = [makeThread()];
|
|
const result = getOrphanedWorktreePathForThread(threads, ThreadId.make("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.make("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.make("thread-1"),
|
|
worktreePath: "/tmp/repo/worktrees/feature-a",
|
|
}),
|
|
makeThread({
|
|
id: ThreadId.make("thread-2"),
|
|
worktreePath: "/tmp/repo/worktrees/feature-a",
|
|
}),
|
|
];
|
|
const result = getOrphanedWorktreePathForThread(threads, ThreadId.make("thread-1"));
|
|
expect(result).toBeNull();
|
|
});
|
|
|
|
it("ignores threads linked to different worktrees", () => {
|
|
const threads = [
|
|
makeThread({
|
|
id: ThreadId.make("thread-1"),
|
|
worktreePath: "/tmp/repo/worktrees/feature-a",
|
|
}),
|
|
makeThread({
|
|
id: ThreadId.make("thread-2"),
|
|
worktreePath: "/tmp/repo/worktrees/feature-b",
|
|
}),
|
|
];
|
|
const result = getOrphanedWorktreePathForThread(threads, ThreadId.make("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");
|
|
});
|
|
});
|
|
|
|
describe("canOfferWorktreeRemoval", () => {
|
|
it("requires a clean worktree with no unpushed commits", () => {
|
|
expect(canOfferWorktreeRemoval({ hasWorkingTreeChanges: false, aheadCount: 0 })).toBe(true);
|
|
expect(canOfferWorktreeRemoval({ hasWorkingTreeChanges: true, aheadCount: 0 })).toBe(false);
|
|
expect(canOfferWorktreeRemoval({ hasWorkingTreeChanges: false, aheadCount: 1 })).toBe(false);
|
|
});
|
|
});
|