feat: add more tests for tool built-ins (#5)
This commit is contained in:
68
src/tests/tools/bash-background.test.ts
Normal file
68
src/tests/tools/bash-background.test.ts
Normal 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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user