@@ -1186,6 +1186,21 @@ test.each([
11861186 }
11871187} )
11881188
1189+ test ( "adds running sessions created while disconnected to their family" , async ( ) => {
1190+ const root = { ...session ( 0 ) , id : "ses_root" }
1191+ const child = { ...session ( 0 ) , id : "ses_child" , parentID : "ses_root" }
1192+ const setup = activityFixture ( ( ) => Response . json ( { data : { ses_child : { type : "running" } } } ) , [ child ] )
1193+
1194+ try {
1195+ setup . data . session . remember ( root )
1196+ setup . emit ( { type : "server.connected" , data : { } } )
1197+ await wait ( ( ) => setup . data . session . family ( "ses_root" ) . includes ( "ses_child" ) )
1198+ expect ( setup . data . session . status ( "ses_child" ) ) . toBe ( "running" )
1199+ } finally {
1200+ setup . dispose ( )
1201+ }
1202+ } )
1203+
11891204test ( "ignores activity snapshots from an older connection" , async ( ) => {
11901205 const reads : ReturnType < typeof Promise . withResolvers < Response > > [ ] = [ ]
11911206 const setup = activityFixture ( ( ) => {
@@ -1257,14 +1272,16 @@ function modelInfo(name: string): ModelInfo {
12571272 }
12581273}
12591274
1260- function activityFixture ( read : ( ) => Response | Promise < Response > ) {
1275+ function activityFixture ( read : ( ) => Response | Promise < Response > , sessions : SessionInfo [ ] = [ ] ) {
12611276 const listeners = new Set < Parameters < CreateDataInput [ "event" ] [ "listen" ] > [ 0 ] > ( )
12621277 const api = OpenCode . make ( {
12631278 baseUrl : "http://opencode.local" ,
12641279 fetch : async ( input , init ) => {
12651280 const request = input instanceof Request ? input : new Request ( input , init )
12661281 const path = new URL ( request . url ) . pathname
12671282 if ( path === "/api/session/active" ) return read ( )
1283+ const known = sessions . find ( ( item ) => path === `/api/session/${ item . id } ` )
1284+ if ( known ) return Response . json ( { data : known } )
12681285 if ( path === "/api/project" ) return Response . json ( [ ] )
12691286 if ( path === "/api/location" ) return Response . json ( { directory : "/project" } )
12701287 return Response . json ( { location : { directory : "/project" } , data : { branch : "main" } } )
0 commit comments