@@ -2,9 +2,17 @@ import type {
22 EnvironmentProject ,
33 EnvironmentThreadShell ,
44} from "@t3tools/client-runtime/state/shell" ;
5- import { EnvironmentId , ProjectId , ProviderInstanceId , ThreadId } from "@t3tools/contracts" ;
5+ import {
6+ CommandId ,
7+ EnvironmentId ,
8+ MessageId ,
9+ ProjectId ,
10+ ProviderInstanceId ,
11+ ThreadId ,
12+ } from "@t3tools/contracts" ;
613import { describe , expect , it } from "vite-plus/test" ;
714
15+ import type { PendingNewTask } from "../../state/use-pending-new-tasks" ;
816import { buildHomeThreadGroups } from "./homeThreadList" ;
917
1018function makeProject (
@@ -44,6 +52,33 @@ function makeThread(
4452 } ;
4553}
4654
55+ function makePendingTask (
56+ input : Pick < EnvironmentProject , "environmentId" | "id" | "title" | "workspaceRoot" > ,
57+ ) : PendingNewTask {
58+ return {
59+ title : input . title ,
60+ message : {
61+ environmentId : input . environmentId ,
62+ threadId : ThreadId . make ( `pending-thread-${ input . id } ` ) ,
63+ messageId : MessageId . make ( `pending-message-${ input . id } ` ) ,
64+ commandId : CommandId . make ( `pending-command-${ input . id } ` ) ,
65+ text : input . title ,
66+ attachments : [ ] ,
67+ createdAt : "2026-06-29T00:00:00.000Z" ,
68+ } ,
69+ creation : {
70+ projectId : input . id ,
71+ projectTitle : input . title ,
72+ projectCwd : input . workspaceRoot ,
73+ workspaceMode : "local" ,
74+ branch : null ,
75+ worktreePath : null ,
76+ } ,
77+ } ;
78+ }
79+
80+ const NOW = Date . parse ( "2026-06-29T00:00:00.000Z" ) ;
81+
4782function buildGroups (
4883 projects : ReadonlyArray < EnvironmentProject > ,
4984 threads : ReadonlyArray < EnvironmentThreadShell > ,
@@ -57,6 +92,7 @@ function buildGroups(
5792 projectSortOrder : "updated_at" ,
5893 threadSortOrder : "updated_at" ,
5994 projectGroupingMode : "repository" ,
95+ now : NOW ,
6096 ...overrides ,
6197 } ) ;
6298}
@@ -220,4 +256,141 @@ describe("buildHomeThreadGroups", () => {
220256 ) ;
221257 expect ( buildGroups ( projects , threads , { projectGroupingMode : "separate" } ) ) . toHaveLength ( 2 ) ;
222258 } ) ;
259+
260+ it ( "default view shows only threads from the last 5 days" , ( ) => {
261+ const environmentId = EnvironmentId . make ( "environment-1" ) ;
262+ const project = makeProject ( {
263+ environmentId,
264+ id : ProjectId . make ( "project-1" ) ,
265+ title : "T3 Code" ,
266+ } ) ;
267+ const threads = [
268+ makeThread ( {
269+ environmentId,
270+ id : ThreadId . make ( "recent-1" ) ,
271+ projectId : project . id ,
272+ title : "Today" ,
273+ updatedAt : "2026-06-28T00:00:00.000Z" ,
274+ } ) ,
275+ makeThread ( {
276+ environmentId,
277+ id : ThreadId . make ( "recent-2" ) ,
278+ projectId : project . id ,
279+ title : "Within window" ,
280+ updatedAt : "2026-06-25T00:00:00.000Z" ,
281+ } ) ,
282+ makeThread ( {
283+ environmentId,
284+ id : ThreadId . make ( "old" ) ,
285+ projectId : project . id ,
286+ title : "Two weeks ago" ,
287+ updatedAt : "2026-06-14T00:00:00.000Z" ,
288+ } ) ,
289+ ] ;
290+
291+ const group = buildGroups ( [ project ] , threads ) [ 0 ] ;
292+ // Default view trims to recent threads...
293+ expect ( group ?. recentThreads . map ( ( thread ) => thread . id ) ) . toEqual ( [ "recent-1" , "recent-2" ] ) ;
294+ // ...while full history stays available for the expanded view.
295+ expect ( group ?. threads . map ( ( thread ) => thread . id ) ) . toEqual ( [ "recent-1" , "recent-2" , "old" ] ) ;
296+ } ) ;
297+
298+ it ( "falls back to the most recent 3 threads when none are within 5 days" , ( ) => {
299+ const environmentId = EnvironmentId . make ( "environment-1" ) ;
300+ const project = makeProject ( {
301+ environmentId,
302+ id : ProjectId . make ( "project-1" ) ,
303+ title : "T3 Code" ,
304+ } ) ;
305+ const threads = [ "2026-06-01" , "2026-06-02" , "2026-06-03" , "2026-06-04" , "2026-06-05" ] . map (
306+ ( day , index ) =>
307+ makeThread ( {
308+ environmentId,
309+ id : ThreadId . make ( `thread-${ index } ` ) ,
310+ projectId : project . id ,
311+ title : `Thread ${ index } ` ,
312+ updatedAt : `${ day } T00:00:00.000Z` ,
313+ } ) ,
314+ ) ;
315+
316+ const group = buildGroups ( [ project ] , threads ) [ 0 ] ;
317+ expect ( group ?. recentThreads . map ( ( thread ) => thread . id ) ) . toEqual ( [
318+ "thread-4" ,
319+ "thread-3" ,
320+ "thread-2" ,
321+ ] ) ;
322+ expect ( group ?. threads ) . toHaveLength ( 5 ) ;
323+ } ) ;
324+
325+ it ( "includes a thread exactly at the 5-day cutoff" , ( ) => {
326+ const environmentId = EnvironmentId . make ( "environment-1" ) ;
327+ const project = makeProject ( {
328+ environmentId,
329+ id : ProjectId . make ( "project-1" ) ,
330+ title : "T3 Code" ,
331+ } ) ;
332+ const exactlyAtCutoff = new Date ( NOW - 5 * 24 * 60 * 60 * 1000 ) . toISOString ( ) ;
333+ const justPastCutoff = new Date ( NOW - 5 * 24 * 60 * 60 * 1000 - 1 ) . toISOString ( ) ;
334+ const threads = [
335+ makeThread ( {
336+ environmentId,
337+ id : ThreadId . make ( "at-cutoff" ) ,
338+ projectId : project . id ,
339+ title : "At cutoff" ,
340+ updatedAt : exactlyAtCutoff ,
341+ } ) ,
342+ makeThread ( {
343+ environmentId,
344+ id : ThreadId . make ( "past-cutoff" ) ,
345+ projectId : project . id ,
346+ title : "Past cutoff" ,
347+ updatedAt : justPastCutoff ,
348+ } ) ,
349+ ] ;
350+
351+ const group = buildGroups ( [ project ] , threads ) [ 0 ] ;
352+ expect ( group ?. recentThreads . map ( ( thread ) => thread . id ) ) . toEqual ( [ "at-cutoff" ] ) ;
353+ } ) ;
354+
355+ it ( "returns an empty recentThreads list for a group with no threads" , ( ) => {
356+ const environmentId = EnvironmentId . make ( "environment-1" ) ;
357+ const project = makeProject ( {
358+ environmentId,
359+ id : ProjectId . make ( "project-1" ) ,
360+ title : "T3 Code" ,
361+ } ) ;
362+
363+ const group = buildGroups ( [ project ] , [ ] , {
364+ pendingTasks : [ makePendingTask ( project ) ] ,
365+ } ) [ 0 ] ;
366+
367+ expect ( group ?. threads ) . toEqual ( [ ] ) ;
368+ expect ( group ?. recentThreads ) . toEqual ( [ ] ) ;
369+ } ) ;
370+
371+ it ( "does not apply the recency window while searching" , ( ) => {
372+ const environmentId = EnvironmentId . make ( "environment-1" ) ;
373+ const project = makeProject ( {
374+ environmentId,
375+ id : ProjectId . make ( "project-1" ) ,
376+ title : "T3 Code" ,
377+ } ) ;
378+ const threads = [ "2026-06-01" , "2026-06-02" , "2026-06-03" , "2026-06-04" , "2026-06-05" ] . map (
379+ ( day , index ) =>
380+ makeThread ( {
381+ environmentId,
382+ id : ThreadId . make ( `thread-${ index } ` ) ,
383+ projectId : project . id ,
384+ title : `Thread ${ index } ` ,
385+ updatedAt : `${ day } T00:00:00.000Z` ,
386+ } ) ,
387+ ) ;
388+
389+ const group = buildGroups ( [ project ] , threads , { searchQuery : "T3 Code" } ) [ 0 ] ;
390+ // Search reaches the full history rather than the 3-thread fallback.
391+ expect ( group ?. recentThreads ) . toHaveLength ( 5 ) ;
392+ expect ( group ?. recentThreads . map ( ( thread ) => thread . id ) ) . toEqual (
393+ group ?. threads . map ( ( thread ) => thread . id ) ,
394+ ) ;
395+ } ) ;
223396} ) ;
0 commit comments