@@ -12,6 +12,7 @@ import { RouteProvider, useRoute } from "../../../src/context/route"
1212import { ThemeProvider } from "../../../src/context/theme"
1313import { DialogProvider } from "../../../src/ui/dialog"
1414import { ToastProvider , useToast } from "../../../src/ui/toast"
15+ import { SessionLocationMissing } from "../../../src/routes/session/location-missing"
1516import { emptyThemeSource } from "../../fixture/fixture"
1617import { createApi , createEventStream , createFetch , json } from "../../fixture/tui-client"
1718import { TestTuiContexts } from "../../fixture/tui-environment"
@@ -175,6 +176,68 @@ test.each([false, true])("Ctrl+M moves only an existing session (home=%s)", asyn
175176 }
176177} )
177178
179+ test ( "choosing a directory recovers the session when its location is unavailable" , async ( ) => {
180+ const fixture = await renderMove ( { directory : clone , unavailable : "location" , showMissingLocation : true } )
181+ try {
182+ await fixture . app . waitForFrame ( ( frame ) => frame . includes ( "Session location unavailable" ) )
183+ fixture . app . mockInput . pressEnter ( )
184+ await fixture . app . waitForFrame ( ( frame ) => frame . includes ( "Worktrees" ) && frame . includes ( linked ) )
185+ await fixture . app . waitFor ( ( ) => fixture . app . renderer . currentFocusedEditor instanceof InputRenderable )
186+ await fixture . app . mockInput . typeText ( "linked" )
187+ await fixture . app . waitForFrame ( ( frame ) => frame . includes ( linked ) && ! frame . includes ( main ) )
188+ fixture . app . mockInput . pressEnter ( )
189+ await fixture . app . waitFor ( ( ) => fixture . moves . length === 1 )
190+
191+ expect ( fixture . moves ) . toEqual ( [ { directory : linked } ] )
192+ expect ( fixture . route . data ) . toEqual ( { type : "session" , sessionID : "ses_clone" } )
193+ expect ( fixture . requests ) . toEqual ( [ ] )
194+ } finally {
195+ fixture . app . renderer . destroy ( )
196+ }
197+ } )
198+
199+ test ( "creating a worktree recovers the session without reading its removed location" , async ( ) => {
200+ const fixture = await renderMove ( { directory : clone , unavailable : "location" , showMissingLocation : true } )
201+ try {
202+ await fixture . app . waitForFrame ( ( frame ) => frame . includes ( "Session location unavailable" ) )
203+ fixture . app . mockInput . pressEnter ( )
204+ await fixture . app . waitForFrame ( ( frame ) => frame . includes ( "Worktrees" ) && frame . includes ( linked ) )
205+ fixture . app . mockInput . pressKey ( "a" , { ctrl : true } )
206+ await fixture . app . waitForFrame ( ( frame ) => frame . includes ( "Name worktree" ) )
207+ await fixture . app . waitFor ( ( ) => fixture . app . renderer . currentFocusedEditor instanceof InputRenderable )
208+ await fixture . app . mockInput . typeText ( "fresh" )
209+ fixture . app . mockInput . pressEnter ( )
210+ await fixture . app . waitFor ( ( ) => fixture . moves . length === 1 )
211+
212+ expect ( fixture . requests ) . toEqual ( [ { payload : { projectID : "proj_test" , name : "fresh" } , directory : null } ] )
213+ expect ( fixture . moves ) . toEqual ( [ { directory : created } ] )
214+ expect ( fixture . route . data ) . toEqual ( { type : "session" , sessionID : "ses_clone" } )
215+ expect ( fixture . reads . locations ) . not . toContain ( clone )
216+ } finally {
217+ fixture . app . renderer . destroy ( )
218+ }
219+ } )
220+
221+ test ( "failed recovery does not navigate away from the session" , async ( ) => {
222+ const fixture = await renderMove ( { directory : clone , unavailable : "location" , showMissingLocation : true , moveFails : true } )
223+ try {
224+ await fixture . app . waitForFrame ( ( frame ) => frame . includes ( "Session location unavailable" ) )
225+ fixture . app . mockInput . pressEnter ( )
226+ await fixture . app . waitForFrame ( ( frame ) => frame . includes ( "Worktrees" ) && frame . includes ( linked ) )
227+ await fixture . app . waitFor ( ( ) => fixture . app . renderer . currentFocusedEditor instanceof InputRenderable )
228+ await fixture . app . mockInput . typeText ( "linked" )
229+ await fixture . app . waitForFrame ( ( frame ) => frame . includes ( linked ) && ! frame . includes ( main ) )
230+ fixture . app . mockInput . pressEnter ( )
231+ await fixture . app . waitFor ( ( ) => fixture . toast . currentToast !== null )
232+
233+ expect ( fixture . moves ) . toEqual ( [ { directory : linked } ] )
234+ expect ( fixture . route . data ) . toEqual ( { type : "session" , sessionID : "ses_clone" } )
235+ expect ( fixture . toast . currentToast ) . toMatchObject ( { title : "Failed to move session" , variant : "error" } )
236+ } finally {
237+ fixture . app . renderer . destroy ( )
238+ }
239+ } )
240+
178241test . each ( [
179242 { name : "session" , unavailable : "session" as const } ,
180243 { name : "location" , unavailable : "location" as const } ,
@@ -223,6 +286,8 @@ async function renderMove(input: {
223286 launch ?: string
224287 launchProjectID ?: string
225288 unavailable ?: "session" | "location"
289+ showMissingLocation ?: boolean
290+ moveFails ?: boolean
226291} ) {
227292 const launch = input . launch ?? ( input . home ? input . directory : main )
228293 const requests : unknown [ ] = [ ]
@@ -294,6 +359,7 @@ async function renderMove(input: {
294359 }
295360 if ( url . pathname === "/api/session/ses_clone/move" ) {
296361 moves . push ( await request . json ( ) )
362+ if ( input . moveFails ) return json ( { message : "Destination unavailable" } , { status : 503 } )
297363 return new Response ( null , { status : 204 } )
298364 }
299365 return undefined
@@ -313,7 +379,9 @@ async function renderMove(input: {
313379 projectID : ( ) => ( input . home ? data . location . info ( ) ?. project . id : "proj_test" ) ,
314380 sessionID : ( ) => ( input . home ? undefined : "ses_clone" ) ,
315381 } )
316- return null
382+ return input . showMissingLocation ? (
383+ < SessionLocationMissing directory = { input . directory } projectID = "proj_test" sessionID = "ses_clone" />
384+ ) : null
317385 }
318386
319387 const app = await testRender (
0 commit comments