Files
openclaw/src/agents/bash-tools.exec.pty-fallback.test.ts

30 lines
897 B
TypeScript
Raw Normal View History

2026-01-23 06:26:30 +00:00
import { afterEach, expect, test, vi } from "vitest";
2026-02-17 14:33:38 +09:00
import { resetProcessRegistryForTests } from "./bash-process-registry.js";
import { createExecTool } from "./bash-tools.exec.js";
vi.mock("@lydell/node-pty", () => ({
spawn: () => {
const err = new Error("spawn EBADF");
(err as NodeJS.ErrnoException).code = "EBADF";
throw err;
},
}));
2026-01-23 06:26:30 +00:00
afterEach(() => {
resetProcessRegistryForTests();
vi.clearAllMocks();
});
test("exec falls back when PTY spawn fails", async () => {
const tool = createExecTool({ allowBackground: false, security: "full", ask: "off" });
2026-01-23 06:26:30 +00:00
const result = await tool.execute("toolcall", {
command: "printf ok",
pty: true,
});
expect(result.details.status).toBe("completed");
2026-02-17 15:49:00 +09:00
const text = result.content?.find((item) => item.type === "text")?.text ?? "";
2026-01-23 06:26:30 +00:00
expect(text).toContain("ok");
expect(text).toContain("PTY spawn failed");
});