Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

NodePTY.test.ts

45 lines1.6 KB

1import { FileSystem, Path, Effect } from "effect";
2import { assert, it } from "@effect/vitest";
3​
4import { ensureNodePtySpawnHelperExecutable } from "./NodePTY";
5import * as NodeServices from "@effect/platform-node/NodeServices";
6​
7it.layer(NodeServices.layer)("ensureNodePtySpawnHelperExecutable", (it) => {
8 it.effect("adds executable bits when helper exists but is not executable", () =>
9 Effect.gen(function* () {
10 if (process.platform === "win32") return;
11​
12 const fs = yield* FileSystem.FileSystem;
13 const path = yield* Path.Path;
14​
15 const dir = yield* fs.makeTempDirectoryScoped({ prefix: "pty-helper-test-" });
16 const helperPath = path.join(dir, "spawn-helper");
17 yield* fs.writeFileString(helperPath, "#!/bin/sh\nexit 0\n");
18 yield* fs.chmod(helperPath, 0o644);
19​
20 yield* ensureNodePtySpawnHelperExecutable(helperPath);
21​
22 const mode = (yield* fs.stat(helperPath)).mode & 0o777;
23 assert.equal(mode & 0o111, 0o111);
24 }),
25 );
26​
27 it.effect("keeps executable helper as executable", () =>
28 Effect.gen(function* () {
29 if (process.platform === "win32") return;
30​
31 const fs = yield* FileSystem.FileSystem;
32 const path = yield* Path.Path;
33​
34 const dir = yield* fs.makeTempDirectoryScoped({ prefix: "pty-helper-test-" });
35 const helperPath = path.join(dir, "spawn-helper");
36 yield* fs.writeFileString(helperPath, "#!/bin/sh\nexit 0\n");
37 yield* fs.chmod(helperPath, 0o755);
38​
39 yield* ensureNodePtySpawnHelperExecutable(helperPath);
40​
41 const mode = (yield* fs.stat(helperPath)).mode & 0o777;
42 assert.equal(mode & 0o111, 0o111);
43 }),
44 );
45});