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

ptyAdapter.test.ts

54 lines1.7 KB

1import fs from "node:fs";
2import os from "node:os";
3import path from "node:path";
4​
5import { afterEach, describe, expect, it } from "vitest";
6​
7import { ensureNodePtySpawnHelperExecutable } from "./ptyAdapter";
8​
9function fileMode(filePath: string): number {
10 return fs.statSync(filePath).mode & 0o777;
12​
13describe("ensureNodePtySpawnHelperExecutable", () => {
14 const tempDirs: string[] = [];
15​
16 afterEach(() => {
17 for (const dir of tempDirs.splice(0, tempDirs.length)) {
18 fs.rmSync(dir, { recursive: true, force: true });
19 }
20 });
21​
22 it("adds executable bits when helper exists but is not executable", () => {
23 if (process.platform === "win32") return;
24​
25 const dir = fs.mkdtempSync(path.join(os.tmpdir(), "pty-helper-test-"));
26 tempDirs.push(dir);
27 const helperPath = path.join(dir, "spawn-helper");
28 fs.writeFileSync(helperPath, "#!/bin/sh\nexit 0\n", "utf8");
29 fs.chmodSync(helperPath, 0o644);
30​
31 ensureNodePtySpawnHelperExecutable(helperPath);
32​
33 expect(fileMode(helperPath) & 0o111).toBe(0o111);
34 });
35​
36 it("keeps executable helper as executable", () => {
37 if (process.platform === "win32") return;
38​
39 const dir = fs.mkdtempSync(path.join(os.tmpdir(), "pty-helper-test-"));
40 tempDirs.push(dir);
41 const helperPath = path.join(dir, "spawn-helper");
42 fs.writeFileSync(helperPath, "#!/bin/sh\nexit 0\n", "utf8");
43 fs.chmodSync(helperPath, 0o755);
44​
45 ensureNodePtySpawnHelperExecutable(helperPath);
46​
47 expect(fileMode(helperPath) & 0o111).toBe(0o111);
48 });
49​
50 it("does not throw when helper path is missing", () => {
51 const missing = path.join(os.tmpdir(), `does-not-exist-${Date.now()}`);
52 expect(() => ensureNodePtySpawnHelperExecutable(missing)).not.toThrow();
53 });
54});