2
0

bash.test.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. abort: AbortSignal.any([]),
  11. metadata: () => {},
  12. }
  13. const bash = await BashTool.init()
  14. const projectRoot = path.join(__dirname, "../..")
  15. Log.init({ print: false })
  16. describe("tool.bash", () => {
  17. test("basic", async () => {
  18. await App.provide({ cwd: projectRoot }, async () => {
  19. const result = await bash.execute(
  20. {
  21. command: "echo 'test'",
  22. description: "Echo test message",
  23. },
  24. ctx,
  25. )
  26. expect(result.metadata.exit).toBe(0)
  27. expect(result.metadata.stdout).toContain("test")
  28. })
  29. })
  30. test("cd ../ should fail outside of project root", async () => {
  31. await App.provide({ cwd: projectRoot }, async () => {
  32. await expect(
  33. bash.execute(
  34. {
  35. command: "cd ../",
  36. description: "Try to cd to parent directory",
  37. },
  38. ctx,
  39. ),
  40. ).rejects.toThrow("This command references paths outside of")
  41. })
  42. })
  43. })