use treesitter to parse bash commands and catch commands that go outside of cwd (#1443)

This commit is contained in:
Dax
2025-07-30 20:57:52 -04:00
committed by GitHub
parent 3b7085ca28
commit 18888351e9
13 changed files with 226 additions and 59 deletions

View File

@@ -0,0 +1,44 @@
import { describe, expect, test } from "bun:test"
import { App } from "../../src/app/app"
import path from "path"
import { BashTool } from "../../src/tool/bash"
import { Log } from "../../src/util/log"
const ctx = {
sessionID: "test",
messageID: "",
abort: AbortSignal.any([]),
metadata: () => {},
}
const bash = await BashTool.init()
const projectRoot = path.join(__dirname, "../..")
Log.init({ print: false })
describe("tool.bash", () => {
test("basic", async () => {
await App.provide({ cwd: projectRoot }, async () => {
await bash.execute(
{
command: "cd foo/bar && ls",
description: "List files in foo/bar",
},
ctx,
)
})
})
test("cd ../ should fail", async () => {
await App.provide({ cwd: projectRoot }, async () => {
expect(
bash.execute(
{
command: "cd ../",
description: "Try to cd to parent directory",
},
ctx,
),
).rejects.toThrow()
})
})
})