httpapi-reference.test.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 "@opencode-ai/core/global"
  5. import { resetDatabase } from "../fixture/db"
  6. import { disposeAllInstances, tmpdir } from "../fixture/fixture"
  7. afterEach(async () => {
  8. await disposeAllInstances()
  9. await resetDatabase()
  10. })
  11. describe("reference HttpApi", () => {
  12. test("lists usable references resolved in the server workspace", async () => {
  13. await using tmp = await tmpdir({
  14. config: {
  15. formatter: false,
  16. lsp: false,
  17. reference: {
  18. docs: "./docs",
  19. effect: { repository: "Effect-TS/effect", branch: "main" },
  20. bad: "not-a-repo",
  21. },
  22. },
  23. })
  24. const response = await Server.Default().app.request("/api/reference", {
  25. headers: { "x-opencode-directory": tmp.path },
  26. })
  27. expect(response.status).toBe(200)
  28. const body = await response.json()
  29. expect(body).toMatchObject({ location: { directory: tmp.path } })
  30. expect(body.data).toEqual([
  31. {
  32. name: "docs",
  33. path: path.join(tmp.path, "docs"),
  34. source: {
  35. type: "local",
  36. path: path.join(tmp.path, "docs"),
  37. },
  38. },
  39. {
  40. name: "effect",
  41. path: path.join(Global.Path.repos, "github.com", "Effect-TS", "effect"),
  42. source: {
  43. type: "git",
  44. repository: "Effect-TS/effect",
  45. branch: "main",
  46. },
  47. },
  48. ])
  49. })
  50. })