read.test.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { describe, expect, test } from "bun:test"
  2. import path from "path"
  3. import { ReadTool } from "../../src/tool/read"
  4. import { Instance } from "../../src/project/instance"
  5. import { tmpdir } from "../fixture/fixture"
  6. const ctx = {
  7. sessionID: "test",
  8. messageID: "",
  9. callID: "",
  10. agent: "build",
  11. abort: AbortSignal.any([]),
  12. metadata: () => {},
  13. }
  14. describe("tool.read env file blocking", () => {
  15. test.each([
  16. [".env", true],
  17. [".env.local", true],
  18. [".env.production", true],
  19. [".env.sample", false],
  20. [".env.example", false],
  21. [".envrc", false],
  22. ["environment.ts", false],
  23. ])("%s blocked=%s", async (filename, blocked) => {
  24. await using tmp = await tmpdir({
  25. init: (dir) => Bun.write(path.join(dir, filename), "content"),
  26. })
  27. await Instance.provide({
  28. directory: tmp.path,
  29. fn: async () => {
  30. const read = await ReadTool.init()
  31. const promise = read.execute({ filePath: path.join(tmp.path, filename) }, ctx)
  32. if (blocked) {
  33. await expect(promise).rejects.toThrow("blocked")
  34. } else {
  35. expect((await promise).output).toContain("content")
  36. }
  37. },
  38. })
  39. })
  40. })