|
| 1 | +// @effect-diagnostics nodeBuiltinImport:off -- Raw filename bytes are not supported by Effect FileSystem paths. |
| 2 | +import * as NodeFSP from "node:fs/promises"; |
| 3 | + |
1 | 4 | import * as NodeServices from "@effect/platform-node/NodeServices"; |
| 5 | +import * as HostProcess from "@t3tools/shared/HostProcess"; |
2 | 6 | import { describe, expect, it } from "@effect/vitest"; |
3 | 7 | import * as Effect from "effect/Effect"; |
4 | 8 | import * as FileSystem from "effect/FileSystem"; |
@@ -43,6 +47,36 @@ it.layer(NodeServices.layer)("digestPluginSource", (it) => { |
43 | 47 | }), |
44 | 48 | ); |
45 | 49 |
|
| 50 | + it.effect("covers valid filenames containing the Unicode replacement character", () => |
| 51 | + Effect.gen(function* () { |
| 52 | + const fs = yield* FileSystem.FileSystem; |
| 53 | + const path = yield* Path.Path; |
| 54 | + const directory = yield* makeTree({ "a�.js": "A" }); |
| 55 | + const first = yield* digestPluginSource(directory); |
| 56 | + yield* fs.writeFileString(path.join(directory, "a�.js"), "B"); |
| 57 | + expect((yield* digestPluginSource(directory)).digest).not.toBe(first.digest); |
| 58 | + }), |
| 59 | + ); |
| 60 | + |
| 61 | + it.effect.each(["file", "directory"] as const)( |
| 62 | + "refuses invalid UTF-8 %s names", |
| 63 | + (kind, context) => |
| 64 | + Effect.gen(function* () { |
| 65 | + const platform = yield* HostProcess.Platform; |
| 66 | + if (platform !== "linux") context.skip(); |
| 67 | + const directory = yield* makeTree({ "a�.js": "B" }); |
| 68 | + const raw = Buffer.concat([ |
| 69 | + Buffer.from(`${directory}/`), |
| 70 | + Buffer.from([0x61, 0xff, 0x2e, 0x6a, 0x73]), |
| 71 | + ]); |
| 72 | + yield* Effect.tryPromise(() => |
| 73 | + kind === "file" ? NodeFSP.writeFile(raw, "A") : NodeFSP.mkdir(raw), |
| 74 | + ); |
| 75 | + const error = yield* digestPluginSource(directory).pipe(Effect.flip); |
| 76 | + expect(error.reason).toBe("a filename is not valid UTF-8."); |
| 77 | + }), |
| 78 | + ); |
| 79 | + |
46 | 80 | it.effect("covers hidden paths, which an entry or import may use", () => |
47 | 81 | Effect.gen(function* () { |
48 | 82 | const fs = yield* FileSystem.FileSystem; |
|
0 commit comments