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

Sidebar.logic.test.ts

1,463 lines43.8 KB

1import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
2import {
3 archiveSelectedThreadEntries,
4 buildBulkTitleRegenerationContextMenuItem,
5 buildMultiSelectThreadContextMenuItems,
6 createThreadJumpHintVisibilityController,
7 getSidebarThreadIdsToPrewarm,
8 getVisibleSidebarThreadIds,
9 resolveAdjacentThreadId,
10 getFallbackThreadIdAfterDelete,
11 getVisibleThreadsForProject,
12 getProjectSortTimestamp,
13 hasUnseenCompletion,
14 isContextMenuPointerDown,
15 isTrailingDoubleClick,
16 orderItemsByPreferredIds,
17 resolveProjectStatusIndicator,
18 resolveSidebarStageBadgeLabel,
19 resolveThreadRowClassName,
20 resolveSidebarV2Status,
21 resolveThreadStatusPill,
22 resolveWorkingStartedAt,
23 formatWorkingDurationLabel,
24 shouldNavigateAfterProjectRemoval,
25 shouldClearThreadSelectionOnMouseDown,
26 sortLogicalProjectsForSidebar,
27 sortSettledThreadsForSidebarV2,
28 sortThreadsForSidebarV2,
29 sortProjectsForSidebar,
30 sortScopedProjectsForSidebar,
31 THREAD_JUMP_HINT_SHOW_DELAY_MS,
32} from "./Sidebar.logic";
33import {
34 EnvironmentId,
35 OrchestrationLatestTurn,
36 ProjectId,
37 ProviderInstanceId,
38 ThreadId,
39} from "@t3tools/contracts";
40​
41import {
42 DEFAULT_INTERACTION_MODE,
43 DEFAULT_RUNTIME_MODE,
44 type Project,
45 type Thread,
46} from "../types";
47​
48const localEnvironmentId = EnvironmentId.make("environment-local");
49​
50describe("shouldNavigateAfterProjectRemoval", () => {
51 const projectThreads = [{ environmentId: "environment-local", id: "thread-1" }];
52​
53 it("navigates away from a draft route owned by the removed project", () => {
54 expect(
55 shouldNavigateAfterProjectRemoval({
56 routeTarget: { kind: "draft", draftId: "draft-1" as never },
57 projectThreads,
58 projectDraftId: "draft-1",
59 }),
60 ).toBe(true);
61 });
62​
63 it("does not navigate away from a different draft route", () => {
64 expect(
65 shouldNavigateAfterProjectRemoval({
66 routeTarget: { kind: "draft", draftId: "draft-2" as never },
67 projectThreads,
68 projectDraftId: "draft-1",
69 }),
70 ).toBe(false);
71 });
72​
73 it("navigates away from a server thread owned by the removed project", () => {
74 expect(
75 shouldNavigateAfterProjectRemoval({
76 routeTarget: {
77 kind: "server",
78 threadRef: {
79 environmentId: EnvironmentId.make("environment-local"),
80 threadId: ThreadId.make("thread-1"),
81 },
82 },
83 projectThreads,
84 projectDraftId: null,
85 }),
86 ).toBe(true);
87 });
88​
89 it("does not navigate from an unrelated route", () => {
90 expect(
91 shouldNavigateAfterProjectRemoval({
92 routeTarget: null,
93 projectThreads,
94 projectDraftId: null,
95 }),
96 ).toBe(false);
97 });
98});
99​
100describe("archiveSelectedThreadEntries", () => {
101 const entries = [{ threadKey: "one" }, { threadKey: "two" }, { threadKey: "three" }] as const;
102 const success = { _tag: "Success" } as const;
103 const failure = { _tag: "Failure" } as const;
104​
105 it("records every entry after full success", async () => {
106 const outcome = await archiveSelectedThreadEntries({
107 entries,
108 archive: async (_entry, onArchived) => {
109 onArchived();
110 return success;
111 },
112 });
113​
114 expect(outcome).toEqual({
115 archivedThreadKeys: ["one", "two", "three"],
116 mutationFailure: null,
117 followupFailures: [],
118 });
119 });
120​
121 it("stops at a mutation failure and retains prior successes", async () => {
122 const archive = vi.fn(async (entry: (typeof entries)[number], onArchived: () => void) => {
123 if (entry.threadKey === "two") return failure;
124 onArchived();
125 return success;
126 });
127 const outcome = await archiveSelectedThreadEntries({ entries, archive });
128​
129 expect(archive).toHaveBeenCalledTimes(2);
130 expect(outcome).toEqual({
131 archivedThreadKeys: ["one"],
132 mutationFailure: failure,
133 followupFailures: [],
134 });
135 });
136​
137 it("continues after a post-archive failure", async () => {
138 const archive = vi.fn(async (entry: (typeof entries)[number], onArchived: () => void) => {
139 onArchived();
140 return entry.threadKey === "two" ? failure : success;
141 });
142 const outcome = await archiveSelectedThreadEntries({ entries, archive });
143​
144 expect(archive).toHaveBeenCalledTimes(3);
145 expect(outcome).toEqual({
146 archivedThreadKeys: ["one", "two", "three"],
147 mutationFailure: null,
148 followupFailures: [failure],
149 });
150 });
151});
152​
153describe("buildBulkTitleRegenerationContextMenuItem", () => {
154 it("counts only threads that can start a new regeneration", () => {
155 expect(
156 buildBulkTitleRegenerationContextMenuItem({
157 supportedCount: 4,
158 actionableCount: 3,
159 }),
160 ).toEqual({
161 id: "regenerate-title",
162 label: "Regenerate titles (3)",
163 });
164 });
165​
166 it("shows a disabled progress item when every supported thread is pending", () => {
167 expect(
168 buildBulkTitleRegenerationContextMenuItem({
169 supportedCount: 2,
170 actionableCount: 0,
171 }),
172 ).toEqual({
173 id: "regenerate-title",
174 label: "Regenerating… (2)",
175 disabled: true,
176 });
177 });
178​
179 it("omits the action when no selected environment supports it", () => {
180 expect(
181 buildBulkTitleRegenerationContextMenuItem({
182 supportedCount: 0,
183 actionableCount: 0,
184 }),
185 ).toBeNull();
186 });
187});
188​
189describe("buildMultiSelectThreadContextMenuItems", () => {
190 it("offers bulk archive with the selected count", () => {
191 expect(
192 buildMultiSelectThreadContextMenuItems({ count: 3, hasRunningThread: false }),
193 ).toContainEqual({ id: "archive", label: "Archive (3)", disabled: false });
194 });
195​
196 it("disables bulk archive when a selected thread is running", () => {
197 expect(
198 buildMultiSelectThreadContextMenuItems({ count: 2, hasRunningThread: true }),
199 ).toContainEqual({ id: "archive", label: "Archive (2)", disabled: true });
200 });
201});
202​
203describe("resolveSidebarStageBadgeLabel", () => {
204 it("returns Nightly for nightly primary server versions", () => {
205 expect(
206 resolveSidebarStageBadgeLabel({
207 primaryServerVersion: "0.0.28-nightly.20260616.12",
208 fallbackStageLabel: "Alpha",
209 }),
210 ).toBe("Nightly");
211 });
212​
213 it("returns the fallback label for stable primary server versions", () => {
214 expect(
215 resolveSidebarStageBadgeLabel({
216 primaryServerVersion: "0.0.27",
217 fallbackStageLabel: "Alpha",
218 }),
219 ).toBe("Alpha");
220 });
221​
222 it("returns the fallback label when the primary server version is missing", () => {
223 expect(
224 resolveSidebarStageBadgeLabel({
225 primaryServerVersion: null,
226 fallbackStageLabel: "Dev",
227 }),
228 ).toBe("Dev");
229 });
230​
231 it("returns the fallback label for malformed nightly prerelease versions", () => {
232 expect(
233 resolveSidebarStageBadgeLabel({
234 primaryServerVersion: "0.0.28-nightly.20260616",
235 fallbackStageLabel: "Alpha",
236 }),
237 ).toBe("Alpha");
238 });
239});
240​
241function makeLatestTurn(overrides?: {
242 completedAt?: string | null;
243 startedAt?: string | null;
244}): OrchestrationLatestTurn {
245 return {
246 turnId: "turn-1" as never,
247 state: "completed",
248 assistantMessageId: null,
249 requestedAt: "2026-03-09T10:00:00.000Z",
250 startedAt:
251 overrides?.startedAt !== undefined ? overrides.startedAt : "2026-03-09T10:00:00.000Z",
252 completedAt:
253 overrides?.completedAt !== undefined ? overrides.completedAt : "2026-03-09T10:05:00.000Z",
254 };
256​
257describe("hasUnseenCompletion", () => {
258 it("returns true when a thread completed after its last visit", () => {
259 expect(
260 hasUnseenCompletion({
261 hasActionableProposedPlan: false,
262 hasPendingApprovals: false,
263 hasPendingUserInput: false,
264 interactionMode: "default",
265 latestTurn: makeLatestTurn(),
266 lastVisitedAt: "2026-03-09T10:04:00.000Z",
267 session: null,
268 }),
269 ).toBe(true);
270 });
271​
272 it("treats a missing client visit marker as read", () => {
273 expect(
274 hasUnseenCompletion({
275 hasActionableProposedPlan: false,
276 hasPendingApprovals: false,
277 hasPendingUserInput: false,
278 interactionMode: "default",
279 latestTurn: makeLatestTurn(),
280 lastVisitedAt: undefined,
281 session: null,
282 }),
283 ).toBe(false);
284 });
285});
286​
287describe("createThreadJumpHintVisibilityController", () => {
288 beforeEach(() => {
289 vi.useFakeTimers();
290 });
291​
292 afterEach(() => {
293 vi.useRealTimers();
294 });
295​
296 it("delays showing jump hints until the configured delay elapses", () => {
297 const visibilityChanges: boolean[] = [];
298 const controller = createThreadJumpHintVisibilityController({
299 delayMs: THREAD_JUMP_HINT_SHOW_DELAY_MS,
300 onVisibilityChange: (visible) => {
301 visibilityChanges.push(visible);
302 },
303 });
304​
305 controller.sync(true);
306 vi.advanceTimersByTime(THREAD_JUMP_HINT_SHOW_DELAY_MS - 1);
307​
308 expect(visibilityChanges).toEqual([]);
309​
310 vi.advanceTimersByTime(1);
311​
312 expect(visibilityChanges).toEqual([true]);
313 });
314​
315 it("hides immediately when the modifiers are released", () => {
316 const visibilityChanges: boolean[] = [];
317 const controller = createThreadJumpHintVisibilityController({
318 delayMs: THREAD_JUMP_HINT_SHOW_DELAY_MS,
319 onVisibilityChange: (visible) => {
320 visibilityChanges.push(visible);
321 },
322 });
323​
324 controller.sync(true);
325 vi.advanceTimersByTime(THREAD_JUMP_HINT_SHOW_DELAY_MS);
326 controller.sync(false);
327​
328 expect(visibilityChanges).toEqual([true, false]);
329 });
330​
331 it("cancels a pending reveal when the modifier is released early", () => {
332 const visibilityChanges: boolean[] = [];
333 const controller = createThreadJumpHintVisibilityController({
334 delayMs: THREAD_JUMP_HINT_SHOW_DELAY_MS,
335 onVisibilityChange: (visible) => {
336 visibilityChanges.push(visible);
337 },
338 });
339​
340 controller.sync(true);
341 vi.advanceTimersByTime(Math.floor(THREAD_JUMP_HINT_SHOW_DELAY_MS / 2));
342 controller.sync(false);
343 vi.advanceTimersByTime(THREAD_JUMP_HINT_SHOW_DELAY_MS);
344​
345 expect(visibilityChanges).toEqual([]);
346 });
347});
348​
349describe("getSidebarThreadIdsToPrewarm", () => {
350 it("returns only the first visible thread ids up to the prewarm limit", () => {
351 expect(getSidebarThreadIdsToPrewarm(["t1", "t2", "t3"], 2)).toEqual(["t1", "t2"]);
352 });
353​
354 it("returns all visible thread ids when they fit within the limit", () => {
355 expect(getSidebarThreadIdsToPrewarm(["t1", "t2"], 10)).toEqual(["t1", "t2"]);
356 });
357​
358 it("returns no thread ids when the limit is zero", () => {
359 expect(getSidebarThreadIdsToPrewarm(["t1", "t2"], 0)).toEqual([]);
360 });
361});
362​
363describe("shouldClearThreadSelectionOnMouseDown", () => {
364 it("preserves selection for thread items", () => {
365 const child = {
366 closest: (selector: string) =>
367 selector.includes("[data-thread-item]") ? ({} as Element) : null,
368 } as unknown as HTMLElement;
369​
370 expect(shouldClearThreadSelectionOnMouseDown(child)).toBe(false);
371 });
372​
373 it("preserves selection for thread list toggle controls", () => {
374 const selectionSafe = {
375 closest: (selector: string) =>
376 selector.includes("[data-thread-selection-safe]") ? ({} as Element) : null,
377 } as unknown as HTMLElement;
378​
379 expect(shouldClearThreadSelectionOnMouseDown(selectionSafe)).toBe(false);
380 });
381​
382 it("clears selection for unrelated sidebar clicks", () => {
383 const unrelated = {
384 closest: () => null,
385 } as unknown as HTMLElement;
386​
387 expect(shouldClearThreadSelectionOnMouseDown(unrelated)).toBe(true);
388 });
389});
390​
391describe("isTrailingDoubleClick", () => {
392 it("treats a single click as a normal activation", () => {
393 expect(isTrailingDoubleClick(1)).toBe(false);
394 });
395​
396 it("treats synthetic/keyboard activations (detail 0) as a normal activation", () => {
397 expect(isTrailingDoubleClick(0)).toBe(false);
398 });
399​
400 it("ignores the second click of a double-click so it does not navigate", () => {
401 expect(isTrailingDoubleClick(2)).toBe(true);
402 });
403​
404 it("ignores further clicks of a triple-click", () => {
405 expect(isTrailingDoubleClick(3)).toBe(true);
406 });
407});
408​
409describe("orderItemsByPreferredIds", () => {
410 it("keeps preferred ids first, skips stale ids, and preserves the relative order of remaining items", () => {
411 const ordered = orderItemsByPreferredIds({
412 items: [
413 { id: ProjectId.make("project-1"), name: "One" },
414 { id: ProjectId.make("project-2"), name: "Two" },
415 { id: ProjectId.make("project-3"), name: "Three" },
416 ],
417 preferredIds: [
418 ProjectId.make("project-3"),
419 ProjectId.make("project-missing"),
420 ProjectId.make("project-1"),
421 ],
422 getId: (project) => project.id,
423 });
424​
425 expect(ordered.map((project) => project.id)).toEqual([
426 ProjectId.make("project-3"),
427 ProjectId.make("project-1"),
428 ProjectId.make("project-2"),
429 ]);
430 });
431​
432 it("does not duplicate items when preferred ids repeat", () => {
433 const ordered = orderItemsByPreferredIds({
434 items: [
435 { id: ProjectId.make("project-1"), name: "One" },
436 { id: ProjectId.make("project-2"), name: "Two" },
437 ],
438 preferredIds: [
439 ProjectId.make("project-2"),
440 ProjectId.make("project-1"),
441 ProjectId.make("project-2"),
442 ],
443 getId: (project) => project.id,
444 });
445​
446 expect(ordered.map((project) => project.id)).toEqual([
447 ProjectId.make("project-2"),
448 ProjectId.make("project-1"),
449 ]);
450 });
451​
452 it("honors projectOrder physical keys via getProjectOrderKey", async () => {
453 // Regression guard for #1904 / the regression introduced by #2055:
454 // `projectOrder` is populated with physical keys (envId + cwd-derived)
455 // by the store and by drag-end handlers. Readers must identify projects
456 // with the same key format, or manual sort silently snaps back.
457 const { getProjectOrderKey } = await import("../logicalProject");
458 const projects = [
459 {
460 environmentId: EnvironmentId.make("environment-local"),
461 id: ProjectId.make("id-alpha"),
462 workspaceRoot: "/work/alpha",
463 },
464 {
465 environmentId: EnvironmentId.make("environment-local"),
466 id: ProjectId.make("id-beta"),
467 workspaceRoot: "/work/beta",
468 },
469 {
470 environmentId: EnvironmentId.make("environment-local"),
471 id: ProjectId.make("id-gamma"),
472 workspaceRoot: "/work/gamma",
473 },
474 ];
475 const ordered = orderItemsByPreferredIds({
476 items: projects,
477 preferredIds: [getProjectOrderKey(projects[2]!), getProjectOrderKey(projects[0]!)],
478 getId: getProjectOrderKey,
479 });
480​
481 expect(ordered.map((project) => project.workspaceRoot)).toEqual([
482 "/work/gamma",
483 "/work/alpha",
484 "/work/beta",
485 ]);
486 });
487​
488 it("resolves legacy preference aliases without materializing project state", () => {
489 const ordered = orderItemsByPreferredIds({
490 items: [
491 { id: "physical-a", cwd: "/work/a" },
492 { id: "physical-b", cwd: "/work/b" },
493 { id: "physical-c", cwd: "/work/c" },
494 ],
495 preferredIds: ["legacy:/work/c", "legacy:/work/a"],
496 getId: (project) => project.id,
497 getPreferenceIds: (project) => [project.id, `legacy:${project.cwd}`],
498 });
499​
500 expect(ordered.map((project) => project.id)).toEqual([
501 "physical-c",
502 "physical-a",
503 "physical-b",
504 ]);
505 });
506});
507​
508describe("resolveAdjacentThreadId", () => {
509 it("resolves adjacent thread ids in ordered sidebar traversal", () => {
510 const threads = [
511 ThreadId.make("thread-1"),
512 ThreadId.make("thread-2"),
513 ThreadId.make("thread-3"),
514 ];
515​
516 expect(
517 resolveAdjacentThreadId({
518 threadIds: threads,
519 currentThreadId: threads[1] ?? null,
520 direction: "previous",
521 }),
522 ).toBe(threads[0]);
523 expect(
524 resolveAdjacentThreadId({
525 threadIds: threads,
526 currentThreadId: threads[1] ?? null,
527 direction: "next",
528 }),
529 ).toBe(threads[2]);
530 expect(
531 resolveAdjacentThreadId({
532 threadIds: threads,
533 currentThreadId: null,
534 direction: "next",
535 }),
536 ).toBe(threads[0]);
537 expect(
538 resolveAdjacentThreadId({
539 threadIds: threads,
540 currentThreadId: null,
541 direction: "previous",
542 }),
543 ).toBe(threads[2]);
544 expect(
545 resolveAdjacentThreadId({
546 threadIds: threads,
547 currentThreadId: threads[0] ?? null,
548 direction: "previous",
549 }),
550 ).toBeNull();
551 });
552});
553​
554describe("getVisibleSidebarThreadIds", () => {
555 it("returns only the rendered visible thread order across projects", () => {
556 expect(
557 getVisibleSidebarThreadIds([
558 {
559 renderedThreadIds: [
560 ThreadId.make("thread-12"),
561 ThreadId.make("thread-11"),
562 ThreadId.make("thread-10"),
563 ],
564 },
565 {
566 renderedThreadIds: [ThreadId.make("thread-8"), ThreadId.make("thread-6")],
567 },
568 ]),
569 ).toEqual([
570 ThreadId.make("thread-12"),
571 ThreadId.make("thread-11"),
572 ThreadId.make("thread-10"),
573 ThreadId.make("thread-8"),
574 ThreadId.make("thread-6"),
575 ]);
576 });
577​
578 it("skips threads from collapsed projects whose thread panels are not shown", () => {
579 expect(
580 getVisibleSidebarThreadIds([
581 {
582 shouldShowThreadPanel: false,
583 renderedThreadIds: [ThreadId.make("thread-hidden-2"), ThreadId.make("thread-hidden-1")],
584 },
585 {
586 shouldShowThreadPanel: true,
587 renderedThreadIds: [ThreadId.make("thread-12"), ThreadId.make("thread-11")],
588 },
589 ]),
590 ).toEqual([ThreadId.make("thread-12"), ThreadId.make("thread-11")]);
591 });
592});
593​
594describe("isContextMenuPointerDown", () => {
595 it("treats secondary-button presses as context menu gestures on all platforms", () => {
596 expect(
597 isContextMenuPointerDown({
598 button: 2,
599 ctrlKey: false,
600 isMac: false,
601 }),
602 ).toBe(true);
603 });
604​
605 it("treats ctrl+primary-click as a context menu gesture on macOS", () => {
606 expect(
607 isContextMenuPointerDown({
608 button: 0,
609 ctrlKey: true,
610 isMac: true,
611 }),
612 ).toBe(true);
613 });
614​
615 it("does not treat ctrl+primary-click as a context menu gesture off macOS", () => {
616 expect(
617 isContextMenuPointerDown({
618 button: 0,
619 ctrlKey: true,
620 isMac: false,
621 }),
622 ).toBe(false);
623 });
624});
625​
626describe("resolveSidebarV2Status", () => {
627 const session = {
628 threadId: ThreadId.make("thread-1"),
629 status: "running" as const,
630 providerName: "Codex",
631 providerInstanceId: ProviderInstanceId.make("codex"),
632 runtimeMode: DEFAULT_RUNTIME_MODE,
633 activeTurnId: "turn-1" as never,
634 lastError: null,
635 updatedAt: "2026-03-09T10:00:00.000Z",
636 };
637​
638 const idle = { hasPendingApprovals: false, hasPendingUserInput: false };
639​
640 it("prioritizes approval over a running session", () => {
641 expect(resolveSidebarV2Status({ ...idle, hasPendingApprovals: true, session })).toBe(
642 "approval",
643 );
644 });
645​
646 it("prioritizes awaiting input over a running session, below approval", () => {
647 expect(resolveSidebarV2Status({ ...idle, hasPendingUserInput: true, session })).toBe("input");
648 expect(
649 resolveSidebarV2Status({
650 ...idle,
651 hasPendingApprovals: true,
652 hasPendingUserInput: true,
653 session,
654 }),
655 ).toBe("approval");
656 });
657​
658 it("reports working for running and starting sessions", () => {
659 expect(resolveSidebarV2Status({ ...idle, session })).toBe("working");
660 expect(
661 resolveSidebarV2Status({
662 ...idle,
663 session: { ...session, status: "starting" as const },
664 }),
665 ).toBe("working");
666 });
667​
668 it("reports failed only while the session status is error", () => {
669 expect(
670 resolveSidebarV2Status({
671 ...idle,
672 session: { ...session, status: "error" as const, lastError: "boom" },
673 }),
674 ).toBe("failed");
675 expect(
676 resolveSidebarV2Status({
677 ...idle,
678 session: { ...session, status: "stopped" as const, lastError: "persisted" },
679 }),
680 ).toBe("ready");
681 expect(
682 resolveSidebarV2Status({
683 ...idle,
684 session: { ...session, status: "ready" as const, lastError: "persisted" },
685 }),
686 ).toBe("ready");
687 });
688​
689 it("defaults to ready with no session", () => {
690 expect(resolveSidebarV2Status({ ...idle, session: null })).toBe("ready");
691 });
692});
693​
694describe("sortThreadsForSidebarV2", () => {
695 const sortable = (input: { id: string; createdAt: string }) => ({
696 id: input.id,
697 createdAt: input.createdAt,
698 });
699​
700 it("orders by creation time, newest first, ignoring activity", () => {
701 const sorted = sortThreadsForSidebarV2([
702 sortable({ id: "oldest", createdAt: "2026-03-09T08:00:00.000Z" }),
703 sortable({ id: "newest", createdAt: "2026-03-09T12:00:00.000Z" }),
704 sortable({ id: "middle", createdAt: "2026-03-09T10:00:00.000Z" }),
705 ]);
706​
707 expect(sorted.map((thread) => thread.id)).toEqual(["newest", "middle", "oldest"]);
708 });
709​
710 it("breaks creation-time ties by id so the order is stable", () => {
711 const sorted = sortThreadsForSidebarV2([
712 sortable({ id: "b", createdAt: "2026-03-09T10:00:00.000Z" }),
713 sortable({ id: "a", createdAt: "2026-03-09T10:00:00.000Z" }),
714 ]);
715​
716 expect(sorted.map((thread) => thread.id)).toEqual(["a", "b"]);
717 });
718});
719​
720describe("sortSettledThreadsForSidebarV2", () => {
721 const settled = (input: {
722 id: string;
723 settledAt?: string | null;
724 latestUserMessageAt?: string | null;
725 latestTurn?: OrchestrationLatestTurn | null;
726 updatedAt?: string;
727 }) => ({
728 id: input.id,
729 settledAt: input.settledAt ?? null,
730 latestUserMessageAt: input.latestUserMessageAt ?? null,
731 latestTurn: input.latestTurn ?? null,
732 updatedAt: input.updatedAt ?? "2026-03-09T09:00:00.000Z",
733 });
734​
735 it("orders by settle time, most recently settled first", () => {
736 const sorted = sortSettledThreadsForSidebarV2([
737 settled({
738 id: "settled-first",
739 settledAt: "2026-03-09T10:00:00.000Z",
740 // Created/active later than the other thread: settle time must win.
741 latestUserMessageAt: "2026-03-09T09:59:00.000Z",
742 }),
743 settled({
744 id: "settled-last",
745 settledAt: "2026-03-09T12:00:00.000Z",
746 latestUserMessageAt: "2026-03-09T08:00:00.000Z",
747 }),
748 ]);
749​
750 expect(sorted.map((thread) => thread.id)).toEqual(["settled-last", "settled-first"]);
751 });
752​
753 it("falls back to last activity for auto-settled threads without a settledAt stamp", () => {
754 const sorted = sortSettledThreadsForSidebarV2([
755 settled({ id: "auto-old", latestUserMessageAt: "2026-03-09T08:00:00.000Z" }),
756 settled({ id: "explicit", settledAt: "2026-03-09T10:00:00.000Z" }),
757 settled({ id: "auto-recent", latestUserMessageAt: "2026-03-09T11:00:00.000Z" }),
758 ]);
759​
760 expect(sorted.map((thread) => thread.id)).toEqual(["auto-recent", "explicit", "auto-old"]);
761 });
762​
763 it("counts a turn completion as activity for auto-settled threads", () => {
764 // The message came in before the other thread's, but its turn finished
765 // after: completion time is the real "work ended" moment.
766 const sorted = sortSettledThreadsForSidebarV2([
767 settled({ id: "message-only", latestUserMessageAt: "2026-03-09T10:04:00.000Z" }),
768 settled({
769 id: "completed-later",
770 latestUserMessageAt: "2026-03-09T10:00:00.000Z",
771 latestTurn: makeLatestTurn({ completedAt: "2026-03-09T10:30:00.000Z" }),
772 }),
773 ]);
774​
775 expect(sorted.map((thread) => thread.id)).toEqual(["completed-later", "message-only"]);
776 });
777​
778 it("breaks timestamp ties by id so the order is stable", () => {
779 const sorted = sortSettledThreadsForSidebarV2([
780 settled({ id: "b", settledAt: "2026-03-09T10:00:00.000Z" }),
781 settled({ id: "a", settledAt: "2026-03-09T10:00:00.000Z" }),
782 ]);
783​
784 expect(sorted.map((thread) => thread.id)).toEqual(["a", "b"]);
785 });
786});
787​
788describe("resolveWorkingStartedAt", () => {
789 const session = {
790 threadId: ThreadId.make("thread-1"),
791 status: "running" as const,
792 providerName: "Codex",
793 providerInstanceId: ProviderInstanceId.make("codex"),
794 runtimeMode: DEFAULT_RUNTIME_MODE,
795 activeTurnId: "turn-1" as never,
796 lastError: null,
797 updatedAt: "2026-03-09T10:02:00.000Z",
798 };
799​
800 it("uses the running turn's start time", () => {
801 expect(
802 resolveWorkingStartedAt({
803 latestTurn: makeLatestTurn({ completedAt: null }),
804 session,
805 }),
806 ).toBe("2026-03-09T10:00:00.000Z");
807 });
808​
809 it("uses the request time while a turn awaits adoption", () => {
810 expect(
811 resolveWorkingStartedAt({
812 latestTurn: makeLatestTurn({ startedAt: null, completedAt: null }),
813 session,
814 }),
815 ).toBe("2026-03-09T10:00:00.000Z");
816 });
817​
818 it("falls back to the session transition when the latest turn already completed", () => {
819 expect(
820 resolveWorkingStartedAt({
821 latestTurn: makeLatestTurn(),
822 session,
823 }),
824 ).toBe("2026-03-09T10:02:00.000Z");
825 });
826​
827 it("skips a malformed startedAt instead of returning it", () => {
828 expect(
829 resolveWorkingStartedAt({
830 latestTurn: makeLatestTurn({ startedAt: "not-a-date", completedAt: null }),
831 session,
832 }),
833 ).toBe("2026-03-09T10:00:00.000Z");
834 });
835​
836 it("returns null with neither a running turn nor a session", () => {
837 expect(resolveWorkingStartedAt({ latestTurn: null, session: null })).toBeNull();
838 });
839});
840​
841describe("formatWorkingDurationLabel", () => {
842 it("formats seconds, minutes, and hours", () => {
843 expect(formatWorkingDurationLabel(0)).toBe("0s");
844 expect(formatWorkingDurationLabel(42_000)).toBe("42s");
845 expect(formatWorkingDurationLabel(5 * 60_000)).toBe("5m");
846 expect(formatWorkingDurationLabel(90 * 60_000)).toBe("1h 30m");
847 });
848​
849 it("clamps negative and non-finite elapsed values to zero", () => {
850 expect(formatWorkingDurationLabel(-5_000)).toBe("0s");
851 expect(formatWorkingDurationLabel(Number.NaN)).toBe("0s");
852 });
853});
854​
855describe("resolveThreadStatusPill", () => {
856 const baseThread = {
857 hasActionableProposedPlan: false,
858 hasPendingApprovals: false,
859 hasPendingUserInput: false,
860 interactionMode: "plan" as const,
861 latestTurn: null,
862 lastVisitedAt: undefined,
863 session: {
864 threadId: ThreadId.make("thread-1"),
865 status: "running" as const,
866 providerName: "Codex",
867 providerInstanceId: ProviderInstanceId.make("codex"),
868 runtimeMode: DEFAULT_RUNTIME_MODE,
869 activeTurnId: "turn-1" as never,
870 lastError: null,
871 updatedAt: "2026-03-09T10:00:00.000Z",
872 },
873 };
874​
875 it("shows pending approval before all other statuses", () => {
876 expect(
877 resolveThreadStatusPill({
878 thread: {
879 ...baseThread,
880 hasPendingApprovals: true,
881 hasPendingUserInput: true,
882 },
883 }),
884 ).toMatchObject({ label: "Pending Approval", pulse: false });
885 });
886​
887 it("shows awaiting input when plan mode is blocked on user answers", () => {
888 expect(
889 resolveThreadStatusPill({
890 thread: {
891 ...baseThread,
892 hasPendingUserInput: true,
893 },
894 }),
895 ).toMatchObject({ label: "Awaiting Input", pulse: false });
896 });
897​
898 it("falls back to working when the thread is actively running without blockers", () => {
899 expect(
900 resolveThreadStatusPill({
901 thread: baseThread,
902 }),
903 ).toMatchObject({ label: "Working", pulse: true });
904 });
905​
906 it("shows plan ready when a settled plan turn has a proposed plan ready for follow-up", () => {
907 expect(
908 resolveThreadStatusPill({
909 thread: {
910 ...baseThread,
911 hasActionableProposedPlan: true,
912 latestTurn: makeLatestTurn(),
913 session: {
914 ...baseThread.session,
915 status: "ready",
916 activeTurnId: null,
917 },
918 },
919 }),
920 ).toMatchObject({ label: "Plan Ready", pulse: false });
921 });
922​
923 it("does not manufacture completed state without a client visit marker", () => {
924 expect(
925 resolveThreadStatusPill({
926 thread: {
927 ...baseThread,
928 latestTurn: makeLatestTurn(),
929 session: {
930 ...baseThread.session,
931 status: "ready",
932 activeTurnId: null,
933 },
934 },
935 }),
936 ).toBeNull();
937 });
938​
939 it("shows completed when there is an unseen completion and no active blocker", () => {
940 expect(
941 resolveThreadStatusPill({
942 thread: {
943 ...baseThread,
944 interactionMode: "default",
945 latestTurn: makeLatestTurn(),
946 lastVisitedAt: "2026-03-09T10:04:00.000Z",
947 session: {
948 ...baseThread.session,
949 status: "ready",
950 activeTurnId: null,
951 },
952 },
953 }),
954 ).toMatchObject({ label: "Completed", pulse: false });
955 });
956});
957​
958describe("resolveThreadRowClassName", () => {
959 it("uses the active sidebar surface when a thread is both selected and active", () => {
960 const className = resolveThreadRowClassName({ isActive: true, isSelected: true });
961 expect(className).toContain("bg-sidebar-row-active");
962 expect(className).toContain("text-sidebar-foreground");
963 expect(className).not.toContain("bg-primary");
964 });
965​
966 it("uses selected hover colors for selected threads", () => {
967 const className = resolveThreadRowClassName({ isActive: false, isSelected: true });
968 expect(className).toContain("bg-sidebar-row-selected");
969 expect(className).toContain("hover:bg-sidebar-row-active");
970 expect(className).not.toContain("bg-primary");
971 });
972​
973 it("uses the active sidebar surface for active-only threads", () => {
974 const className = resolveThreadRowClassName({ isActive: true, isSelected: false });
975 expect(className).toContain("bg-sidebar-row-active");
976 expect(className).toContain("hover:bg-sidebar-row-active");
977 });
978});
979​
980describe("resolveProjectStatusIndicator", () => {
981 it("returns null when no threads have a notable status", () => {
982 expect(resolveProjectStatusIndicator([null, null])).toBeNull();
983 });
984​
985 it("surfaces the highest-priority actionable state across project threads", () => {
986 expect(
987 resolveProjectStatusIndicator([
988 {
989 label: "Completed",
990 colorClass: "text-emerald-600",
991 dotClass: "bg-emerald-500",
992 pulse: false,
993 },
994 {
995 label: "Pending Approval",
996 colorClass: "text-amber-600",
997 dotClass: "bg-amber-500",
998 pulse: false,
999 },
1001 label: "Working",
1002 colorClass: "text-sky-600",
1003 dotClass: "bg-sky-500",
1004 pulse: true,
1005 },
1006 ]),
1007 ).toMatchObject({ label: "Pending Approval", dotClass: "bg-amber-500" });
1008 });
1009​
1010 it("prefers plan-ready over completed when no stronger action is needed", () => {
1011 expect(
1012 resolveProjectStatusIndicator([
1014 label: "Completed",
1015 colorClass: "text-emerald-600",
1016 dotClass: "bg-emerald-500",
1017 pulse: false,
1018 },
1020 label: "Plan Ready",
1021 colorClass: "text-violet-600",
1022 dotClass: "bg-violet-500",
1023 pulse: false,
1024 },
1025 ]),
1026 ).toMatchObject({ label: "Plan Ready", dotClass: "bg-violet-500" });
1027 });
1028});
1029​
1030describe("getVisibleThreadsForProject", () => {
1031 it("includes the active thread even when it falls below the folded preview", () => {
1032 const threads = Array.from({ length: 8 }, (_, index) =>
1033 makeThread({
1034 id: ThreadId.make(`thread-${index + 1}`),
1035 title: `Thread ${index + 1}`,
1036 }),
1037 );
1038​
1039 const result = getVisibleThreadsForProject({
1040 threads,
1041 activeThreadId: ThreadId.make("thread-8"),
1042 isThreadListExpanded: false,
1043 previewLimit: 6,
1044 });
1045​
1046 expect(result.hasHiddenThreads).toBe(true);
1047 expect(result.visibleThreads.map((thread) => thread.id)).toEqual([
1048 ThreadId.make("thread-1"),
1049 ThreadId.make("thread-2"),
1050 ThreadId.make("thread-3"),
1051 ThreadId.make("thread-4"),
1052 ThreadId.make("thread-5"),
1053 ThreadId.make("thread-6"),
1054 ThreadId.make("thread-8"),
1055 ]);
1056 expect(result.hiddenThreads.map((thread) => thread.id)).toEqual([ThreadId.make("thread-7")]);
1057 });
1058​
1059 it("returns all threads when the list is expanded", () => {
1060 const threads = Array.from({ length: 8 }, (_, index) =>
1061 makeThread({
1062 id: ThreadId.make(`thread-${index + 1}`),
1063 }),
1064 );
1065​
1066 const result = getVisibleThreadsForProject({
1067 threads,
1068 activeThreadId: ThreadId.make("thread-8"),
1069 isThreadListExpanded: true,
1070 previewLimit: 6,
1071 });
1072​
1073 expect(result.hasHiddenThreads).toBe(true);
1074 expect(result.visibleThreads.map((thread) => thread.id)).toEqual(
1075 threads.map((thread) => thread.id),
1076 );
1077 expect(result.hiddenThreads).toEqual([]);
1078 });
1079});
1080​
1081function makeProject(overrides: Partial<Project> = {}): Project {
1082 const { defaultModelSelection, ...rest } = overrides;
1083 return {
1084 id: ProjectId.make("project-1"),
1085 environmentId: localEnvironmentId,
1086 title: "Project",
1087 workspaceRoot: "/tmp/project",
1088 repositoryIdentity: null,
1089 defaultModelSelection: {
1090 instanceId: ProviderInstanceId.make("codex"),
1091 model: "gpt-5.4",
1092 ...defaultModelSelection,
1093 },
1094 createdAt: "2026-03-09T10:00:00.000Z",
1095 updatedAt: "2026-03-09T10:00:00.000Z",
1096 scripts: [],
1097 ...rest,
1098 };
1100​
1101function makeThread(overrides: Partial<Thread> = {}): Thread {
1102 return {
1103 id: ThreadId.make("thread-1"),
1104 environmentId: localEnvironmentId,
1105 projectId: ProjectId.make("project-1"),
1106 title: "Thread",
1107 modelSelection: {
1108 instanceId: ProviderInstanceId.make("codex"),
1109 model: "gpt-5.4",
1110 ...overrides?.modelSelection,
1111 },
1112 runtimeMode: DEFAULT_RUNTIME_MODE,
1113 interactionMode: DEFAULT_INTERACTION_MODE,
1114 session: null,
1115 messages: [],
1116 proposedPlans: [],
1117 createdAt: "2026-03-09T10:00:00.000Z",
1118 archivedAt: null,
1119 settledOverride: null,
1120 settledAt: null,
1121 deletedAt: null,
1122 updatedAt: "2026-03-09T10:00:00.000Z",
1123 latestTurn: null,
1124 branch: null,
1125 worktreePath: null,
1126 checkpoints: [],
1127 activities: [],
1128 ...overrides,
1129 };
1131​
1132describe("getFallbackThreadIdAfterDelete", () => {
1133 it("returns the top remaining thread in the deleted thread's project sidebar order", () => {
1134 const fallbackThreadId = getFallbackThreadIdAfterDelete({
1135 threads: [
1136 makeThread({
1137 id: ThreadId.make("thread-oldest"),
1138 projectId: ProjectId.make("project-1"),
1139 createdAt: "2026-03-09T10:00:00.000Z",
1140 messages: [],
1141 }),
1142 makeThread({
1143 id: ThreadId.make("thread-active"),
1144 projectId: ProjectId.make("project-1"),
1145 createdAt: "2026-03-09T10:05:00.000Z",
1146 messages: [],
1147 }),
1148 makeThread({
1149 id: ThreadId.make("thread-newest"),
1150 projectId: ProjectId.make("project-1"),
1151 createdAt: "2026-03-09T10:10:00.000Z",
1152 messages: [],
1153 }),
1154 makeThread({
1155 id: ThreadId.make("thread-other-project"),
1156 projectId: ProjectId.make("project-2"),
1157 createdAt: "2026-03-09T10:20:00.000Z",
1158 messages: [],
1159 }),
1160 ],
1161 deletedThreadId: ThreadId.make("thread-active"),
1162 sortOrder: "created_at",
1163 });
1164​
1165 expect(fallbackThreadId).toBe(ThreadId.make("thread-newest"));
1166 });
1167​
1168 it("skips other threads being deleted in the same action", () => {
1169 const fallbackThreadId = getFallbackThreadIdAfterDelete({
1170 threads: [
1171 makeThread({
1172 id: ThreadId.make("thread-active"),
1173 projectId: ProjectId.make("project-1"),
1174 createdAt: "2026-03-09T10:05:00.000Z",
1175 messages: [],
1176 }),
1177 makeThread({
1178 id: ThreadId.make("thread-newest"),
1179 projectId: ProjectId.make("project-1"),
1180 createdAt: "2026-03-09T10:10:00.000Z",
1181 messages: [],
1182 }),
1183 makeThread({
1184 id: ThreadId.make("thread-next"),
1185 projectId: ProjectId.make("project-1"),
1186 createdAt: "2026-03-09T10:07:00.000Z",
1187 messages: [],
1188 }),
1189 ],
1190 deletedThreadId: ThreadId.make("thread-active"),
1191 deletedThreadIds: new Set([ThreadId.make("thread-active"), ThreadId.make("thread-newest")]),
1192 sortOrder: "created_at",
1193 });
1194​
1195 expect(fallbackThreadId).toBe(ThreadId.make("thread-next"));
1196 });
1197});
1198describe("sortProjectsForSidebar", () => {
1199 it("sorts projects by the most recent user message across their threads", () => {
1200 const projects = [
1201 makeProject({ id: ProjectId.make("project-1"), title: "Older project" }),
1202 makeProject({ id: ProjectId.make("project-2"), title: "Newer project" }),
1203 ];
1204 const threads = [
1205 makeThread({
1206 projectId: ProjectId.make("project-1"),
1207 updatedAt: "2026-03-09T10:20:00.000Z",
1208 messages: [
1210 id: "message-1" as never,
1211 role: "user",
1212 text: "older project user message",
1213 turnId: null,
1214 createdAt: "2026-03-09T10:01:00.000Z",
1215 updatedAt: "2026-03-09T10:01:00.000Z",
1216 streaming: false,
1217 },
1218 ],
1219 }),
1220 makeThread({
1221 id: ThreadId.make("thread-2"),
1222 projectId: ProjectId.make("project-2"),
1223 updatedAt: "2026-03-09T10:05:00.000Z",
1224 messages: [
1226 id: "message-2" as never,
1227 role: "user",
1228 text: "newer project user message",
1229 turnId: null,
1230 createdAt: "2026-03-09T10:05:00.000Z",
1231 updatedAt: "2026-03-09T10:05:00.000Z",
1232 streaming: false,
1233 },
1234 ],
1235 }),
1236 ];
1237​
1238 const sorted = sortProjectsForSidebar(projects, threads, "updated_at");
1239​
1240 expect(sorted.map((project) => project.id)).toEqual([
1241 ProjectId.make("project-2"),
1242 ProjectId.make("project-1"),
1243 ]);
1244 });
1245​
1246 it("falls back to project timestamps when a project has no threads", () => {
1247 const sorted = sortProjectsForSidebar(
1249 makeProject({
1250 id: ProjectId.make("project-1"),
1251 title: "Older project",
1252 updatedAt: "2026-03-09T10:01:00.000Z",
1253 }),
1254 makeProject({
1255 id: ProjectId.make("project-2"),
1256 title: "Newer project",
1257 updatedAt: "2026-03-09T10:05:00.000Z",
1258 }),
1259 ],
1260 [],
1261 "updated_at",
1262 );
1263​
1264 expect(sorted.map((project) => project.id)).toEqual([
1265 ProjectId.make("project-2"),
1266 ProjectId.make("project-1"),
1267 ]);
1268 });
1269​
1270 it("falls back to name and id ordering when projects have no sortable timestamps", () => {
1271 const sorted = sortProjectsForSidebar(
1273 makeProject({
1274 id: ProjectId.make("project-2"),
1275 title: "Beta",
1276 createdAt: "invalid-created-at" as never,
1277 updatedAt: "invalid-updated-at" as never,
1278 }),
1279 makeProject({
1280 id: ProjectId.make("project-1"),
1281 title: "Alpha",
1282 createdAt: "invalid-created-at" as never,
1283 updatedAt: "invalid-updated-at" as never,
1284 }),
1285 ],
1286 [],
1287 "updated_at",
1288 );
1289​
1290 expect(sorted.map((project) => project.id)).toEqual([
1291 ProjectId.make("project-1"),
1292 ProjectId.make("project-2"),
1293 ]);
1294 });
1295​
1296 it("preserves manual project ordering", () => {
1297 const projects = [
1298 makeProject({ id: ProjectId.make("project-2"), title: "Second" }),
1299 makeProject({ id: ProjectId.make("project-1"), title: "First" }),
1300 ];
1301​
1302 const sorted = sortProjectsForSidebar(projects, [], "manual");
1303​
1304 expect(sorted.map((project) => project.id)).toEqual([
1305 ProjectId.make("project-2"),
1306 ProjectId.make("project-1"),
1307 ]);
1308 });
1309​
1310 it("ignores archived threads when sorting projects", () => {
1311 const sorted = sortProjectsForSidebar(
1313 makeProject({
1314 id: ProjectId.make("project-1"),
1315 title: "Visible project",
1316 updatedAt: "2026-03-09T10:01:00.000Z",
1317 }),
1318 makeProject({
1319 id: ProjectId.make("project-2"),
1320 title: "Archived-only project",
1321 updatedAt: "2026-03-09T10:00:00.000Z",
1322 }),
1323 ],
1325 makeThread({
1326 id: ThreadId.make("thread-visible"),
1327 projectId: ProjectId.make("project-1"),
1328 updatedAt: "2026-03-09T10:02:00.000Z",
1329 archivedAt: null,
1330 }),
1331 makeThread({
1332 id: ThreadId.make("thread-archived"),
1333 projectId: ProjectId.make("project-2"),
1334 updatedAt: "2026-03-09T10:10:00.000Z",
1335 archivedAt: "2026-03-09T10:11:00.000Z",
1336 }),
1337 ].filter((thread) => thread.archivedAt === null),
1338 "updated_at",
1339 );
1340​
1341 expect(sorted.map((project) => project.id)).toEqual([
1342 ProjectId.make("project-1"),
1343 ProjectId.make("project-2"),
1344 ]);
1345 });
1346​
1347 it("returns the project timestamp when no threads are present", () => {
1348 const timestamp = getProjectSortTimestamp(
1349 makeProject({ updatedAt: "2026-03-09T10:10:00.000Z" }),
1350 [],
1351 "updated_at",
1352 );
1353​
1354 expect(timestamp).toBe(Date.parse("2026-03-09T10:10:00.000Z"));
1355 });
1356});
1357​
1358describe("sortScopedProjectsForSidebar", () => {
1359 it("keeps identical project ids in different environments separate", () => {
1360 const remoteEnvironmentId = EnvironmentId.make("environment-remote");
1361 const sharedProjectId = ProjectId.make("shared-project");
1362 const projects = [
1363 makeProject({
1364 environmentId: localEnvironmentId,
1365 id: sharedProjectId,
1366 title: "Local project",
1367 }),
1368 makeProject({
1369 environmentId: remoteEnvironmentId,
1370 id: sharedProjectId,
1371 title: "Remote project",
1372 }),
1373 ];
1374 const threads = [
1375 makeThread({
1376 environmentId: localEnvironmentId,
1377 projectId: sharedProjectId,
1378 updatedAt: "2026-03-09T10:02:00.000Z",
1379 }),
1380 makeThread({
1381 environmentId: remoteEnvironmentId,
1382 projectId: sharedProjectId,
1383 updatedAt: "2026-03-09T10:10:00.000Z",
1384 }),
1385 ];
1386​
1387 const sorted = sortScopedProjectsForSidebar(projects, threads, "updated_at");
1388​
1389 expect(sorted.map((project) => project.title)).toEqual(["Remote project", "Local project"]);
1390 });
1391​
1392 it("does not use archived threads as project activity", () => {
1393 const projects = [
1394 makeProject({
1395 id: ProjectId.make("project-visible"),
1396 title: "Visible project",
1397 updatedAt: "2026-03-09T10:01:00.000Z",
1398 }),
1399 makeProject({
1400 id: ProjectId.make("project-archived"),
1401 title: "Archived-only project",
1402 updatedAt: "2026-03-09T10:00:00.000Z",
1403 }),
1404 ];
1405 const threads = [
1406 makeThread({
1407 id: ThreadId.make("thread-visible"),
1408 projectId: ProjectId.make("project-visible"),
1409 updatedAt: "2026-03-09T10:02:00.000Z",
1410 }),
1411 makeThread({
1412 id: ThreadId.make("thread-archived"),
1413 projectId: ProjectId.make("project-archived"),
1414 updatedAt: "2026-03-09T10:10:00.000Z",
1415 archivedAt: "2026-03-09T10:11:00.000Z",
1416 }),
1417 ];
1418​
1419 const sorted = sortScopedProjectsForSidebar(projects, threads, "updated_at");
1420​
1421 expect(sorted.map((project) => project.title)).toEqual([
1422 "Visible project",
1423 "Archived-only project",
1424 ]);
1425 });
1426});
1427​
1428describe("sortLogicalProjectsForSidebar", () => {
1429 it("uses saved order only in manual mode and activity order otherwise", () => {
1430 const olderProjectId = ProjectId.make("project-older");
1431 const newerProjectId = ProjectId.make("project-newer");
1432 const projects = [
1434 ...makeProject({ id: olderProjectId, title: "Older project" }),
1435 projectKey: "logical-older",
1436 memberProjectRefs: [{ environmentId: localEnvironmentId, projectId: olderProjectId }],
1437 },
1439 ...makeProject({ id: newerProjectId, title: "Newer project" }),
1440 projectKey: "logical-newer",
1441 memberProjectRefs: [{ environmentId: localEnvironmentId, projectId: newerProjectId }],
1442 },
1443 ];
1444 const threads = [
1445 makeThread({
1446 projectId: olderProjectId,
1447 updatedAt: "2026-03-09T10:01:00.000Z",
1448 }),
1449 makeThread({
1450 id: ThreadId.make("thread-newer"),
1451 projectId: newerProjectId,
1452 updatedAt: "2026-03-09T10:05:00.000Z",
1453 }),
1454 ];
1455​
1456 expect(sortLogicalProjectsForSidebar(projects, threads, "manual")).toEqual(projects);
1457 expect(
1458 sortLogicalProjectsForSidebar(projects, threads, "updated_at").map(
1459 (project) => project.projectKey,
1460 ),
1461 ).toEqual(["logical-newer", "logical-older"]);
1462 });
1463});