@@ -9,6 +9,14 @@ const state = vi.hoisted(() => ({
99 projection : null as unknown ,
1010 commandSucceeds : false ,
1111 relatedShells : [ ] as unknown [ ] ,
12+ threadTitles : { } as Record < string , string > ,
13+ titleLookup : { isSuccess : true , isPending : false } ,
14+ archivedThreads : [ ] as unknown [ ] ,
15+ } ) ) ;
16+
17+ vi . mock ( import ( "../../state/query" ) , async ( original ) => ( {
18+ ...( await original ( ) ) ,
19+ useEnvironmentQuery : ( ( ) => ( { data : state . threadTitles , ...state . titleLookup } ) ) as never ,
1220} ) ) ;
1321
1422vi . mock ( import ( "@effect/atom-react" ) , async ( original ) => ( {
@@ -31,7 +39,9 @@ vi.mock(import("../../state/environments"), () => ({
3139 useEnvironmentProviders : ( ( ) => new Map ( ) ) as never ,
3240} ) ) ;
3341vi . mock ( import ( "../../lib/archivedThreadsState" ) , ( ) => ( {
34- useArchivedThreadSnapshots : ( ( ) => ( { snapshots : [ ] } ) ) as never ,
42+ useArchivedThreadSnapshots : ( ( ) => ( {
43+ snapshots : [ { environmentId : "environment" , snapshot : { threads : state . archivedThreads } } ] ,
44+ } ) ) as never ,
3545} ) ) ;
3646vi . mock ( import ( "../../state/use-atom-command" ) , ( ) => ( {
3747 useAtomCommand : ( ( ) => async ( ) =>
@@ -51,6 +61,9 @@ const threadId = ThreadId.make("fork");
5161function setup ( ) {
5262 state . commandSucceeds = false ;
5363 state . relatedShells = [ ] ;
64+ state . threadTitles = { source : "Source" } ;
65+ state . titleLookup = { isSuccess : true , isPending : false } ;
66+ state . archivedThreads = [ ] ;
5467 state . projection = {
5568 thread : {
5669 id : threadId ,
@@ -343,3 +356,99 @@ it("shows a delegated-from thread's full title in its tooltip even when its envi
343356 await row . click ( { force : true } ) ;
344357 expect ( screen . router ?. state . location . pathname ) . toBe ( "/environment/fork" ) ;
345358} ) ;
359+
360+ it . each ( [
361+ {
362+ name : "an omitted existing fork" ,
363+ exists : true ,
364+ success : true ,
365+ pending : false ,
366+ archived : false ,
367+ visible : true ,
368+ } ,
369+ {
370+ name : "a deleted fork" ,
371+ exists : false ,
372+ success : true ,
373+ pending : false ,
374+ archived : false ,
375+ visible : false ,
376+ } ,
377+ {
378+ name : "an existing archived fork with a stale title" ,
379+ exists : true ,
380+ success : true ,
381+ pending : false ,
382+ archived : true ,
383+ visible : true ,
384+ } ,
385+ {
386+ name : "a deleted fork in a stale archived snapshot" ,
387+ exists : false ,
388+ success : true ,
389+ pending : false ,
390+ archived : true ,
391+ visible : false ,
392+ } ,
393+ {
394+ name : "an unresolved fork" ,
395+ exists : false ,
396+ success : true ,
397+ pending : true ,
398+ archived : false ,
399+ visible : true ,
400+ } ,
401+ {
402+ name : "a fork after lookup failure" ,
403+ exists : false ,
404+ success : false ,
405+ pending : false ,
406+ archived : false ,
407+ visible : true ,
408+ } ,
409+ ] ) (
410+ "keeps or hides $name after checking its existence" ,
411+ async ( { exists, success, pending, archived, visible } ) => {
412+ setup ( ) ;
413+ const projection = makeThreadProjectionFixture ( ) ;
414+ const deletedId = ThreadId . make ( "deleted-fork" ) ;
415+ const title = "Example fork" ;
416+ state . threadTitles = exists ? { [ deletedId ] : title } : { } ;
417+ state . titleLookup = { isSuccess : success , isPending : pending } ;
418+ if ( archived )
419+ state . archivedThreads = [
420+ {
421+ ...projection . thread ,
422+ id : deletedId ,
423+ title : "Old archived title" ,
424+ archivedAt : projection . thread . updatedAt ,
425+ lineage : { parentThreadId : projection . thread . id , relationshipToParent : "fork" } ,
426+ } ,
427+ ] ;
428+ state . projection = {
429+ ...projection ,
430+ contextTransfers : [
431+ {
432+ sourceThreadId : projection . thread . id ,
433+ targetThreadId : deletedId ,
434+ status : "pending" ,
435+ } ,
436+ ] ,
437+ } ;
438+ await using screen = await render (
439+ < ThreadRelationshipsPanel
440+ environmentId = { environmentId }
441+ threadId = { projection . thread . id }
442+ showLineage
443+ showSideChats
444+ /> ,
445+ ) ;
446+ if ( visible ) {
447+ await expect
448+ . element ( screen . getByText ( exists || archived ? title : deletedId , { exact : true } ) )
449+ . toBeVisible ( ) ;
450+ } else {
451+ await expect . element ( screen . getByRole ( "region" , { name : "Lineage" } ) ) . not . toBeInTheDocument ( ) ;
452+ }
453+ } ,
454+ ) ;
0 commit comments