Elffuss BraidHub

kikocis/continue public

main · 3.2 KiBRawPermalink
1import { runTerminalCommandTool } from "./runTerminalCommand.js";
2
3describe("runTerminalCommandTool", () => {
4 const isWindows = process.platform === "win32";
5 const isMac = process.platform === "darwin";
6 const isLinux = process.platform === "linux";
7
8 describe("basic platform-specific terminal execution", () => {
9 it("should execute a simple echo command", async () => {
10 let command: string;
11 let expectedOutput: string;
12
13 if (isWindows) {
14 command = 'Write-Output "hello world"';
15 expectedOutput = "hello world";
16 } else {
17 command = 'echo "hello world"';
18 expectedOutput = "hello world";
19 }
20
21 const result = await runTerminalCommandTool.run({ command });
22 expect(result.trim()).toBe(expectedOutput);
23 });
24
25 it("should get current directory", async () => {
26 let command: string;
27
28 if (isWindows) {
29 command = "Get-Location | Select-Object -ExpandProperty Path";
30 } else {
31 command = "pwd";
32 }
33
34 const result = await runTerminalCommandTool.run({ command });
35
36 if (isWindows) {
37 // Windows paths like C:\path\to\dir
38 expect(result.trim()).toMatch(/^[A-Za-z]:\\.*/);
39 } else {
40 // Unix paths like /path/to/dir
41 expect(result.trim()).toMatch(/^\/.*$/);
42 }
43 });
44
45 it("should list directory contents", async () => {
46 let command: string;
47
48 if (isWindows) {
49 command = "Get-ChildItem | Select-Object -ExpandProperty Name";
50 } else {
51 command = "ls";
52 }
53
54 const result = await runTerminalCommandTool.run({ command });
55 // Should return some directory content (not empty)
56 expect(result.length).toBeGreaterThan(0);
57 });
58
59 it("should handle command that produces version info", async () => {
60 // Node.js should be available on all platforms in CI
61 const command = "node --version";
62 const result = await runTerminalCommandTool.run({ command });
63
64 // Should contain version number (starts with v)
65 expect(result.trim()).toMatch(/^v\d+\.\d+\.\d+/);
66 });
67 });
68
69 describe("basic error handling", () => {
70 it("should handle non-existent commands", async () => {
71 const command = "definitely-not-a-real-command-xyz123";
72
73 await expect(runTerminalCommandTool.run({ command })).rejects.toMatch(
74 /Error \(exit code|Command timed out|not found|not recognized/,
75 );
76 });
77 });
78
79 describe("platform-specific features", () => {
80 if (isWindows) {
81 it("should work with Windows commands", async () => {
82 const result = await runTerminalCommandTool.run({
83 command: "Write-Output $env:OS",
84 });
85 expect(result.trim()).toBe("Windows_NT");
86 });
87 }
88
89 if (isMac) {
90 it("should work with macOS commands", async () => {
91 const result = await runTerminalCommandTool.run({
92 command: "uname -s",
93 });
94 expect(result.trim()).toBe("Darwin");
95 });
96 }
97
98 if (isLinux) {
99 it("should work with Linux commands", async () => {
100 const result = await runTerminalCommandTool.run({
101 command: "uname -s",
102 });
103 expect(result.trim()).toBe("Linux");
104 });
105 }
106 });
107});