httpapi-reference.test.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { afterEach, describe, expect, test } from "bun:test"
  2. import path from "path"
  3. import { Server } from "../../src/server/server"
  4. import { Global } from "@kirincode-ai/core/global"
  5. import { resetDatabase } from "../fixture/db"
  6. import { disposeAllInstances, tmpdir } from "../fixture/fixture"
  7. import { Effect } from "effect"
  8. import { pollWithTimeout } from "../lib/effect"
  9. afterEach(async () => {
  10. await disposeAllInstances()
  11. await resetDatabase()
  12. })
  13. describe("reference HttpApi", () => {
  14. test("lists usable references resolved in the server workspace", async () => {
  15. await using tmp = await tmpdir({
  16. config: {
  17. formatter: false,
  18. lsp: false,
  19. references: {
  20. docs: "./docs",
  21. effect: { repository: "Effect-TS/effect", branch: "main" },
  22. bad: "not-a-repo",
  23. },
  24. },
  25. })
  26. const body = await Effect.runPromise(
  27. pollWithTimeout(
  28. Effect.promise(async () => {
  29. const response = await Server.Default().app.request("/api/reference", {
  30. headers: { "x-opencode-directory": tmp.path },
  31. })
  32. expect(response.status).toBe(200)
  33. const body = await response.json()
  34. return body.data.length === 0 ? undefined : body
  35. }),
  36. "references were not loaded",
  37. ),
  38. )
  39. expect(body).toMatchObject({ location: { directory: tmp.path } })
  40. expect(body.data).toEqual([
  41. {
  42. name: "docs",
  43. path: path.join(tmp.path, "docs"),
  44. source: {
  45. type: "local",
  46. path: path.join(tmp.path, "docs"),
  47. },
  48. },
  49. {
  50. name: "effect",
  51. path: path.join(Global.Path.repos, "github.com", "Effect-TS", "effect"),
  52. source: {
  53. type: "git",
  54. repository: "Effect-TS/effect",
  55. branch: "main",
  56. },
  57. },
  58. ])
  59. })
  60. })