bash.test.ts 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. await bash.execute(
  20. {
  21. command: "cd foo/bar && ls",
  22. description: "List files in foo/bar",
  23. },
  24. ctx,
  25. )
  26. })
  27. })
  28. test("cd ../ should fail", async () => {
  29. await App.provide({ cwd: projectRoot }, async () => {
  30. expect(
  31. bash.execute(
  32. {
  33. command: "cd ../",
  34. description: "Try to cd to parent directory",
  35. },
  36. ctx,
  37. ),
  38. ).rejects.toThrow()
  39. })
  40. })
  41. })