@@ -384,6 +384,71 @@ test("getShellEnv does not inject MEMORY_DIR aliases when memfs is disabled", ()
384384 } ) ;
385385} ) ;
386386
387+ test ( "getShellEnv honors an explicit MEMORY_DIR scope outside the memory store" , ( ) => {
388+ withTemporaryAgentEnv ( `agent-test-${ Date . now ( ) } ` , ( ) => {
389+ withTemporaryEnv (
390+ {
391+ MEMORY_DIR : "/tmp/dream-batch-clone/output" ,
392+ LETTA_MEMORY_DIR : "/tmp/dream-batch-clone/output" ,
393+ LETTA_MEMORY_DIR_EXPLICIT : "1" ,
394+ } ,
395+ ( ) => {
396+ const originalIsMemfsEnabled =
397+ settingsManager . isMemfsEnabled . bind ( settingsManager ) ;
398+ (
399+ settingsManager as unknown as {
400+ isMemfsEnabled : ( id : string ) => boolean ;
401+ }
402+ ) . isMemfsEnabled = ( ) => false ;
403+ try {
404+ const env = getShellEnv ( ) ;
405+ expect ( env . MEMORY_DIR ) . toBe ( "/tmp/dream-batch-clone/output" ) ;
406+ expect ( env . LETTA_MEMORY_DIR ) . toBe ( "/tmp/dream-batch-clone/output" ) ;
407+ } finally {
408+ (
409+ settingsManager as unknown as {
410+ isMemfsEnabled : ( id : string ) => boolean ;
411+ }
412+ ) . isMemfsEnabled = originalIsMemfsEnabled ;
413+ }
414+ } ,
415+ ) ;
416+ } ) ;
417+ } ) ;
418+
419+ test ( "getShellEnv strips an explicit scope pointing into another agent's memory" , ( ) => {
420+ const otherAgentMemory = getMemoryFilesystemRoot ( `agent-other-${ Date . now ( ) } ` ) ;
421+ withTemporaryAgentEnv ( `agent-test-${ Date . now ( ) } ` , ( ) => {
422+ withTemporaryEnv (
423+ {
424+ MEMORY_DIR : otherAgentMemory ,
425+ LETTA_MEMORY_DIR : otherAgentMemory ,
426+ LETTA_MEMORY_DIR_EXPLICIT : "1" ,
427+ } ,
428+ ( ) => {
429+ const originalIsMemfsEnabled =
430+ settingsManager . isMemfsEnabled . bind ( settingsManager ) ;
431+ (
432+ settingsManager as unknown as {
433+ isMemfsEnabled : ( id : string ) => boolean ;
434+ }
435+ ) . isMemfsEnabled = ( ) => false ;
436+ try {
437+ const env = getShellEnv ( ) ;
438+ expect ( env . MEMORY_DIR ) . toBeUndefined ( ) ;
439+ expect ( env . LETTA_MEMORY_DIR ) . toBeUndefined ( ) ;
440+ } finally {
441+ (
442+ settingsManager as unknown as {
443+ isMemfsEnabled : ( id : string ) => boolean ;
444+ }
445+ ) . isMemfsEnabled = originalIsMemfsEnabled ;
446+ }
447+ } ,
448+ ) ;
449+ } ) ;
450+ } ) ;
451+
387452test ( "getShellEnv preserves inherited parent MEMORY_DIR for subagents" , ( ) => {
388453 const parentAgentId = `agent-parent-${ Date . now ( ) } ` ;
389454 const childAgentId = `agent-child-${ Date . now ( ) } ` ;
0 commit comments