|
2 | 2 | import * as NodeFSP from "node:fs/promises"; |
3 | 3 | import * as NodeServices from "@effect/platform-node/NodeServices"; |
4 | 4 | import { FileFinder } from "@ff-labs/fff-node"; |
5 | | -import * as NodeFSP from "node:fs/promises"; |
6 | 5 | import { it, afterEach, describe, expect } from "@effect/vitest"; |
7 | 6 | import * as Effect from "effect/Effect"; |
8 | 7 | import * as FileSystem from "effect/FileSystem"; |
@@ -821,6 +820,32 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceEntries", (it) => { |
821 | 820 | }), |
822 | 821 | ); |
823 | 822 |
|
| 823 | + it.effect("does not read a directory selected through a network link", () => |
| 824 | + Effect.gen(function* () { |
| 825 | + const workspaceEntries = yield* WorkspaceEntries.WorkspaceEntries; |
| 826 | + const path = yield* Path.Path; |
| 827 | + const fs = yield* FileSystem.FileSystem; |
| 828 | + const cwd = yield* fs.realPath(yield* makeTempDir({ prefix: "t3code-picker-selected-" })); |
| 829 | + const target = yield* makeTempDir({ prefix: "t3code-picker-local-" }); |
| 830 | + const link = path.join(cwd, "network"); |
| 831 | + yield* Effect.tryPromise(() => NodeFSP.symlink(target, link, "junction")); |
| 832 | + const originalReadlink = NodeFSP.readlink; |
| 833 | + using _readlink = vi |
| 834 | + .spyOn(NodeFSP, "readlink") |
| 835 | + .mockImplementation((file, options) => |
| 836 | + String(file) === link |
| 837 | + ? Promise.resolve(String.raw`\\host\share`) |
| 838 | + : originalReadlink(file, options), |
| 839 | + ); |
| 840 | + using readdir = vi.spyOn(NodeFSP, "readdir"); |
| 841 | + const result = yield* workspaceEntries.browse({ |
| 842 | + partialPath: yield* appendSeparator(link), |
| 843 | + }); |
| 844 | + expect(result).toEqual({ parentPath: link, entries: [] }); |
| 845 | + expect(readdir).not.toHaveBeenCalled(); |
| 846 | + }), |
| 847 | + ); |
| 848 | + |
824 | 849 | it.effect("omits direct and chained network links without statting their targets", () => |
825 | 850 | Effect.gen(function* () { |
826 | 851 | const workspaceEntries = yield* WorkspaceEntries.WorkspaceEntries; |
|
0 commit comments