@@ -747,6 +747,271 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceEntries", (it) => {
747747 } ) ;
748748
749749 describe ( "browse" , ( ) => {
750+ it . effect (
751+ "offers directory links in browsing and autocomplete while retaining their symlink paths" ,
752+ ( ) =>
753+ Effect . gen ( function * ( ) {
754+ const workspaceEntries = yield * WorkspaceEntries . WorkspaceEntries ;
755+ const path = yield * Path . Path ;
756+ const cwd = yield * makeTempDir ( { prefix : "t3code-picker-links-" } ) ;
757+ const target = yield * makeTempDir ( { prefix : "t3code-picker-target-" } ) ;
758+ yield * writeTextFile ( target , "nested-project/package.json" , "{}" ) ;
759+ yield * writeTextFile ( cwd , "ordinary/package.json" , "{}" ) ;
760+ const names = [ "linked-project" , "Templates" , "Recent" , ".linked-hidden" ] ;
761+ for ( const name of names ) {
762+ yield * Effect . tryPromise ( ( ) =>
763+ NodeFSP . symlink ( target , path . join ( cwd , name ) , "junction" ) ,
764+ ) ;
765+ }
766+ const root = yield * appendSeparator ( cwd ) ;
767+ const directory = yield * workspaceEntries . browse ( { partialPath : root } ) ;
768+ expect ( directory ) . toEqual ( {
769+ parentPath : cwd ,
770+ entries : [ ...names , "ordinary" ]
771+ . toSorted ( ( a , b ) => a . localeCompare ( b ) )
772+ . map ( ( name ) => ( {
773+ name,
774+ fullPath : path . join ( cwd , name ) ,
775+ } ) ) ,
776+ } ) ;
777+ expect ( yield * workspaceEntries . browse ( { partialPath : `${ root } LiNk` } ) ) . toEqual ( {
778+ parentPath : cwd ,
779+ entries : [ { name : "linked-project" , fullPath : path . join ( cwd , "linked-project" ) } ] ,
780+ } ) ;
781+ expect ( yield * workspaceEntries . browse ( { partialPath : `${ root } .link` } ) ) . toEqual ( {
782+ parentPath : cwd ,
783+ entries : [ { name : ".linked-hidden" , fullPath : path . join ( cwd , ".linked-hidden" ) } ] ,
784+ } ) ;
785+ const alias = path . join ( cwd , "linked-project" ) ;
786+ expect (
787+ yield * workspaceEntries . browse ( { partialPath : yield * appendSeparator ( alias ) } ) ,
788+ ) . toEqual ( {
789+ parentPath : alias ,
790+ entries : [ { name : "nested-project" , fullPath : path . join ( alias , "nested-project" ) } ] ,
791+ } ) ;
792+ } ) ,
793+ ) ;
794+
795+ it . effect (
796+ "omits file, broken, cyclic, and inaccessible link targets without losing other directories" ,
797+ ( ) =>
798+ Effect . gen ( function * ( ) {
799+ const workspaceEntries = yield * WorkspaceEntries . WorkspaceEntries ;
800+ const path = yield * Path . Path ;
801+ const cwd = yield * makeTempDir ( { prefix : "t3code-picker-link-errors-" } ) ;
802+ const fs = yield * FileSystem . FileSystem ;
803+ const target = yield * fs . realPath (
804+ yield * makeTempDir ( { prefix : "t3code-picker-link-target-" } ) ,
805+ ) ;
806+ yield * writeTextFile ( cwd , "plain-file.txt" ) ;
807+ yield * writeTextFile ( cwd , "ordinary/package.json" , "{}" ) ;
808+ for ( const name of [
809+ "linked-good" ,
810+ "linked-file" ,
811+ "linked-broken" ,
812+ "linked-loop" ,
813+ "linked-denied" ,
814+ ] ) {
815+ yield * fs . makeDirectory ( path . join ( target , name ) ) ;
816+ yield * Effect . tryPromise ( ( ) =>
817+ NodeFSP . symlink ( path . join ( target , name ) , path . join ( cwd , name ) , "junction" ) ,
818+ ) ;
819+ }
820+ const originalStat = NodeFSP . stat ;
821+ const fileStat = yield * Effect . tryPromise ( ( ) =>
822+ originalStat ( path . join ( cwd , "plain-file.txt" ) ) ,
823+ ) ;
824+ const failures = new Map ( [
825+ [ path . join ( target , "linked-broken" ) , "ENOENT" ] ,
826+ [ path . join ( target , "linked-loop" ) , "ELOOP" ] ,
827+ [ path . join ( target , "linked-denied" ) , "EACCES" ] ,
828+ ] ) ;
829+ // Inject target states so this also runs on Windows without file-symlink privileges.
830+ using _stat = vi . spyOn ( NodeFSP , "stat" ) . mockImplementation ( ( file , options ) => {
831+ const code = failures . get ( String ( file ) ) ;
832+ if ( code ) return Promise . reject ( Object . assign ( new Error ( code ) , { code } ) ) ;
833+ if ( String ( file ) === path . join ( target , "linked-file" ) ) return Promise . resolve ( fileStat ) ;
834+ return originalStat ( file , options ) ;
835+ } ) ;
836+ const result = yield * workspaceEntries . browse ( {
837+ partialPath : yield * appendSeparator ( cwd ) ,
838+ } ) ;
839+ expect ( result . entries ) . toEqual ( [
840+ { name : "linked-good" , fullPath : path . join ( cwd , "linked-good" ) } ,
841+ { name : "ordinary" , fullPath : path . join ( cwd , "ordinary" ) } ,
842+ ] ) ;
843+ } ) ,
844+ ) ;
845+
846+ it . effect ( "omits direct and chained network links without statting their targets" , ( ) =>
847+ Effect . gen ( function * ( ) {
848+ const workspaceEntries = yield * WorkspaceEntries . WorkspaceEntries ;
849+ const path = yield * Path . Path ;
850+ const fs = yield * FileSystem . FileSystem ;
851+ const cwd = yield * fs . realPath ( yield * makeTempDir ( { prefix : "t3code-picker-network-" } ) ) ;
852+ const target = yield * makeTempDir ( { prefix : "t3code-picker-local-" } ) ;
853+ const direct = path . join ( cwd , "network" ) ;
854+ const chained = path . join ( cwd , "chained" ) ;
855+ const local = path . join ( cwd , "local" ) ;
856+ for ( const link of [ direct , local ] ) {
857+ yield * Effect . tryPromise ( ( ) => NodeFSP . symlink ( target , link , "junction" ) ) ;
858+ }
859+ yield * Effect . tryPromise ( ( ) => NodeFSP . symlink ( direct , chained , "junction" ) ) ;
860+ const originalReadlink = NodeFSP . readlink ;
861+ const networkTarget = String . raw `\\host\share` ;
862+ using _readlink = vi
863+ . spyOn ( NodeFSP , "readlink" )
864+ . mockImplementation ( ( file , options ) =>
865+ String ( file ) === direct
866+ ? Promise . resolve ( networkTarget )
867+ : originalReadlink ( file , options ) ,
868+ ) ;
869+ using stat = vi . spyOn ( NodeFSP , "stat" ) ;
870+ using lstat = vi . spyOn ( NodeFSP , "lstat" ) ;
871+ const result = yield * workspaceEntries . browse ( {
872+ partialPath : yield * appendSeparator ( cwd ) ,
873+ } ) ;
874+ expect ( result . entries ) . toEqual ( [ { name : "local" , fullPath : local } ] ) ;
875+ expect ( stat . mock . calls . map ( ( [ file ] ) => String ( file ) ) ) . not . toContain ( direct ) ;
876+ expect ( stat . mock . calls . map ( ( [ file ] ) => String ( file ) ) ) . not . toContain ( chained ) ;
877+ expect ( stat . mock . calls . map ( ( [ file ] ) => String ( file ) ) ) . not . toContain ( networkTarget ) ;
878+ expect ( lstat . mock . calls . map ( ( [ file ] ) => String ( file ) ) ) . not . toContain ( networkTarget ) ;
879+ } ) ,
880+ ) ;
881+
882+ it . effect (
883+ "rejects a network redirect in an intermediate target component before probing it" ,
884+ ( ) =>
885+ Effect . gen ( function * ( ) {
886+ const workspaceEntries = yield * WorkspaceEntries . WorkspaceEntries ;
887+ const path = yield * Path . Path ;
888+ const fs = yield * FileSystem . FileSystem ;
889+ const root = yield * fs . realPath (
890+ yield * makeTempDir ( { prefix : "t3code-picker-component-" } ) ,
891+ ) ;
892+ const cwd = path . join ( root , "projects" ) ;
893+ const target = path . join ( root , "target" ) ;
894+ yield * fs . makeDirectory ( cwd ) ;
895+ yield * fs . makeDirectory ( path . join ( target , "project" ) , { recursive : true } ) ;
896+ const redirect = path . join ( root , "redirect" ) ;
897+ const localRedirect = path . join ( root , "local-redirect" ) ;
898+ for ( const link of [ redirect , localRedirect ] ) {
899+ yield * Effect . tryPromise ( ( ) => NodeFSP . symlink ( target , link , "junction" ) ) ;
900+ }
901+ const blocked = path . join ( cwd , "blocked" ) ;
902+ const local = path . join ( cwd , "local" ) ;
903+ const unsafeTarget = path . join ( redirect , "project" ) ;
904+ yield * Effect . tryPromise ( ( ) => NodeFSP . symlink ( unsafeTarget , blocked , "junction" ) ) ;
905+ yield * Effect . tryPromise ( ( ) =>
906+ NodeFSP . symlink ( path . join ( localRedirect , "project" ) , local , "junction" ) ,
907+ ) ;
908+ const originalReadlink = NodeFSP . readlink ;
909+ const networkTarget = String . raw `\\host\share` ;
910+ using _readlink = vi
911+ . spyOn ( NodeFSP , "readlink" )
912+ . mockImplementation ( ( file , options ) =>
913+ String ( file ) === redirect
914+ ? Promise . resolve ( networkTarget )
915+ : originalReadlink ( file , options ) ,
916+ ) ;
917+ using stat = vi . spyOn ( NodeFSP , "stat" ) ;
918+ using lstat = vi . spyOn ( NodeFSP , "lstat" ) ;
919+ const result = yield * workspaceEntries . browse ( {
920+ partialPath : yield * appendSeparator ( cwd ) ,
921+ } ) ;
922+ expect ( result . entries ) . toEqual ( [ { name : "local" , fullPath : local } ] ) ;
923+ expect ( lstat . mock . calls . map ( ( [ file ] ) => String ( file ) ) ) . not . toContain ( unsafeTarget ) ;
924+ expect ( lstat . mock . calls . map ( ( [ file ] ) => String ( file ) ) ) . not . toContain ( networkTarget ) ;
925+ expect ( stat . mock . calls . map ( ( [ file ] ) => String ( file ) ) ) . not . toContain ( blocked ) ;
926+ expect ( stat . mock . calls . map ( ( [ file ] ) => String ( file ) ) ) . not . toContain ( local ) ;
927+ expect ( stat . mock . calls . map ( ( [ file ] ) => String ( file ) ) ) . not . toContain ( unsafeTarget ) ;
928+ expect ( stat . mock . calls . map ( ( [ file ] ) => String ( file ) ) ) . toContain (
929+ path . join ( target , "project" ) ,
930+ ) ;
931+ } ) ,
932+ ) ;
933+
934+ it . effect (
935+ "reads a chosen link's resolved folder and skips one retargeted to a network share" ,
936+ ( ) =>
937+ Effect . gen ( function * ( ) {
938+ const workspaceEntries = yield * WorkspaceEntries . WorkspaceEntries ;
939+ const path = yield * Path . Path ;
940+ const fs = yield * FileSystem . FileSystem ;
941+ const root = yield * fs . realPath ( yield * makeTempDir ( { prefix : "t3code-picker-parent-" } ) ) ;
942+ const target = path . join ( root , "target" ) ;
943+ yield * fs . makeDirectory ( path . join ( target , "child" ) , { recursive : true } ) ;
944+ const local = path . join ( root , "local" ) ;
945+ const network = path . join ( root , "network" ) ;
946+ for ( const link of [ local , network ] ) {
947+ yield * Effect . tryPromise ( ( ) => NodeFSP . symlink ( target , link , "junction" ) ) ;
948+ }
949+ const originalReadlink = NodeFSP . readlink ;
950+ const networkTarget = String . raw `\\host\share` ;
951+ using _readlink = vi
952+ . spyOn ( NodeFSP , "readlink" )
953+ . mockImplementation ( ( file , options ) =>
954+ String ( file ) === network
955+ ? Promise . resolve ( networkTarget )
956+ : originalReadlink ( file , options ) ,
957+ ) ;
958+ using readdir = vi . spyOn ( NodeFSP , "readdir" ) ;
959+
960+ const localResult = yield * workspaceEntries . browse ( {
961+ partialPath : yield * appendSeparator ( local ) ,
962+ } ) ;
963+ expect ( localResult . entries ) . toEqual ( [
964+ { name : "child" , fullPath : path . join ( local , "child" ) } ,
965+ ] ) ;
966+ const networkResult = yield * workspaceEntries . browse ( {
967+ partialPath : yield * appendSeparator ( network ) ,
968+ } ) ;
969+ expect ( networkResult . entries ) . toEqual ( [ ] ) ;
970+ const readPaths = readdir . mock . calls . map ( ( [ file ] ) => String ( file ) ) ;
971+ expect ( readPaths ) . toContain ( target ) ;
972+ expect ( readPaths ) . not . toContain ( local ) ;
973+ expect ( readPaths ) . not . toContain ( network ) ;
974+ } ) ,
975+ ) ;
976+
977+ it . effect ( "resolves parent components after local links and bounds cyclic links" , ( ) =>
978+ Effect . gen ( function * ( ) {
979+ const workspaceEntries = yield * WorkspaceEntries . WorkspaceEntries ;
980+ const path = yield * Path . Path ;
981+ const fs = yield * FileSystem . FileSystem ;
982+ const root = yield * fs . realPath ( yield * makeTempDir ( { prefix : "t3code-picker-relative-" } ) ) ;
983+ const cwd = path . join ( root , "projects" ) ;
984+ const target = path . join ( root , "physical" , "sibling" ) ;
985+ const via = path . join ( root , "via" ) ;
986+ yield * fs . makeDirectory ( cwd ) ;
987+ yield * fs . makeDirectory ( target , { recursive : true } ) ;
988+ yield * fs . makeDirectory ( path . join ( root , "physical" , "child" ) ) ;
989+ yield * Effect . tryPromise ( ( ) =>
990+ NodeFSP . symlink ( path . join ( root , "physical" , "child" ) , via , "junction" ) ,
991+ ) ;
992+ const relative = path . join ( cwd , "relative" ) ;
993+ const cycle = path . join ( cwd , "cycle" ) ;
994+ for ( const link of [ relative , cycle ] ) {
995+ yield * Effect . tryPromise ( ( ) => NodeFSP . symlink ( target , link , "junction" ) ) ;
996+ }
997+ const originalReadlink = NodeFSP . readlink ;
998+ // Junction fixtures avoid Windows symlink privileges; inject relative and cyclic targets.
999+ using readlink = vi . spyOn ( NodeFSP , "readlink" ) . mockImplementation ( ( file , options ) => {
1000+ if ( String ( file ) === relative )
1001+ return Promise . resolve ( [ ".." , "via" , ".." , "sibling" ] . join ( path . sep ) ) ;
1002+ if ( String ( file ) === cycle ) return Promise . resolve ( cycle ) ;
1003+ return originalReadlink ( file , options ) ;
1004+ } ) ;
1005+ using stat = vi . spyOn ( NodeFSP , "stat" ) ;
1006+ const result = yield * workspaceEntries . browse ( { partialPath : yield * appendSeparator ( cwd ) } ) ;
1007+ expect ( result . entries ) . toEqual ( [ { name : "relative" , fullPath : relative } ] ) ;
1008+ expect ( stat . mock . calls . map ( ( [ file ] ) => String ( file ) ) ) . toContain ( target ) ;
1009+ expect ( stat . mock . calls . map ( ( [ file ] ) => String ( file ) ) ) . not . toContain ( relative ) ;
1010+ expect ( stat . mock . calls . map ( ( [ file ] ) => String ( file ) ) ) . not . toContain ( cycle ) ;
1011+ expect ( readlink . mock . calls . filter ( ( [ file ] ) => String ( file ) === cycle ) ) . toHaveLength ( 40 ) ;
1012+ } ) ,
1013+ ) ;
1014+
7501015 it . effect ( "shows dot directories in directory mode and hidden-prefix mode" , ( ) =>
7511016 Effect . gen ( function * ( ) {
7521017 const workspaceEntries = yield * WorkspaceEntries . WorkspaceEntries ;
0 commit comments