bash.test.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { describe, expect, test } from "bun:test"
  2. import { App } from "../../src/app/app"
  3. import path from "path"
  4. import { BashTool } from "../../src/tool/bash"
  5. import { Log } from "../../src/util/log"
  6. const ctx = {
  7. sessionID: "test",
  8. messageID: "",
  9. toolCallID: "",
  10. agent: "build",
  11. abort: AbortSignal.any([]),
  12. metadata: () => {},
  13. }
  14. const bash = await BashTool.init()
  15. const projectRoot = path.join(__dirname, "../..")
  16. Log.init({ print: false })
  17. describe("tool.bash", () => {
  18. test("basic", async () => {
  19. await App.provide({ cwd: projectRoot }, async () => {
  20. const result = await bash.execute(
  21. {
  22. command: "echo 'test'",
  23. description: "Echo test message",
  24. },
  25. ctx,
  26. )
  27. expect(result.metadata.exit).toBe(0)
  28. expect(result.metadata.output).toContain("test")
  29. })
  30. })
  31. test("cd ../ should fail outside of project root", async () => {
  32. await App.provide({ cwd: projectRoot }, async () => {
  33. expect(
  34. bash.execute(
  35. {
  36. command: "cd ../",
  37. description: "Try to cd to parent directory",
  38. },
  39. ctx,
  40. ),
  41. ).rejects.toThrow("This command references paths outside of")
  42. })
  43. })
  44. })