feat: add more tests for tool built-ins (#5)

This commit is contained in:
Charles Packer
2025-10-25 11:33:30 -07:00
committed by GitHub
parent dd773bf285
commit da2c50cbeb
19 changed files with 792 additions and 1 deletions

View File

@@ -0,0 +1,68 @@
import { describe, expect, test } from "bun:test";
import { bash } from "../../tools/impl/Bash";
import { bash_output } from "../../tools/impl/BashOutput";
import { kill_bash } from "../../tools/impl/KillBash";
describe("Bash background tools", () => {
test("starts background process and returns ID in text", async () => {
const result = await bash({
command: "echo 'test'",
description: "Test background",
run_in_background: true,
});
expect(result.content[0].text).toContain("background with ID:");
expect(result.content[0].text).toMatch(/bash_\d+/);
});
test("BashOutput retrieves output from background shell", async () => {
// Start background process
const startResult = await bash({
command: "echo 'background output'",
description: "Test background",
run_in_background: true,
});
// Extract bash_id from the response text
const match = startResult.content[0].text.match(/bash_(\d+)/);
expect(match).toBeDefined();
const bashId = `bash_${match![1]}`;
// Wait for command to complete
await new Promise((resolve) => setTimeout(resolve, 200));
// Retrieve output
const outputResult = await bash_output({ bash_id: bashId });
expect(outputResult.message).toContain("background output");
});
test("BashOutput handles non-existent bash_id gracefully", async () => {
const result = await bash_output({ bash_id: "nonexistent" });
expect(result.message).toContain("No background process found");
});
test("KillBash terminates background process", async () => {
// Start long-running process
const startResult = await bash({
command: "sleep 10",
description: "Test kill",
run_in_background: true,
});
const match = startResult.content[0].text.match(/bash_(\d+)/);
const bashId = `bash_${match![1]}`;
// Kill it (KillBash uses shell_id parameter)
const killResult = await kill_bash({ shell_id: bashId });
expect(killResult.killed).toBe(true);
});
test("KillBash handles non-existent shell_id", async () => {
const result = await kill_bash({ shell_id: "nonexistent" });
expect(result.killed).toBe(false);
});
});