@@ -1142,6 +1142,13 @@ async function writeWorkspaceFile(
11421142 // succeeds. Eagerly starting it would orphan a rejecting root promise as an unhandled
11431143 // rejection when validation fails first — the readFile/access paths already defer the same way.
11441144 const relative = await toCanonicalRelativeWorkspacePath ( root , absolutePath ) ;
1145+ // fs-safe 0.5.2 atomically replaces a final symlink on write. The workspace
1146+ // contract rejects symlink write targets so the link and its target survive.
1147+ const rootReal = await fs . realpath ( root ) ;
1148+ const targetStat = await fs . lstat ( path . resolve ( rootReal , relative ) ) . catch ( ( ) => undefined ) ;
1149+ if ( targetStat ?. isSymbolicLink ( ) ) {
1150+ throw new FsSafeError ( "symlink" , `refusing to write to symlink: ${ absolutePath } ` ) ;
1151+ }
11451152 await ( await getRoot ( ) ) . write ( relative , content , { mkdir : true } ) ;
11461153}
11471154
@@ -1189,7 +1196,10 @@ function createHostWriteOperations(
11891196 writeFile : ( absolutePath : string , content : string ) =>
11901197 writeWorkspaceFile ( root , getRoot , absolutePath , content ) ,
11911198 readFile : async ( absolutePath : string ) => {
1192- const relative = toRelativeWorkspacePath ( root , absolutePath ) ;
1199+ // Canonicalize symlink parents like the write path: fs-safe 0.5.2
1200+ // rejects intermediate symlinks by default, but in-workspace symlink
1201+ // parents are part of the workspace contract.
1202+ const relative = await toCanonicalRelativeWorkspacePath ( root , absolutePath ) ;
11931203 return ( await ( await getRoot ( ) ) . read ( relative ) ) . buffer ;
11941204 } ,
11951205 statFile : async ( absolutePath : string ) => {
@@ -1236,7 +1246,10 @@ function createHostEditOperations(
12361246 return withMemoryWriteProvenance (
12371247 {
12381248 readFile : async ( absolutePath : string ) => {
1239- const relative = toRelativeWorkspacePath ( root , absolutePath ) ;
1249+ // Canonicalize symlink parents like the write path: fs-safe 0.5.2
1250+ // rejects intermediate symlinks by default, but in-workspace symlink
1251+ // parents are part of the workspace contract.
1252+ const relative = await toCanonicalRelativeWorkspacePath ( root , absolutePath ) ;
12401253 const safeRead = await ( await getRoot ( ) ) . read ( relative ) ;
12411254 return safeRead . buffer ;
12421255 } ,
@@ -1249,7 +1262,8 @@ function createHostEditOperations(
12491262 access : async ( absolutePath : string ) => {
12501263 let relative : string ;
12511264 try {
1252- relative = toRelativeWorkspacePath ( root , absolutePath ) ;
1265+ // Canonicalized like readFile so in-workspace symlink parents pass.
1266+ relative = await toCanonicalRelativeWorkspacePath ( root , absolutePath ) ;
12531267 } catch {
12541268 // Path escapes workspace root. Don't throw here – the upstream
12551269 // library replaces any `access` error with a misleading "File not
0 commit comments