11// @effect-diagnostics nodeBuiltinImport:off
2+ import * as NodeFSP from "node:fs/promises";
3+
24import * as NodeServices from "@effect/platform-node/NodeServices";
35import { it, afterEach, describe, expect } from "@effect/vitest";
46import * as Effect from "effect/Effect";
@@ -17,7 +19,14 @@ import * as WorkspacePaths from "./WorkspacePaths.ts";
1719
1820vi.mock("node:fs/promises", async (importOriginal) => {
1921 const actual = await importOriginal<typeof import("node:fs/promises")>();
20- return { ...actual, readdir: vi.fn(actual.readdir) };
22+ return {
23+ ...actual,
24+ readdir: vi.fn(actual.readdir),
25+ stat: vi.fn(actual.stat),
26+ readlink: vi.fn(actual.readlink),
27+ realpath: vi.fn(actual.realpath),
28+ lstat: vi.fn(actual.lstat),
29+ };
2130});
2231
2332const layerTest = Layer.empty.pipe(
@@ -94,6 +103,44 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceEntries", (it) => {
94103 vi.restoreAllMocks();
95104 });
96105
106+ // quarantine: #19681 requires host support for creating symlinks.
107+ it.effect.skipIf(!symlinksSupported)(
108+ "never follows network targets while classifying links",
109+ () =>
110+ Effect.gen(function* () {
111+ const cwd = yield* makeTempDir();
112+ const fs = yield* FileSystem.FileSystem;
113+ const path = yield* Path.Path;
114+ yield* fs.makeDirectory(path.join(cwd, "storage"));
115+ yield* fs.symlink("storage", path.join(cwd, "network"));
116+ yield* fs.symlink("network", path.join(cwd, "chain"));
117+ yield* fs.symlink("network/child", path.join(cwd, "nested"));
118+ yield* fs.symlink("storage", path.join(cwd, "safe"));
119+ const actual = yield* Effect.promise(() =>
120+ vi.importActual<typeof NodeFSP>("node:fs/promises"),
121+ );
122+ using readlink = vi
123+ .spyOn(NodeFSP, "readlink")
124+ .mockImplementation(async (target, options) => {
125+ if (String(target).endsWith(`${path.sep}network`))
126+ return String.raw`\\attacker.test\share`;
127+ return actual.readlink(target, options);
128+ });
129+ using stat = vi.spyOn(NodeFSP, "stat");
130+ using realpath = vi.spyOn(NodeFSP, "realpath");
131+ using lstat = vi.spyOn(NodeFSP, "lstat");
132+ const entries = yield* WorkspaceEntries.WorkspaceEntries;
133+ const browse = yield* entries.browse({ partialPath: yield* appendSeparator(cwd) });
134+ expect(browse.entries.map((entry) => entry.name)).toEqual(["safe", "storage"]);
135+ const listed = yield* entries.list({ cwd, directoryPath: "" });
136+ expect(listed.entries.map((entry) => entry.path).toSorted()).toEqual(["safe", "storage"]);
137+ expect(stat.mock.calls).toEqual([]);
138+ for (const calls of [realpath.mock.calls, lstat.mock.calls, readlink.mock.calls]) {
139+ expect(calls.some(([target]) => /^[\\/]{2}/.test(String(target)))).toBe(false);
140+ }
141+ }),
142+ );
143+
97144 describe("list", () => {
98145 it.effect("lists immediate children including ignored and empty directories", () =>
99146 Effect.gen(function* () {
@@ -236,6 +283,7 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceEntries", (it) => {
236283 }),
237284 );
238285
286+ // quarantine: #19681 requires host support for creating symlinks.
239287 it.effect.skipIf(!symlinksSupported)("lists accessible directory and file links", () =>
240288 Effect.gen(function* () {
241289 const cwd = yield* makeTempDir();
@@ -264,6 +312,7 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceEntries", (it) => {
264312 }),
265313 );
266314
315+ // quarantine: #19681 requires host support for creating symlinks.
267316 it.effect.skipIf(!symlinksSupported)(
268317 "omits broken links, git links, and directory cycles",
269318 () =>
@@ -618,6 +667,7 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceEntries", (it) => {
618667 });
619668
620669 describe("browse", () => {
670+ // quarantine: #19681 requires host support for creating symlinks.
621671 it.effect.skipIf(!symlinksSupported)("offers linked directories when choosing a project", () =>
622672 Effect.gen(function* () {
623673 const cwd = yield* makeTempDir();
0 commit comments