@@ -6,6 +6,7 @@ import * as FileSystem from "effect/FileSystem";
66import * as Layer from "effect/Layer" ;
77import * as Path from "effect/Path" ;
88import * as PlatformError from "effect/PlatformError" ;
9+ import { symlinksSupported } from "@t3tools/shared/testing/symlinks" ;
910import { vi } from "vite-plus/test" ;
1011
1112import * as ServerConfig from "../config.ts" ;
@@ -222,28 +223,77 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceEntries", (it) => {
222223 } ) ,
223224 ) ;
224225
225- it . effect (
226- "rejects directory traversal, git internals, and symlinks outside the workspace" ,
226+ it . effect ( "rejects directory traversal and git internals" , ( ) =>
227+ Effect . gen ( function * ( ) {
228+ const cwd = yield * makeTempDir ( ) ;
229+ const outside = yield * makeTempDir ( ) ;
230+ yield * writeTextFile ( cwd , ".git/HEAD" ) ;
231+ const workspaceEntries = yield * WorkspaceEntries . WorkspaceEntries ;
232+ for ( const directoryPath of [ "../" , outside , ".git" , "missing" ] ) {
233+ const error = yield * workspaceEntries . list ( { cwd, directoryPath } ) . pipe ( Effect . flip ) ;
234+ expect ( error . _tag ) . toBe ( "WorkspaceEntriesReadDirectoryError" ) ;
235+ }
236+ } ) ,
237+ ) ;
238+
239+ it . effect . skipIf ( ! symlinksSupported ) ( "lists accessible directory and file links" , ( ) =>
240+ Effect . gen ( function * ( ) {
241+ const cwd = yield * makeTempDir ( ) ;
242+ const outside = yield * makeTempDir ( ) ;
243+ const fs = yield * FileSystem . FileSystem ;
244+ const path = yield * Path . Path ;
245+ yield * writeTextFile ( outside , "notes.md" , "report\n" ) ;
246+ yield * fs . symlink ( outside , path . join ( cwd , "external" ) ) ;
247+ yield * fs . symlink ( path . join ( outside , "notes.md" ) , path . join ( cwd , "report.md" ) ) ;
248+ yield * fs . symlink ( path . join ( outside , "missing" ) , path . join ( cwd , "broken" ) ) ;
249+ const entries = yield * WorkspaceEntries . WorkspaceEntries ;
250+ expect ( ( yield * entries . list ( { cwd, directoryPath : "" } ) ) . entries ) . toEqual (
251+ expect . arrayContaining ( [
252+ { path : "external" , kind : "directory" } ,
253+ { path : "report.md" , kind : "file" } ,
254+ ] ) ,
255+ ) ;
256+ expect (
257+ ( yield * entries . list ( { cwd, directoryPath : "" } ) ) . entries . some (
258+ ( entry ) => entry . path === "broken" ,
259+ ) ,
260+ ) . toBe ( false ) ;
261+ expect ( ( yield * entries . list ( { cwd, directoryPath : "external" } ) ) . entries ) . toEqual ( [
262+ { path : "external/notes.md" , kind : "file" } ,
263+ ] ) ;
264+ } ) ,
265+ ) ;
266+
267+ it . effect . skipIf ( ! symlinksSupported ) (
268+ "omits broken links, git links, and directory cycles" ,
227269 ( ) =>
228270 Effect . gen ( function * ( ) {
229271 const cwd = yield * makeTempDir ( ) ;
230272 const outside = yield * makeTempDir ( ) ;
231- const fileSystem = yield * FileSystem . FileSystem ;
273+ const fs = yield * FileSystem . FileSystem ;
232274 const path = yield * Path . Path ;
233- yield * writeTextFile ( cwd , ".git/HEAD" ) ;
234- const platform = yield * HostProcess . Platform ;
235- if ( platform !== "win32" ) yield * fileSystem . symlink ( outside , path . join ( cwd , "external" ) ) ;
236- const workspaceEntries = yield * WorkspaceEntries . WorkspaceEntries ;
237- for ( const directoryPath of [
238- "../" ,
239- outside ,
240- ".git" ,
241- "missing" ,
242- ...( platform !== "win32" ? [ "external" ] : [ ] ) ,
243- ] ) {
244- const error = yield * workspaceEntries . list ( { cwd, directoryPath } ) . pipe ( Effect . flip ) ;
245- expect ( error . _tag ) . toBe ( "WorkspaceEntriesReadDirectoryError" ) ;
246- }
275+ yield * writeTextFile ( outside , "a/notes.md" ) ;
276+ yield * writeTextFile ( outside , "b/notes.md" ) ;
277+ yield * writeTextFile ( outside , ".git/HEAD" ) ;
278+ yield * fs . symlink ( path . join ( outside , "a" ) , path . join ( cwd , "external" ) ) ;
279+ yield * fs . symlink ( "." , path . join ( cwd , "self" ) ) ;
280+ yield * fs . symlink ( path . join ( outside , ".git" ) , path . join ( cwd , "metadata" ) ) ;
281+ yield * fs . symlink ( path . join ( outside , ".git/HEAD" ) , path . join ( cwd , "head-link" ) ) ;
282+ yield * fs . symlink ( path . join ( outside , "missing" ) , path . join ( cwd , "broken" ) ) ;
283+ yield * fs . symlink ( "../b" , path . join ( outside , "a/to-b" ) ) ;
284+ yield * fs . symlink ( "../a" , path . join ( outside , "b/to-a" ) ) ;
285+ yield * fs . symlink ( "." , path . join ( outside , "a/self" ) ) ;
286+ yield * fs . symlink ( ".." , path . join ( outside , "a/up" ) ) ;
287+ const entries = yield * WorkspaceEntries . WorkspaceEntries ;
288+ expect ( ( yield * entries . list ( { cwd, directoryPath : "" } ) ) . entries ) . toEqual ( [
289+ { path : "external" , kind : "directory" } ,
290+ ] ) ;
291+ expect ( ( yield * entries . list ( { cwd, directoryPath : "external" } ) ) . entries ) . toEqual ( [
292+ { path : "external/notes.md" , kind : "file" } ,
293+ { path : "external/to-b" , kind : "directory" } ,
294+ ] ) ;
295+ const nested = yield * entries . list ( { cwd, directoryPath : "external/to-b" } ) ;
296+ expect ( nested . entries ) . toEqual ( [ { path : "external/to-b/notes.md" , kind : "file" } ] ) ;
247297 } ) ,
248298 ) ;
249299
@@ -568,6 +618,26 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceEntries", (it) => {
568618 } ) ;
569619
570620 describe ( "browse" , ( ) => {
621+ it . effect . skipIf ( ! symlinksSupported ) ( "offers linked directories when choosing a project" , ( ) =>
622+ Effect . gen ( function * ( ) {
623+ const cwd = yield * makeTempDir ( ) ;
624+ const target = yield * makeTempDir ( ) ;
625+ const fs = yield * FileSystem . FileSystem ;
626+ const path = yield * Path . Path ;
627+ yield * fs . symlink ( target , path . join ( cwd , "project-link" ) ) ;
628+ yield * fs . symlink ( path . join ( target , "missing" ) , path . join ( cwd , "broken" ) ) ;
629+ const entries = yield * WorkspaceEntries . WorkspaceEntries ;
630+ const result = yield * entries . browse ( { partialPath : yield * appendSeparator ( cwd ) } ) ;
631+ expect ( result . entries ) . toEqual ( [
632+ { name : "project-link" , fullPath : path . join ( cwd , "project-link" ) } ,
633+ ] ) ;
634+ const workspacePaths = yield * WorkspacePaths . WorkspacePaths ;
635+ expect ( yield * workspacePaths . normalizeWorkspaceRoot ( result . entries [ 0 ] ! . fullPath ) ) . toBe (
636+ path . join ( cwd , "project-link" ) ,
637+ ) ;
638+ } ) ,
639+ ) ;
640+
571641 it . effect ( "shows dot directories in directory mode and hidden-prefix mode" , ( ) =>
572642 Effect . gen ( function * ( ) {
573643 const workspaceEntries = yield * WorkspaceEntries . WorkspaceEntries ;
0 commit comments