@@ -314,7 +314,7 @@ describe("symlinks", () => {
314314 ) . toBe ( "x" ) ;
315315 } ) ;
316316
317- it ( "refuses to write under a respelled dangling symlink, reporting a missing parent " , async ( ) => {
317+ it ( "refuses to write under a respelled dangling symlink, naming it as broken (#5191) " , async ( ) => {
318318 await fs . symlink (
319319 path . join ( outside , "not-yet" ) ,
320320 path . join ( dir , "dangling" ) ,
@@ -324,24 +324,51 @@ describe("symlinks", () => {
324324 content : "x" ,
325325 } ) ;
326326 expect ( textOf ( result ) ) . toBe (
327- `Parent directory does not exist : ${ path . join ( dir , "DANGLING" ) } ` ,
327+ `Broken symlink : ${ path . join ( dir , "DANGLING" ) } points to a target that does not exist ` ,
328328 ) ;
329329 await expect ( fs . stat ( path . join ( outside , "not-yet" ) ) ) . rejects . toThrow ( ) ;
330330 } ) ;
331331 } ,
332332 ) ;
333333
334- it ( "refuses to write through a dangling symlink, reporting a missing parent" , async ( ) => {
334+ // #5191: the refusal is right, and the message names the symlink rather
335+ // than reporting its parent, which exists, as missing.
336+ it ( "refuses to write through a dangling symlink, naming it as broken (#5191)" , async ( ) => {
335337 const link = path . join ( dir , "dangling" ) ;
336338 await fs . symlink ( path . join ( outside , "not-yet" ) , link ) ;
337339 const result = await call ( client , "write_file" , {
338340 path : link ,
339341 content : "x" ,
340342 } ) ;
341- expect ( textOf ( result ) ) . toBe ( `Parent directory does not exist: ${ dir } ` ) ;
343+ expect ( textOf ( result ) ) . toBe (
344+ `Broken symlink: ${ link } points to a target that does not exist` ,
345+ ) ;
342346 await expect ( fs . stat ( path . join ( outside , "not-yet" ) ) ) . rejects . toThrow ( ) ;
343347 } ) ;
344348
349+ it ( "refuses to read a dangling symlink, naming it as broken (#5191)" , async ( ) => {
350+ const link = path . join ( dir , "dangling" ) ;
351+ await fs . symlink ( path . join ( dir , "gone.txt" ) , link ) ;
352+ const result = await read ( link ) ;
353+ expect ( result . isError ) . toBe ( true ) ;
354+ expect ( textOf ( result ) ) . toBe (
355+ `Broken symlink: ${ link } points to a target that does not exist` ,
356+ ) ;
357+ } ) ;
358+
359+ it ( "names a dangling symlink in the middle of a path as broken (#5191)" , async ( ) => {
360+ const link = path . join ( dir , "dangling-dir" ) ;
361+ await fs . symlink ( path . join ( dir , "gone" ) , link ) ;
362+ const result = await call ( client , "write_file" , {
363+ path : path . join ( link , "f.txt" ) ,
364+ content : "x" ,
365+ } ) ;
366+ expect ( textOf ( result ) ) . toBe (
367+ `Broken symlink: ${ link } points to a target that does not exist` ,
368+ ) ;
369+ await expect ( fs . stat ( path . join ( dir , "gone" ) ) ) . rejects . toThrow ( ) ;
370+ } ) ;
371+
345372 it ( "reports a realpath failure other than ENOENT as is" , async ( ) => {
346373 await fs . writeFile ( path . join ( dir , "file.txt" ) , "" ) ;
347374 const result = await read ( path . join ( dir , "file.txt" , "child" ) ) ;
0 commit comments