@@ -75,6 +75,50 @@ async function main() {
7575 fs . openSync = open ;
7676 }
7777 } ) ;
78+ function failTraversal ( roots , phase , fn ) {
79+ const open = fs . opendirSync ;
80+ let closed = false ;
81+ fs . opendirSync = ( directory , ...args ) => {
82+ if ( directory !== roots . project ) return open ( directory , ...args ) ;
83+ const fail = ( ) => {
84+ const error = new Error ( 'Synthetic private directory detail.' ) ;
85+ error . code = 'EACCES' ;
86+ throw error ;
87+ } ;
88+ if ( phase === 'open' ) return fail ( ) ;
89+ const handle = open ( directory , ...args ) ;
90+ return {
91+ readSync : ( ) => phase === 'read' ? fail ( ) : handle . readSync ( ) ,
92+ closeSync : ( ) => {
93+ handle . closeSync ( ) ; closed = true ;
94+ if ( phase === 'close' ) fail ( ) ;
95+ } ,
96+ } ;
97+ } ;
98+ try { fn ( ) ; } finally {
99+ fs . opendirSync = open ;
100+ if ( phase !== 'open' ) assert . equal ( closed , true ) ;
101+ }
102+ }
103+ for ( const phase of [ 'open' , 'read' , 'close' ] ) {
104+ check ( `direct read classifies directory ${ phase } failure` , ( { roots, read } ) => {
105+ failTraversal ( roots , phase , ( ) => {
106+ assert . throws ( read , error => error . code === 'ECC_MEMORY_INCOMPLETE'
107+ && ! error . message . includes ( 'Synthetic private directory detail.' ) ) ;
108+ } ) ;
109+ } ) ;
110+ check ( `MCP read classifies directory ${ phase } failure` , ( { roots, mcp } ) => {
111+ failTraversal ( roots , phase , ( ) => {
112+ const result = mcp ( ) ; assert . equal ( result . isError , true ) ;
113+ const error = JSON . parse ( result . content [ 0 ] . text ) . error ;
114+ assert . equal ( error . code , 'MEMORY_READ_INCOMPLETE' ) ;
115+ assert . equal ( error . message . includes ( 'Synthetic private directory detail.' ) , false ) ;
116+ } ) ;
117+ } ) ;
118+ }
119+ check ( 'unreadable traversal cannot establish missing memory' , ( { roots, read } ) => {
120+ failTraversal ( roots , 'open' , ( ) => incomplete ( ( ) => read ( 'mem_synthetic_missing' ) ) ) ;
121+ } ) ;
78122 check ( 'MCP incomplete lookup has a distinct bounded error' , ( { mcp, truncate } ) => {
79123 truncate ( ) ; const result = mcp ( ) ; assert . equal ( result . isError , true ) ;
80124 const error = JSON . parse ( result . content [ 0 ] . text ) . error ;
0 commit comments