|
|
@@ -231,6 +231,49 @@ describe("tool.bash permissions", () => {
|
|
|
},
|
|
|
})
|
|
|
})
|
|
|
+
|
|
|
+ test("matches redirects in permission pattern", async () => {
|
|
|
+ await using tmp = await tmpdir({ git: true })
|
|
|
+ await Instance.provide({
|
|
|
+ directory: tmp.path,
|
|
|
+ fn: async () => {
|
|
|
+ const bash = await BashTool.init()
|
|
|
+ const requests: Array<Omit<PermissionNext.Request, "id" | "sessionID" | "tool">> = []
|
|
|
+ const testCtx = {
|
|
|
+ ...ctx,
|
|
|
+ ask: async (req: Omit<PermissionNext.Request, "id" | "sessionID" | "tool">) => {
|
|
|
+ requests.push(req)
|
|
|
+ },
|
|
|
+ }
|
|
|
+ await bash.execute({ command: "cat > /tmp/output.txt", description: "Redirect ls output" }, testCtx)
|
|
|
+ const bashReq = requests.find((r) => r.permission === "bash")
|
|
|
+ expect(bashReq).toBeDefined()
|
|
|
+ expect(bashReq!.patterns).toContain("cat > /tmp/output.txt")
|
|
|
+ },
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ test("always pattern has space before wildcard to not include different commands", async () => {
|
|
|
+ await using tmp = await tmpdir({ git: true })
|
|
|
+ await Instance.provide({
|
|
|
+ directory: tmp.path,
|
|
|
+ fn: async () => {
|
|
|
+ const bash = await BashTool.init()
|
|
|
+ const requests: Array<Omit<PermissionNext.Request, "id" | "sessionID" | "tool">> = []
|
|
|
+ const testCtx = {
|
|
|
+ ...ctx,
|
|
|
+ ask: async (req: Omit<PermissionNext.Request, "id" | "sessionID" | "tool">) => {
|
|
|
+ requests.push(req)
|
|
|
+ },
|
|
|
+ }
|
|
|
+ await bash.execute({ command: "ls -la", description: "List" }, testCtx)
|
|
|
+ const bashReq = requests.find((r) => r.permission === "bash")
|
|
|
+ expect(bashReq).toBeDefined()
|
|
|
+ const pattern = bashReq!.always[0]
|
|
|
+ expect(pattern).toBe("ls *")
|
|
|
+ },
|
|
|
+ })
|
|
|
+ })
|
|
|
})
|
|
|
|
|
|
describe("tool.bash truncation", () => {
|