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

31 lines
907 B
TypeScript
Raw Normal View History

2026-01-23 06:26:30 +00:00
import { afterEach, expect, test, vi } from "vitest";
import { resetProcessRegistryForTests } from "./bash-process-registry";
import { createExecTool, setPtyModuleLoaderForTests } from "./bash-tools.exec";
2026-01-23 06:26:30 +00:00
afterEach(() => {
resetProcessRegistryForTests();
setPtyModuleLoaderForTests();
2026-01-23 06:26:30 +00:00
vi.clearAllMocks();
});
test("exec falls back when PTY spawn fails", async () => {
setPtyModuleLoaderForTests(async () => ({
2026-01-23 06:26:30 +00:00
spawn: () => {
const err = new Error("spawn EBADF");
(err as NodeJS.ErrnoException).code = "EBADF";
throw err;
},
}));
const tool = createExecTool({ allowBackground: false });
const result = await tool.execute("toolcall", {
command: "printf ok",
pty: true,
});
expect(result.details.status).toBe("completed");
const text = result.content?.[0]?.text ?? "";
expect(text).toContain("ok");
expect(text).toContain("PTY spawn failed");
});