@@ -621,7 +621,10 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceEntries", (it) => {
621621 const workspaceEntries = yield * WorkspaceEntries . WorkspaceEntries ;
622622 const path = yield * Path . Path ;
623623 const cwd = yield * makeTempDir ( { prefix : "t3code-picker-link-errors-" } ) ;
624- const target = yield * makeTempDir ( { prefix : "t3code-picker-link-target-" } ) ;
624+ const fs = yield * FileSystem . FileSystem ;
625+ const target = yield * fs . realPath (
626+ yield * makeTempDir ( { prefix : "t3code-picker-link-target-" } ) ,
627+ ) ;
625628 yield * writeTextFile ( cwd , "plain-file.txt" ) ;
626629 yield * writeTextFile ( cwd , "ordinary/package.json" , "{}" ) ;
627630 for ( const name of [
@@ -631,24 +634,25 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceEntries", (it) => {
631634 "linked-loop" ,
632635 "linked-denied" ,
633636 ] ) {
637+ yield * fs . makeDirectory ( path . join ( target , name ) ) ;
634638 yield * Effect . tryPromise ( ( ) =>
635- NodeFSP . symlink ( target , path . join ( cwd , name ) , "junction" ) ,
639+ NodeFSP . symlink ( path . join ( target , name ) , path . join ( cwd , name ) , "junction" ) ,
636640 ) ;
637641 }
638642 const originalStat = NodeFSP . stat ;
639643 const fileStat = yield * Effect . tryPromise ( ( ) =>
640644 originalStat ( path . join ( cwd , "plain-file.txt" ) ) ,
641645 ) ;
642646 const failures = new Map ( [
643- [ path . join ( cwd , "linked-broken" ) , "ENOENT" ] ,
644- [ path . join ( cwd , "linked-loop" ) , "ELOOP" ] ,
645- [ path . join ( cwd , "linked-denied" ) , "EACCES" ] ,
647+ [ path . join ( target , "linked-broken" ) , "ENOENT" ] ,
648+ [ path . join ( target , "linked-loop" ) , "ELOOP" ] ,
649+ [ path . join ( target , "linked-denied" ) , "EACCES" ] ,
646650 ] ) ;
647651 // Inject target states so this also runs on Windows without file-symlink privileges.
648652 using _stat = vi . spyOn ( NodeFSP , "stat" ) . mockImplementation ( ( file , options ) => {
649653 const code = failures . get ( String ( file ) ) ;
650654 if ( code ) return Promise . reject ( Object . assign ( new Error ( code ) , { code } ) ) ;
651- if ( String ( file ) === path . join ( cwd , "linked-file" ) ) return Promise . resolve ( fileStat ) ;
655+ if ( String ( file ) === path . join ( target , "linked-file" ) ) return Promise . resolve ( fileStat ) ;
652656 return originalStat ( file , options ) ;
653657 } ) ;
654658 const result = yield * workspaceEntries . browse ( {
@@ -665,7 +669,8 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceEntries", (it) => {
665669 Effect . gen ( function * ( ) {
666670 const workspaceEntries = yield * WorkspaceEntries . WorkspaceEntries ;
667671 const path = yield * Path . Path ;
668- const cwd = yield * makeTempDir ( { prefix : "t3code-picker-network-" } ) ;
672+ const fs = yield * FileSystem . FileSystem ;
673+ const cwd = yield * fs . realPath ( yield * makeTempDir ( { prefix : "t3code-picker-network-" } ) ) ;
669674 const target = yield * makeTempDir ( { prefix : "t3code-picker-local-" } ) ;
670675 const direct = path . join ( cwd , "network" ) ;
671676 const chained = path . join ( cwd , "chained" ) ;
@@ -696,6 +701,96 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceEntries", (it) => {
696701 } ) ,
697702 ) ;
698703
704+ it . effect (
705+ "rejects a network redirect in an intermediate target component before probing it" ,
706+ ( ) =>
707+ Effect . gen ( function * ( ) {
708+ const workspaceEntries = yield * WorkspaceEntries . WorkspaceEntries ;
709+ const path = yield * Path . Path ;
710+ const fs = yield * FileSystem . FileSystem ;
711+ const root = yield * fs . realPath (
712+ yield * makeTempDir ( { prefix : "t3code-picker-component-" } ) ,
713+ ) ;
714+ const cwd = path . join ( root , "projects" ) ;
715+ const target = path . join ( root , "target" ) ;
716+ yield * fs . makeDirectory ( cwd ) ;
717+ yield * fs . makeDirectory ( path . join ( target , "project" ) , { recursive : true } ) ;
718+ const redirect = path . join ( root , "redirect" ) ;
719+ const localRedirect = path . join ( root , "local-redirect" ) ;
720+ for ( const link of [ redirect , localRedirect ] ) {
721+ yield * Effect . tryPromise ( ( ) => NodeFSP . symlink ( target , link , "junction" ) ) ;
722+ }
723+ const blocked = path . join ( cwd , "blocked" ) ;
724+ const local = path . join ( cwd , "local" ) ;
725+ const unsafeTarget = path . join ( redirect , "project" ) ;
726+ yield * Effect . tryPromise ( ( ) => NodeFSP . symlink ( unsafeTarget , blocked , "junction" ) ) ;
727+ yield * Effect . tryPromise ( ( ) =>
728+ NodeFSP . symlink ( path . join ( localRedirect , "project" ) , local , "junction" ) ,
729+ ) ;
730+ const originalReadlink = NodeFSP . readlink ;
731+ const networkTarget = String . raw `\\host\share` ;
732+ using _readlink = vi
733+ . spyOn ( NodeFSP , "readlink" )
734+ . mockImplementation ( ( file , options ) =>
735+ String ( file ) === redirect
736+ ? Promise . resolve ( networkTarget )
737+ : originalReadlink ( file , options ) ,
738+ ) ;
739+ using stat = vi . spyOn ( NodeFSP , "stat" ) ;
740+ using lstat = vi . spyOn ( NodeFSP , "lstat" ) ;
741+ const result = yield * workspaceEntries . browse ( {
742+ partialPath : yield * appendSeparator ( cwd ) ,
743+ } ) ;
744+ expect ( result . entries ) . toEqual ( [ { name : "local" , fullPath : local } ] ) ;
745+ expect ( lstat . mock . calls . map ( ( [ file ] ) => String ( file ) ) ) . not . toContain ( unsafeTarget ) ;
746+ expect ( lstat . mock . calls . map ( ( [ file ] ) => String ( file ) ) ) . not . toContain ( networkTarget ) ;
747+ expect ( stat . mock . calls . map ( ( [ file ] ) => String ( file ) ) ) . not . toContain ( blocked ) ;
748+ expect ( stat . mock . calls . map ( ( [ file ] ) => String ( file ) ) ) . not . toContain ( local ) ;
749+ expect ( stat . mock . calls . map ( ( [ file ] ) => String ( file ) ) ) . not . toContain ( unsafeTarget ) ;
750+ expect ( stat . mock . calls . map ( ( [ file ] ) => String ( file ) ) ) . toContain (
751+ path . join ( target , "project" ) ,
752+ ) ;
753+ } ) ,
754+ ) ;
755+
756+ it . effect ( "resolves parent components after local links and bounds cyclic links" , ( ) =>
757+ Effect . gen ( function * ( ) {
758+ const workspaceEntries = yield * WorkspaceEntries . WorkspaceEntries ;
759+ const path = yield * Path . Path ;
760+ const fs = yield * FileSystem . FileSystem ;
761+ const root = yield * fs . realPath ( yield * makeTempDir ( { prefix : "t3code-picker-relative-" } ) ) ;
762+ const cwd = path . join ( root , "projects" ) ;
763+ const target = path . join ( root , "physical" , "sibling" ) ;
764+ const via = path . join ( root , "via" ) ;
765+ yield * fs . makeDirectory ( cwd ) ;
766+ yield * fs . makeDirectory ( target , { recursive : true } ) ;
767+ yield * fs . makeDirectory ( path . join ( root , "physical" , "child" ) ) ;
768+ yield * Effect . tryPromise ( ( ) =>
769+ NodeFSP . symlink ( path . join ( root , "physical" , "child" ) , via , "junction" ) ,
770+ ) ;
771+ const relative = path . join ( cwd , "relative" ) ;
772+ const cycle = path . join ( cwd , "cycle" ) ;
773+ for ( const link of [ relative , cycle ] ) {
774+ yield * Effect . tryPromise ( ( ) => NodeFSP . symlink ( target , link , "junction" ) ) ;
775+ }
776+ const originalReadlink = NodeFSP . readlink ;
777+ // Junction fixtures avoid Windows symlink privileges; inject relative and cyclic targets.
778+ using readlink = vi . spyOn ( NodeFSP , "readlink" ) . mockImplementation ( ( file , options ) => {
779+ if ( String ( file ) === relative )
780+ return Promise . resolve ( [ ".." , "via" , ".." , "sibling" ] . join ( path . sep ) ) ;
781+ if ( String ( file ) === cycle ) return Promise . resolve ( cycle ) ;
782+ return originalReadlink ( file , options ) ;
783+ } ) ;
784+ using stat = vi . spyOn ( NodeFSP , "stat" ) ;
785+ const result = yield * workspaceEntries . browse ( { partialPath : yield * appendSeparator ( cwd ) } ) ;
786+ expect ( result . entries ) . toEqual ( [ { name : "relative" , fullPath : relative } ] ) ;
787+ expect ( stat . mock . calls . map ( ( [ file ] ) => String ( file ) ) ) . toContain ( target ) ;
788+ expect ( stat . mock . calls . map ( ( [ file ] ) => String ( file ) ) ) . not . toContain ( relative ) ;
789+ expect ( stat . mock . calls . map ( ( [ file ] ) => String ( file ) ) ) . not . toContain ( cycle ) ;
790+ expect ( readlink . mock . calls . filter ( ( [ file ] ) => String ( file ) === cycle ) ) . toHaveLength ( 40 ) ;
791+ } ) ,
792+ ) ;
793+
699794 it . effect ( "shows dot directories in directory mode and hidden-prefix mode" , ( ) =>
700795 Effect . gen ( function * ( ) {
701796 const workspaceEntries = yield * WorkspaceEntries . WorkspaceEntries ;
0 commit comments