@@ -65,10 +65,21 @@ const row = (id: string, title: string) =>
6565 ( { id : ThreadId . make ( id ) , title } ) as OrchestrationV2ThreadShell ;
6666
6767function setup ( shells : ReadonlyMap < string , OrchestrationV2ThreadShell > = new Map ( ) ) {
68- appAtomRegistry . set ( mocks . shells , shells ) ;
68+ const baseShells = new Map ( shells ) ;
69+ appAtomRegistry . set ( mocks . shells , baseShells ) ;
6970 const mounted = new Map < string , OrchestrationV2ThreadFamily > ( ) ;
7071 const counts = new Map < string , number > ( ) ;
7172 const requested = new Set < string > ( ) ;
73+ const publish = ( ) => {
74+ const rows = new Map ( baseShells ) ;
75+ for ( const [ familyKey , family ] of mounted ) {
76+ const [ environmentId ] = JSON . parse ( familyKey ) as [ EnvironmentId , ThreadId ] ;
77+ for ( const thread of family . threads ) {
78+ rows . set ( key ( { environmentId, threadId : thread . id } ) , thread ) ;
79+ }
80+ }
81+ appAtomRegistry . set ( mocks . shells , rows ) ;
82+ } ;
7283 const queries = vi
7384 . spyOn ( threadFamilies , "familyAtom" )
7485 . mockImplementation ( ( environmentId , threadId ) => {
@@ -85,16 +96,6 @@ function setup(shells: ReadonlyMap<string, OrchestrationV2ThreadShell> = new Map
8596 const id = key ( { environmentId, threadId } ) ;
8697 const query = threadFamilies . familyAtom ( environmentId , threadId ) ;
8798 counts . set ( id , ( counts . get ( id ) ?? 0 ) + 1 ) ;
88- const publish = ( ) => {
89- const rows = new Map ( shells ) ;
90- for ( const [ familyKey , family ] of mounted ) {
91- const [ environmentId ] = JSON . parse ( familyKey ) as [ EnvironmentId , ThreadId ] ;
92- for ( const thread of family . threads ) {
93- rows . set ( key ( { environmentId, threadId : thread . id } ) , thread ) ;
94- }
95- }
96- registry . set ( mocks . shells , rows ) ;
97- } ;
9899 const unsubscribe = registry . subscribe (
99100 query ,
100101 ( result ) => {
@@ -114,6 +115,12 @@ function setup(shells: ReadonlyMap<string, OrchestrationV2ThreadShell> = new Map
114115 } ) ;
115116 return {
116117 requested,
118+ setShell : ( target : ScopedThreadRef , thread : OrchestrationV2ThreadShell | null ) =>
119+ act ( ( ) => {
120+ if ( thread === null ) baseShells . delete ( key ( target ) ) ;
121+ else baseShells . set ( key ( target ) , thread ) ;
122+ publish ( ) ;
123+ } ) ,
117124 fail : ( target : ScopedThreadRef , waiting = false ) =>
118125 act ( ( ) =>
119126 appAtomRegistry . set (
@@ -211,6 +218,29 @@ describe("thread link family lookups", () => {
211218 await expect
212219 . element ( screen . getByRole ( "link" , { name : "Thread, Remote thread" } ) )
213220 . toBeInTheDocument ( ) ;
221+ expect ( fixture . requested . has ( key ( remote ) ) ) . toBe ( false ) ;
222+ await fixture . setShell ( remote , null ) ;
223+ expect ( fixture . requested . has ( key ( remote ) ) ) . toBe ( true ) ;
224+ await fixture . resolve ( remote , [ row ( remote . threadId , "Remote thread reloaded" ) ] ) ;
225+ await expect
226+ . element ( screen . getByRole ( "link" , { name : "Thread, Remote thread reloaded" } ) )
227+ . toBeInTheDocument ( ) ;
228+ const duplicate = ref ( remote . threadId , EnvironmentId . make ( "another-remote-environment" ) ) ;
229+ await fixture . setShell ( duplicate , row ( duplicate . threadId , "Ambiguous remote thread" ) ) ;
230+ await expect
231+ . element ( screen . getByRole ( "link" , { name : "Thread, Remote thread reloaded" } ) )
232+ . not . toBeInTheDocument ( ) ;
233+ await fixture . setShell ( duplicate , null ) ;
234+ await expect
235+ . element ( screen . getByRole ( "link" , { name : "Thread, Remote thread reloaded" } ) )
236+ . toBeInTheDocument ( ) ;
237+ const next = ref ( "different-thread" ) ;
238+ await screen . rerender ( view ( next , "markdown" , true ) ) ;
239+ await fixture . fail ( next ) ;
240+ await expect
241+ . element ( screen . getByRole ( "link" , { name : "Thread, Remote thread reloaded" } ) )
242+ . not . toBeInTheDocument ( ) ;
243+ expect ( appAtomRegistry . get ( mocks . shells ) . has ( key ( remote ) ) ) . toBe ( false ) ;
214244 } ,
215245 ) ;
216246
0 commit comments