tool.test.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { describe, expect, test } from "bun:test"
  2. import { App } from "../../src/app/app"
  3. import { GlobTool } from "../../src/tool/glob"
  4. import { ls } from "../../src/tool/ls"
  5. describe("tool.glob", () => {
  6. test("truncate", async () => {
  7. await App.provide({ directory: process.cwd() }, async () => {
  8. let result = await GlobTool.execute(
  9. {
  10. pattern: "./node_modules/**/*",
  11. },
  12. {
  13. toolCallId: "test",
  14. messages: [],
  15. },
  16. )
  17. expect(result.metadata.truncated).toBe(true)
  18. })
  19. })
  20. test("basic", async () => {
  21. await App.provide({ directory: process.cwd() }, async () => {
  22. let result = await GlobTool.execute(
  23. {
  24. pattern: "*.json",
  25. },
  26. {
  27. toolCallId: "test",
  28. messages: [],
  29. },
  30. )
  31. expect(result.metadata).toMatchObject({
  32. truncated: false,
  33. count: 2,
  34. })
  35. })
  36. })
  37. })
  38. describe("tool.ls", () => {
  39. test("basic", async () => {
  40. const result = await App.provide({ directory: process.cwd() }, async () => {
  41. return await ls.execute(
  42. {
  43. path: "./example",
  44. },
  45. {
  46. toolCallId: "test",
  47. messages: [],
  48. },
  49. )
  50. })
  51. expect(result.output).toMatchSnapshot()
  52. })
  53. })