httpapi-reference.test.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. references: {
  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. description: null,
  35. hidden: null,
  36. source: {
  37. type: "local",
  38. path: path.join(tmp.path, "docs"),
  39. description: null,
  40. hidden: null,
  41. },
  42. },
  43. {
  44. name: "effect",
  45. path: path.join(Global.Path.repos, "github.com", "Effect-TS", "effect"),
  46. description: null,
  47. hidden: null,
  48. source: {
  49. type: "git",
  50. repository: "Effect-TS/effect",
  51. branch: "main",
  52. description: null,
  53. hidden: null,
  54. },
  55. },
  56. ])
  57. })
  58. })