5ecd041bfe
- Fixed bash interceptor to check both raw and cwd-normalized commands, catching commands hidden behind leading `cd ... &&` wrappers. - Fixed LSP client shutdown to await graceful shutdown with a 5s timeout before killing the process, and parallelized `shutdownAll` via `Promise.allSettled`. - Fixed concurrent bash command tracking by replacing a single abort controller with a Set, preventing premature cancellation of parallel commands. - Removed `./hooks` and `./hooks/*` export entries from the coding-agent package exports map. - Updated pinned Rust nightly toolchain from `nightly-2026-03-27` to `nightly-2026-04-29` in `rust-toolchain.toml` and CI workflow. - Replaced custom already-published detection in `ci-release-publish.ts` with `bun publish --tolerate-republish` flag.
59 lines
1.7 KiB
TypeScript
59 lines
1.7 KiB
TypeScript
import { describe, expect, it } from "bun:test";
|
|
import type { AgentToolContext } from "@oh-my-pi/pi-agent-core";
|
|
import type { BashInterceptorRule } from "../../src/config/settings-schema";
|
|
import type { ToolSession } from "../../src/tools";
|
|
import { BashTool } from "../../src/tools/bash";
|
|
|
|
function createBashTool(rules: BashInterceptorRule[]): BashTool {
|
|
const session = {
|
|
settings: {
|
|
get(key: string) {
|
|
if (key === "bashInterceptor.enabled") return true;
|
|
if (key === "async.enabled") return false;
|
|
if (key === "bash.autoBackground.enabled") return false;
|
|
if (key === "bash.autoBackground.thresholdMs") return 60_000;
|
|
return undefined;
|
|
},
|
|
getBashInterceptorRules() {
|
|
return rules;
|
|
},
|
|
},
|
|
} as unknown as ToolSession;
|
|
|
|
return new BashTool(session);
|
|
}
|
|
|
|
describe("BashTool interception", () => {
|
|
it("checks the original command before leading cd normalization", async () => {
|
|
const tool = createBashTool([
|
|
{
|
|
pattern: "^\\s*cd\\s+",
|
|
tool: "bash",
|
|
message: "Do not hide directory changes in the command string.",
|
|
},
|
|
]);
|
|
|
|
await expect(
|
|
tool.execute("tool-call", { command: "cd packages/coding-agent && echo ok" }, undefined, undefined, {
|
|
toolNames: ["bash"],
|
|
} as AgentToolContext),
|
|
).rejects.toThrow("Do not hide directory changes");
|
|
});
|
|
|
|
it("checks the cwd-normalized command after leading cd normalization", async () => {
|
|
const tool = createBashTool([
|
|
{
|
|
pattern: "^\\s*cat\\s+",
|
|
tool: "read",
|
|
message: "Use read instead.",
|
|
},
|
|
]);
|
|
|
|
await expect(
|
|
tool.execute("tool-call", { command: "cd packages/coding-agent && cat package.json" }, undefined, undefined, {
|
|
toolNames: ["read"],
|
|
} as AgentToolContext),
|
|
).rejects.toThrow("Use read instead");
|
|
});
|
|
});
|