@@ -286,12 +286,35 @@ func TestMultiWorkspaceRuntime_NoHashConfigured(t *testing.T) {
286286
287287 if _ , err := mw .ListSessions (context .Background ()); err == nil {
288288 t .Fatalf ("expected error when no hash is configured" )
289+ } else if ! errors .Is (err , ErrRuntimeResourceNotFound ) {
290+ t .Fatalf ("expected ErrRuntimeResourceNotFound, got %v" , err )
289291 }
290292 if got := builder .callCount (); got != 0 {
291293 t .Fatalf ("buildPort should not be called when no hash, got %d" , got )
292294 }
293295}
294296
297+ func TestMultiWorkspaceRuntime_NoHashUsesPreloadedAnonymousBundle (t * testing.T ) {
298+ idx := agentsession .NewWorkspaceIndex (t .TempDir ())
299+ builder := newTestBuilder ()
300+
301+ mw := NewMultiWorkspaceRuntime (idx , "" , builder .build )
302+ t .Cleanup (func () { _ = mw .Close () })
303+
304+ preloaded := newRecordingPort ("anonymous-default" )
305+ mw .PreloadWorkspaceBundle ("" , preloaded , preloaded .cleanup )
306+
307+ if _ , err := mw .ListSessions (context .Background ()); err != nil {
308+ t .Fatalf ("ListSessions with anonymous preloaded bundle: %v" , err )
309+ }
310+ if got := preloaded .listSessionsCalls .Load (); got != 1 {
311+ t .Fatalf ("anonymous preloaded listSessions calls = %d, want 1" , got )
312+ }
313+ if got := builder .callCount (); got != 0 {
314+ t .Fatalf ("buildPort should not be called when anonymous preloaded bundle exists; got %d" , got )
315+ }
316+ }
317+
295318func TestMultiWorkspaceRuntime_ContextHashOverridesDefault (t * testing.T ) {
296319 idx , alpha , beta := setupIndex (t )
297320 builder := newTestBuilder ()
@@ -356,6 +379,8 @@ func TestMultiWorkspaceRuntime_UnknownHashErrors(t *testing.T) {
356379 _ , err := mw .ListSessions (ctxWithHash (t , "deadbeef" ))
357380 if err == nil {
358381 t .Fatalf ("expected error for unknown hash" )
382+ } else if ! errors .Is (err , ErrRuntimeResourceNotFound ) {
383+ t .Fatalf ("expected ErrRuntimeResourceNotFound, got %v" , err )
359384 }
360385 if got := builder .callCount (); got != 0 {
361386 t .Fatalf ("buildPort should not be invoked for unknown hash; got %d" , got )
@@ -510,6 +535,27 @@ func TestMultiWorkspaceRuntime_RenameAndDeletePersist(t *testing.T) {
510535 }
511536}
512537
538+ func TestMultiWorkspaceRuntime_DeleteDefaultHashFallsBackToRemainingWorkspace (t * testing.T ) {
539+ idx , alpha , beta := setupIndex (t )
540+ builder := newTestBuilder ()
541+ mw := NewMultiWorkspaceRuntime (idx , alpha .Hash , builder .build )
542+ t .Cleanup (func () { _ = mw .Close () })
543+
544+ if err := mw .DeleteWorkspace (alpha .Hash , false ); err != nil {
545+ t .Fatalf ("Delete default workspace: %v" , err )
546+ }
547+
548+ if _ , err := mw .ListSessions (context .Background ()); err != nil {
549+ t .Fatalf ("ListSessions fallback after deleting default: %v" , err )
550+ }
551+ if builder .portFor (alpha .Path ) != nil {
552+ t .Fatalf ("alpha port should not be rebuilt after delete" )
553+ }
554+ if builder .portFor (beta .Path ) == nil {
555+ t .Fatalf ("expected fallback to remaining workspace beta" )
556+ }
557+ }
558+
513559func TestMultiWorkspaceRuntime_DeleteUnknownErrors (t * testing.T ) {
514560 idx , alpha , _ := setupIndex (t )
515561 builder := newTestBuilder ()
0 commit comments