bash.test.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { describe, expect, test } from "bun:test"
  2. import path from "path"
  3. import { BashTool } from "../../src/tool/bash"
  4. import { Instance } from "../../src/project/instance"
  5. const ctx = {
  6. sessionID: "test",
  7. messageID: "",
  8. toolCallID: "",
  9. agent: "build",
  10. abort: AbortSignal.any([]),
  11. metadata: () => {},
  12. }
  13. const bash = await BashTool.init()
  14. const projectRoot = path.join(__dirname, "../..")
  15. describe("tool.bash", () => {
  16. test("basic", async () => {
  17. await Instance.provide({
  18. directory: projectRoot,
  19. fn: 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. })
  32. test("cd ../ should fail outside of project root", async () => {
  33. await Instance.provide({
  34. directory: projectRoot,
  35. fn: async () => {
  36. expect(
  37. bash.execute(
  38. {
  39. command: "cd ../",
  40. description: "Try to cd to parent directory",
  41. },
  42. ctx,
  43. ),
  44. ).rejects.toThrow("This command references paths outside of")
  45. },
  46. })
  47. })
  48. })