@@ -1,7 +1,35 @@
1-import { describe, expect, it } from "bun:test";
1+import { describe, expect, it, mock } from "bun:test";
22 import { shellTool } from "./shell.ts";
33
4-describe.skipIf(!process.stdin.isTTY)("shellTool", () => {
4+describe("shellTool", () => {
5+ it("appends a newline to streamed output when the command does not print one", async () => {
6+ const onOutput = mock(() => {});
7+
8+ const result = await shellTool.execute({
9+ command: "printf ok",
10+ timeout: 30_000,
11+ onOutput,
12+ });
13+
14+ expect(result.stdout).toBe("ok");
15+ expect(onOutput.mock.calls.map(([chunk]) => chunk).join("")).toBe("ok\n");
16+ });
17+
18+ it("does not duplicate a trailing newline in streamed output", async () => {
19+ const onOutput = mock(() => {});
20+
21+ const result = await shellTool.execute({
22+ command: "printf 'ok\\n'",
23+ timeout: 30_000,
24+ onOutput,
25+ });
26+
27+ expect(result.stdout).toBe("ok");
28+ expect(onOutput.mock.calls.map(([chunk]) => chunk).join("")).toBe("ok\n");
29+ });
30+});
31+
32+describe.skipIf(!process.stdin.isTTY)("shellTool raw mode", () => {
533 it("preserves stdin raw mode if it was enabled", async () => {
634 // Set raw mode to true initially
735 process.stdin.setRawMode(true);