ae1650d689
- Renamed the `find` and `search` tools to `glob` and `grep` respectively across the codebase to improve command clarity. - Implemented full-stack support for the renamed tools, including CLI arguments, system prompts, SDK exports, and tool registration. - Added automated migration logic in `settings` to transform legacy `find` and `search` configuration keys to their new equivalents. - Updated the `collab-web` renderer registry to ensure backwards compatibility with legacy tool outputs.
60 lines
2.2 KiB
TypeScript
60 lines
2.2 KiB
TypeScript
import { describe, expect, it } from "bun:test";
|
|
import type { ToolSession } from "@oh-my-pi/pi-coding-agent/tools";
|
|
import { BashTool } from "@oh-my-pi/pi-coding-agent/tools/bash";
|
|
|
|
function makeSession(): ToolSession {
|
|
return {
|
|
cwd: "/tmp",
|
|
hasUI: false,
|
|
skills: [],
|
|
getSessionFile: () => null,
|
|
settings: {
|
|
get(key: string) {
|
|
if (key === "async.enabled") return false;
|
|
if (key === "bash.autoBackground.enabled") return false;
|
|
if (key === "bash.autoBackground.thresholdMs") return 60_000;
|
|
if (key === "bashInterceptor.enabled") return false;
|
|
if (key === "bash.stripTrailingHeadTail") return false;
|
|
if (key === "astGrep.enabled") return false;
|
|
if (key === "astEdit.enabled") return false;
|
|
if (key === "grep.enabled") return false;
|
|
if (key === "glob.enabled") return false;
|
|
return undefined;
|
|
},
|
|
getBashInterceptorRules() {
|
|
return [];
|
|
},
|
|
},
|
|
getClientBridge: () => undefined,
|
|
} as unknown as ToolSession;
|
|
}
|
|
|
|
describe("BashTool non-zero exit", () => {
|
|
it("resolves with an error result carrying execution details instead of throwing", async () => {
|
|
const tool = new BashTool(makeSession());
|
|
const result = await tool.execute("call-fail", { command: "exit 3" });
|
|
|
|
// A completed command that failed is a non-throwing error result so the
|
|
// renderer keeps the wall time / timeout / exit-code footer.
|
|
expect(result.isError).toBe(true);
|
|
expect(result.details?.exitCode).toBe(3);
|
|
expect(result.details?.timeoutSeconds).toBe(300);
|
|
expect(typeof result.details?.wallTimeMs).toBe("number");
|
|
|
|
// The LLM-facing text still states the exit code verbatim.
|
|
const text = result.content.find(c => c.type === "text")?.text ?? "";
|
|
expect(text).toContain("Command exited with code 3");
|
|
});
|
|
|
|
it("returns a success result with no exit-code detail for a zero exit", async () => {
|
|
const tool = new BashTool(makeSession());
|
|
const result = await tool.execute("call-ok", { command: "printf hi" });
|
|
|
|
expect(result.isError).toBeUndefined();
|
|
expect(result.details?.exitCode).toBeUndefined();
|
|
const text = result.content.find(c => c.type === "text")?.text ?? "";
|
|
expect(text).toContain("hi");
|
|
expect(text).not.toContain("Command exited with code");
|
|
});
|
|
});
|