Open History to see the last commit
1import type {
2 EnvironmentProject,
3 EnvironmentThreadShell,
4} from "@t3tools/client-runtime/state/shell";
5import { threadSearchMatchKey } from "@t3tools/client-runtime/state/thread-search";
6import { EnvironmentId, ProjectId, ProviderInstanceId, ThreadId } from "@t3tools/contracts";
7import { describe, expect, it } from "vite-plus/test";
8
9import {
10 buildHomeProjectScopes,
11 buildHomeThreadGroups,
12 sortHomeProjectScopes,
13} from "./homeThreadList";
14
15function makeProject(
16 input: Partial<EnvironmentProject> & Pick<EnvironmentProject, "environmentId" | "id" | "title">,
17): EnvironmentProject {
18 return {
19 workspaceRoot: `/workspaces/${input.id}`,
20 repositoryIdentity: null,
21 defaultModelSelection: null,
22 scripts: [],
23 createdAt: "2026-06-01T00:00:00.000Z",
24 updatedAt: "2026-06-01T00:00:00.000Z",
25 ...input,
26 };
27}
28
29function makeThread(
30 input: Partial<EnvironmentThreadShell> &
31 Pick<EnvironmentThreadShell, "environmentId" | "id" | "projectId" | "title">,
32): EnvironmentThreadShell {
33 return {
34 modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.4" },
35 runtimeMode: "full-access",
36 interactionMode: "default",
37 branch: null,
38 worktreePath: null,
39 pullRequests: [],
40 latestTurn: null,
41 createdAt: "2026-06-01T00:00:00.000Z",
42 updatedAt: "2026-06-01T00:00:00.000Z",
43 archivedAt: null,
44 session: null,
45 latestUserMessageAt: null,
46 hasPendingApprovals: false,
47 hasPendingUserInput: false,
48 hasActionableProposedPlan: false,
49 ...input,
50 settledOverride: input.settledOverride ?? null,
51 settledAt: input.settledAt ?? null,
52 };
53}
54
55const NOW = Date.parse("2026-06-29T00:00:00.000Z");
56
57function buildGroups(
58 projects: ReadonlyArray<EnvironmentProject>,
59 threads: ReadonlyArray<EnvironmentThreadShell>,
60 overrides: Partial<Parameters<typeof buildHomeThreadGroups>[0]> = {},
61) {
62 return buildHomeThreadGroups({
63 projects,
64 threads,
65 environmentId: null,
66 searchQuery: "",
67 projectSortOrder: "updated_at",
68 threadSortOrder: "updated_at",
69 projectGroupingMode: "repository",
70 now: NOW,
71 ...overrides,
72 });
73}
74
75describe("buildHomeThreadGroups", () => {
76 it("builds one v2 scope for the same repository across environments", () => {
77 const localEnvironmentId = EnvironmentId.make("environment-local");
78 const remoteEnvironmentId = EnvironmentId.make("environment-remote");
79 const repositoryIdentity = {
80 canonicalKey: "github.com/pingdotgg/t3code",
81 locator: {
82 source: "git-remote" as const,
83 remoteName: "origin",
84 remoteUrl: "git@github.com:pingdotgg/t3code.git",
85 },
86 };
87 const projects = [
88 makeProject({
89 environmentId: localEnvironmentId,
90 id: ProjectId.make("project-local"),
91 title: "t3code",
92 repositoryIdentity,
93 }),
94 makeProject({
95 environmentId: remoteEnvironmentId,
96 id: ProjectId.make("project-remote"),
97 title: "t3code",
98 repositoryIdentity,
99 }),
100 ];
101
102 const scopes = buildHomeProjectScopes({
103 projects,
104 environmentId: null,
105 projectGroupingMode: "repository",
106 });
107
108 expect(scopes).toHaveLength(1);
109 expect(scopes[0]?.title).toBe("t3code");
110 expect(scopes[0]?.projects).toEqual(projects);
111 expect(scopes[0]?.projectRefs).toEqual(
112 projects.map((project) => ({
113 environmentId: project.environmentId,
114 projectId: project.id,
115 })),
116 );
117 });
118
119 it("routes stale duplicate project refs through the canonical repository group", () => {
120 const localEnvironmentId = EnvironmentId.make("environment-local");
121 const remoteEnvironmentId = EnvironmentId.make("environment-remote");
122 const repositoryIdentity = {
123 canonicalKey: "github.com/pingdotgg/t3code",
124 locator: {
125 source: "git-remote" as const,
126 remoteName: "origin",
127 remoteUrl: "git@github.com:pingdotgg/t3code.git",
128 },
129 };
130 const local = makeProject({
131 id: ProjectId.make("project-local"),
132 environmentId: localEnvironmentId,
133 title: "t3code",
134 workspaceRoot: "/workspaces/t3code",
135 repositoryIdentity,
136 });
137 const stale = makeProject({
138 environmentId: remoteEnvironmentId,
139 id: ProjectId.make("project-stale"),
140 title: "t3code",
141 workspaceRoot: "/remote/t3code",
142 updatedAt: "2026-06-01T00:00:00.000Z",
143 });
144 const canonicalRemote = makeProject({
145 environmentId: remoteEnvironmentId,
146 id: ProjectId.make("project-canonical-remote"),
147 title: "t3code",
148 workspaceRoot: "/remote/t3code/",
149 repositoryIdentity,
150 updatedAt: "2026-06-02T00:00:00.000Z",
151 });
152 const projects = [local, stale, canonicalRemote];
153 const staleThread = makeThread({
154 environmentId: remoteEnvironmentId,
155 id: ThreadId.make("thread-stale-project-ref"),
156 projectId: stale.id,
157 title: "Still visible",
158 updatedAt: "2026-06-03T00:00:00.000Z",
159 });
160
161 const scopes = buildHomeProjectScopes({
162 projects,
163 environmentId: null,
164 projectGroupingMode: "repository",
165 });
166 const groups = buildGroups(projects, [staleThread]);
167
168 expect(scopes).toHaveLength(1);
169 expect(scopes[0]?.projects.map((project) => project.id)).toEqual([
170 local.id,
171 canonicalRemote.id,
172 ]);
173 expect(scopes[0]?.projectRefs.map((projectRef) => projectRef.projectId)).toEqual([
174 local.id,
175 stale.id,
176 canonicalRemote.id,
177 ]);
178 expect(groups).toHaveLength(1);
179 expect(groups[0]?.threads.map((thread) => thread.id)).toEqual([staleThread.id]);
180 expect(groups[0]?.newThreadTarget?.id).toBe(canonicalRemote.id);
181 });
182
183 it("keeps repository identity from an older duplicate when the freshness winner lacks it", () => {
184 const localEnvironmentId = EnvironmentId.make("environment-local");
185 const remoteEnvironmentId = EnvironmentId.make("environment-remote");
186 const repositoryIdentity = {
187 canonicalKey: "github.com/pingdotgg/t3code",
188 locator: {
189 source: "git-remote" as const,
190 remoteName: "origin",
191 remoteUrl: "git@github.com:pingdotgg/t3code.git",
192 },
193 };
194 const projects = [
195 makeProject({
196 environmentId: localEnvironmentId,
197 id: ProjectId.make("project-local"),
198 title: "t3code",
199 repositoryIdentity,
200 }),
201 makeProject({
202 environmentId: remoteEnvironmentId,
203 id: ProjectId.make("project-remote-with-identity"),
204 title: "t3code",
205 workspaceRoot: "/remote/t3code",
206 repositoryIdentity,
207 updatedAt: "2026-06-01T00:00:00.000Z",
208 }),
209 makeProject({
210 environmentId: remoteEnvironmentId,
211 id: ProjectId.make("project-remote-fresh"),
212 title: "t3code",
213 workspaceRoot: "/remote/t3code/",
214 updatedAt: "2026-06-02T00:00:00.000Z",
215 }),
216 ];
217
218 const scopes = buildHomeProjectScopes({
219 projects,
220 environmentId: null,
221 projectGroupingMode: "repository",
222 });
223
224 expect(scopes).toHaveLength(1);
225 expect(scopes[0]?.representative.id).toBe(ProjectId.make("project-local"));
226 expect(scopes[0]?.projects.map((project) => project.id)).toContain(
227 ProjectId.make("project-remote-fresh"),
228 );
229 expect(scopes[0]?.projectRefs).toHaveLength(3);
230 });
231
232 it("sorts v2 project scopes by their grouped thread activity", () => {
233 const environmentId = EnvironmentId.make("environment-1");
234 const olderProject = makeProject({
235 environmentId,
236 id: ProjectId.make("project-older"),
237 title: "Older project",
238 });
239 const newerProject = makeProject({
240 environmentId,
241 id: ProjectId.make("project-newer"),
242 title: "Newer project",
243 });
244 const scopes = buildHomeProjectScopes({
245 projects: [newerProject, olderProject],
246 environmentId: null,
247 projectGroupingMode: "separate",
248 });
249
250 expect(
251 sortHomeProjectScopes({
252 scopes,
253 threads: [
254 makeThread({
255 environmentId,
256 id: ThreadId.make("thread-older-project"),
257 projectId: olderProject.id,
258 title: "Most recently active",
259 updatedAt: "2026-06-03T00:00:00.000Z",
260 }),
261 makeThread({
262 environmentId,
263 id: ThreadId.make("thread-newer-project"),
264 projectId: newerProject.id,
265 title: "Less recently active",
266 updatedAt: "2026-06-02T00:00:00.000Z",
267 }),
268 ],
269 pendingTasks: [],
270 projectSortOrder: "updated_at",
271 }).map((scope) => scope.representative.id),
272 ).toEqual([olderProject.id, newerProject.id]);
273 });
274
275 it("sorts invalid project creation timestamps after valid ones", () => {
276 const environmentId = EnvironmentId.make("environment-1");
277 const invalidProject = makeProject({
278 environmentId,
279 id: ProjectId.make("project-invalid"),
280 title: "A invalid timestamp",
281 createdAt: "invalid",
282 });
283 const validProject = makeProject({
284 environmentId,
285 id: ProjectId.make("project-valid"),
286 title: "Z valid timestamp",
287 createdAt: "2026-06-02T00:00:00.000Z",
288 });
289 const scopes = buildHomeProjectScopes({
290 projects: [invalidProject, validProject],
291 environmentId: null,
292 projectGroupingMode: "separate",
293 });
294
295 expect(
296 sortHomeProjectScopes({
297 scopes,
298 threads: [],
299 pendingTasks: [],
300 projectSortOrder: "created_at",
301 }).map((scope) => scope.representative.id),
302 ).toEqual([validProject.id, invalidProject.id]);
303 });
304
305 it("uses the freshest member when a grouped scope has no activity", () => {
306 const localEnvironmentId = EnvironmentId.make("environment-local");
307 const remoteEnvironmentId = EnvironmentId.make("environment-remote");
308 const repositoryIdentity = {
309 canonicalKey: "github.com/pingdotgg/t3code",
310 locator: {
311 source: "git-remote" as const,
312 remoteName: "origin",
313 remoteUrl: "git@github.com:pingdotgg/t3code.git",
314 },
315 };
316 const olderMember = makeProject({
317 environmentId: localEnvironmentId,
318 id: ProjectId.make("project-older-member"),
319 title: "t3code",
320 updatedAt: "2026-06-01T00:00:00.000Z",
321 repositoryIdentity,
322 });
323 const newerMember = makeProject({
324 environmentId: remoteEnvironmentId,
325 id: ProjectId.make("project-newer-member"),
326 title: "t3code",
327 updatedAt: "2026-06-03T00:00:00.000Z",
328 repositoryIdentity,
329 });
330 const otherProject = makeProject({
331 environmentId: localEnvironmentId,
332 id: ProjectId.make("project-other"),
333 title: "other",
334 updatedAt: "2026-06-02T00:00:00.000Z",
335 });
336 const scopes = buildHomeProjectScopes({
337 projects: [olderMember, newerMember, otherProject],
338 environmentId: null,
339 projectGroupingMode: "repository",
340 });
341
342 expect(
343 sortHomeProjectScopes({
344 scopes,
345 threads: [],
346 pendingTasks: [],
347 projectSortOrder: "updated_at",
348 })[0]?.key,
349 ).toBe(scopes.find((scope) => scope.projects.length === 2)?.key);
350 });
351
352 it("does not merge unrelated repositories that share a title", () => {
353 const environmentId = EnvironmentId.make("environment-1");
354 const projects = ["one", "two"].map((name) =>
355 makeProject({
356 environmentId,
357 id: ProjectId.make(`project-${name}`),
358 title: "app",
359 repositoryIdentity: {
360 canonicalKey: `github.com/example/${name}`,
361 locator: {
362 source: "git-remote" as const,
363 remoteName: "origin",
364 remoteUrl: `git@github.com:example/${name}.git`,
365 },
366 },
367 }),
368 );
369
370 expect(
371 buildHomeProjectScopes({
372 projects,
373 environmentId: null,
374 projectGroupingMode: "repository",
375 }),
376 ).toHaveLength(2);
377 });
378
379 it("uses the physical project title for a singleton scope", () => {
380 const project = makeProject({
381 environmentId: EnvironmentId.make("environment-1"),
382 id: ProjectId.make("project-1"),
383 title: "local-worktree-name",
384 repositoryIdentity: {
385 canonicalKey: "github.com/pingdotgg/t3code",
386 displayName: "codething-mvp",
387 locator: {
388 source: "git-remote" as const,
389 remoteName: "origin",
390 remoteUrl: "git@github.com:pingdotgg/t3code.git",
391 },
392 },
393 });
394
395 const scopes = buildHomeProjectScopes({
396 projects: [project],
397 environmentId: null,
398 projectGroupingMode: "repository",
399 });
400 const groups = buildGroups(
401 [project],
402 [
403 makeThread({
404 environmentId: project.environmentId,
405 id: ThreadId.make("thread-1"),
406 projectId: project.id,
407 title: "Thread",
408 }),
409 ],
410 );
411
412 expect(scopes[0]?.title).toBe("local-worktree-name");
413 expect(groups[0]?.title).toBe("local-worktree-name");
414 });
415
416 it("sorts the newest thread first regardless of snapshot order", () => {
417 const environmentId = EnvironmentId.make("environment-1");
418 const project = makeProject({
419 environmentId,
420 id: ProjectId.make("project-1"),
421 title: "T3 Code",
422 });
423 const threads = [
424 makeThread({
425 environmentId,
426 id: ThreadId.make("thread-old"),
427 projectId: project.id,
428 title: "Older thread",
429 updatedAt: "2026-06-02T00:00:00.000Z",
430 }),
431 makeThread({
432 environmentId,
433 id: ThreadId.make("thread-new"),
434 projectId: project.id,
435 title: "Newer thread",
436 updatedAt: "2026-06-03T00:00:00.000Z",
437 }),
438 ];
439
440 expect(buildGroups([project], threads)[0]?.threads.map((thread) => thread.id)).toEqual([
441 "thread-new",
442 "thread-old",
443 ]);
444 });
445
446 it("supports independent project and thread creation-time sorting", () => {
447 const environmentId = EnvironmentId.make("environment-1");
448 const olderProject = makeProject({
449 environmentId,
450 id: ProjectId.make("project-older"),
451 title: "Older project",
452 });
453 const newerProject = makeProject({
454 environmentId,
455 id: ProjectId.make("project-newer"),
456 title: "Newer project",
457 });
458 const threads = [
459 makeThread({
460 environmentId,
461 id: ThreadId.make("old-created"),
462 projectId: olderProject.id,
463 title: "Updated recently",
464 createdAt: "2026-06-01T00:00:00.000Z",
465 updatedAt: "2026-06-05T00:00:00.000Z",
466 }),
467 makeThread({
468 environmentId,
469 id: ThreadId.make("new-created"),
470 projectId: olderProject.id,
471 title: "Created recently",
472 createdAt: "2026-06-04T00:00:00.000Z",
473 updatedAt: "2026-06-04T00:00:00.000Z",
474 }),
475 makeThread({
476 environmentId,
477 id: ThreadId.make("newest-project-thread"),
478 projectId: newerProject.id,
479 title: "Newest project",
480 createdAt: "2026-06-06T00:00:00.000Z",
481 }),
482 ];
483
484 const groups = buildGroups([olderProject, newerProject], threads, {
485 projectSortOrder: "created_at",
486 threadSortOrder: "created_at",
487 projectGroupingMode: "separate",
488 });
489
490 expect(groups.map((group) => group.representative.id)).toEqual([
491 "project-newer",
492 "project-older",
493 ]);
494 expect(groups[1]?.threads.map((thread) => thread.id)).toEqual(["new-created", "old-created"]);
495 });
496
497 it("filters both projects and threads to one environment", () => {
498 const localEnvironmentId = EnvironmentId.make("environment-local");
499 const remoteEnvironmentId = EnvironmentId.make("environment-remote");
500 const projects = [
501 makeProject({
502 environmentId: localEnvironmentId,
503 id: ProjectId.make("project-local"),
504 title: "Local",
505 }),
506 makeProject({
507 environmentId: remoteEnvironmentId,
508 id: ProjectId.make("project-remote"),
509 title: "Remote",
510 }),
511 ];
512 const threads = projects.map((project) =>
513 makeThread({
514 environmentId: project.environmentId,
515 id: ThreadId.make(`thread-${project.id}`),
516 projectId: project.id,
517 title: project.title,
518 }),
519 );
520
521 const groups = buildGroups(projects, threads, { environmentId: remoteEnvironmentId });
522
523 expect(groups).toHaveLength(1);
524 expect(groups[0]?.representative.environmentId).toBe(remoteEnvironmentId);
525 expect(groups[0]?.threads.map((thread) => thread.environmentId)).toEqual([remoteEnvironmentId]);
526 });
527
528 it("matches web repository, repository-path, and separate grouping modes", () => {
529 const environmentId = EnvironmentId.make("environment-1");
530 const repositoryIdentity = {
531 canonicalKey: "github.com/t3tools/t3code",
532 locator: {
533 source: "git-remote" as const,
534 remoteName: "origin",
535 remoteUrl: "git@github.com:t3tools/t3code.git",
536 },
537 provider: "github",
538 owner: "t3tools",
539 name: "t3code",
540 displayName: "T3 Code",
541 rootPath: "/workspaces/t3code",
542 };
543 const projects = [
544 makeProject({
545 environmentId,
546 id: ProjectId.make("project-web"),
547 title: "Web",
548 workspaceRoot: "/workspaces/t3code/apps/web",
549 repositoryIdentity,
550 }),
551 makeProject({
552 environmentId,
553 id: ProjectId.make("project-mobile"),
554 title: "Mobile",
555 workspaceRoot: "/workspaces/t3code/apps/mobile",
556 repositoryIdentity,
557 }),
558 ];
559 const threads = projects.map((project) =>
560 makeThread({
561 environmentId,
562 id: ThreadId.make(`thread-${project.id}`),
563 projectId: project.id,
564 title: project.title,
565 }),
566 );
567
568 expect(buildGroups(projects, threads, { projectGroupingMode: "repository" })).toHaveLength(1);
569 expect(
570 buildGroups(projects, threads, { projectGroupingMode: "repository_path" }).map(
571 (group) => group.title,
572 ),
573 ).toEqual(["Mobile", "Web"]);
574 expect(
575 buildGroups(projects, threads, { projectGroupingMode: "separate" }).map(
576 (group) => group.title,
577 ),
578 ).toEqual(["Mobile", "Web"]);
579 });
580
581 it("default view shows only threads from the last 5 days", () => {
582 const environmentId = EnvironmentId.make("environment-1");
583 const project = makeProject({
584 environmentId,
585 id: ProjectId.make("project-1"),
586 title: "T3 Code",
587 });
588 const threads = [
589 makeThread({
590 environmentId,
591 id: ThreadId.make("recent-1"),
592 projectId: project.id,
593 title: "Today",
594 updatedAt: "2026-06-28T00:00:00.000Z",
595 }),
596 makeThread({
597 environmentId,
598 id: ThreadId.make("recent-2"),
599 projectId: project.id,
600 title: "Within window",
601 updatedAt: "2026-06-25T00:00:00.000Z",
602 }),
603 makeThread({
604 environmentId,
605 id: ThreadId.make("old"),
606 projectId: project.id,
607 title: "Two weeks ago",
608 updatedAt: "2026-06-14T00:00:00.000Z",
609 }),
610 ];
611
612 const group = buildGroups([project], threads)[0];
613 // Default view trims to recent threads...
614 expect(group?.recentThreads.map((thread) => thread.id)).toEqual(["recent-1", "recent-2"]);
615 // ...while full history stays available for the expanded view.
616 expect(group?.threads.map((thread) => thread.id)).toEqual(["recent-1", "recent-2", "old"]);
617 });
618
619 it("keeps an old thread in the default view while a message waits in its outbox", () => {
620 const environmentId = EnvironmentId.make("environment-1");
621 const project = makeProject({
622 environmentId,
623 id: ProjectId.make("project-1"),
624 title: "T3 Code",
625 });
626 const threads = [
627 makeThread({
628 environmentId,
629 id: ThreadId.make("recent"),
630 projectId: project.id,
631 title: "Today",
632 updatedAt: "2026-06-28T00:00:00.000Z",
633 }),
634 makeThread({
635 environmentId,
636 id: ThreadId.make("old-queued"),
637 projectId: project.id,
638 title: "Two weeks ago, follow-up queued offline",
639 updatedAt: "2026-06-14T00:00:00.000Z",
640 }),
641 makeThread({
642 environmentId,
643 id: ThreadId.make("old"),
644 projectId: project.id,
645 title: "Two weeks ago",
646 updatedAt: "2026-06-13T00:00:00.000Z",
647 }),
648 ];
649
650 const group = buildGroups([project], threads, {
651 queuedThreadKeys: new Set([`${environmentId}:old-queued`]),
652 })[0];
653 expect(group?.recentThreads.map((thread) => thread.id)).toEqual(["recent", "old-queued"]);
654 });
655
656 it("falls back to the most recent 3 threads when none are within 5 days", () => {
657 const environmentId = EnvironmentId.make("environment-1");
658 const project = makeProject({
659 environmentId,
660 id: ProjectId.make("project-1"),
661 title: "T3 Code",
662 });
663 const threads = ["2026-06-01", "2026-06-02", "2026-06-03", "2026-06-04", "2026-06-05"].map(
664 (day, index) =>
665 makeThread({
666 environmentId,
667 id: ThreadId.make(`thread-${index}`),
668 projectId: project.id,
669 title: `Thread ${index}`,
670 updatedAt: `${day}T00:00:00.000Z`,
671 }),
672 );
673
674 const group = buildGroups([project], threads)[0];
675 expect(group?.recentThreads.map((thread) => thread.id)).toEqual([
676 "thread-4",
677 "thread-3",
678 "thread-2",
679 ]);
680 expect(group?.threads).toHaveLength(5);
681 });
682
683 it("does not apply the recency window while searching", () => {
684 const environmentId = EnvironmentId.make("environment-1");
685 const project = makeProject({
686 environmentId,
687 id: ProjectId.make("project-1"),
688 title: "T3 Code",
689 });
690 const threads = ["2026-06-01", "2026-06-02", "2026-06-03", "2026-06-04", "2026-06-05"].map(
691 (day, index) =>
692 makeThread({
693 environmentId,
694 id: ThreadId.make(`thread-${index}`),
695 projectId: project.id,
696 title: `Thread ${index}`,
697 updatedAt: `${day}T00:00:00.000Z`,
698 }),
699 );
700
701 const group = buildGroups([project], threads, { searchQuery: "T3 Code" })[0];
702 // Search reaches the full history rather than the 3-thread fallback.
703 expect(group?.recentThreads).toHaveLength(5);
704 expect(group?.recentThreads.map((thread) => thread.id)).toEqual(
705 group?.threads.map((thread) => thread.id),
706 );
707 });
708
709 it("includes a thread matched by message content", () => {
710 const environmentId = EnvironmentId.make("environment-1");
711 const project = makeProject({
712 environmentId,
713 id: ProjectId.make("project-1"),
714 title: "T3 Code",
715 });
716 const thread = makeThread({
717 environmentId,
718 id: ThreadId.make("thread-content"),
719 projectId: project.id,
720 title: "Unrelated title",
721 });
722
723 const groups = buildGroups([project], [thread], {
724 searchQuery: "relay reconnect",
725 matchedThreadKeys: new Set([
726 threadSearchMatchKey({
727 environmentId,
728 threadId: thread.id,
729 }),
730 ]),
731 });
732
733 expect(groups[0]?.threads.map((candidate) => candidate.id)).toEqual(["thread-content"]);
734 });
735
736 it("targets quick new threads at the group member with the newest thread", () => {
737 const laptopEnv = EnvironmentId.make("environment-laptop");
738 const desktopEnv = EnvironmentId.make("environment-desktop");
739 const repositoryIdentity = {
740 canonicalKey: "github.com/pingdotgg/t3code",
741 locator: {
742 source: "git-remote" as const,
743 remoteName: "origin",
744 remoteUrl: "git@github.com:pingdotgg/t3code.git",
745 },
746 };
747 const laptopProject = makeProject({
748 environmentId: laptopEnv,
749 id: ProjectId.make("project-laptop"),
750 title: "t3code",
751 repositoryIdentity,
752 });
753 const desktopProject = makeProject({
754 environmentId: desktopEnv,
755 id: ProjectId.make("project-desktop"),
756 title: "t3code",
757 repositoryIdentity,
758 });
759 const threads = [
760 makeThread({
761 environmentId: laptopEnv,
762 id: ThreadId.make("thread-laptop"),
763 projectId: laptopProject.id,
764 title: "Older laptop thread",
765 updatedAt: "2026-06-27T00:00:00.000Z",
766 }),
767 makeThread({
768 environmentId: desktopEnv,
769 id: ThreadId.make("thread-desktop"),
770 projectId: desktopProject.id,
771 title: "Newest desktop thread",
772 updatedAt: "2026-06-28T00:00:00.000Z",
773 }),
774 ];
775
776 // Aggregated into one group by repository; the quick new-thread target
777 // must follow the newest thread (desktop), not the arbitrary first member.
778 const groups = buildGroups([laptopProject, desktopProject], threads);
779 expect(groups).toHaveLength(1);
780 expect(groups[0]?.projects).toHaveLength(2);
781 expect(groups[0]?.newThreadTarget?.environmentId).toBe(desktopEnv);
782 expect(groups[0]?.newThreadTarget?.id).toBe(desktopProject.id);
783 });
784});