sdk-v1-smoke.test.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Smoke test: v1 SDK (the plugin contract) can actually reach core endpoints
  2. // against the current server. v1 generation has been frozen since #5216
  3. // (2025-12-07) so types may be stale, but runtime calls should still work
  4. // for endpoints the v1 SDK was generated against.
  5. import { afterEach, describe, expect, test } from "bun:test"
  6. import { createOpencodeClient } from "@kirincode-ai/sdk"
  7. import { Server } from "../../src/server/server"
  8. import { tmpdir, disposeAllInstances } from "../fixture/fixture"
  9. import { resetDatabase } from "../fixture/db"
  10. afterEach(async () => {
  11. await disposeAllInstances()
  12. await resetDatabase()
  13. })
  14. function client(directory: string) {
  15. return createOpencodeClient({
  16. baseUrl: "http://test",
  17. directory,
  18. fetch: ((req: Request) => Server.Default().app.fetch(req)) as unknown as typeof fetch,
  19. })
  20. }
  21. describe("v1 SDK runtime smoke", () => {
  22. test("session.list reaches the server and returns 200", async () => {
  23. await using tmp = await tmpdir({ git: true, config: { formatter: false, lsp: false } })
  24. const sdk = client(tmp.path)
  25. const result = await sdk.session.list()
  26. expect(result.error).toBeUndefined()
  27. expect(Array.isArray(result.data)).toBe(true)
  28. })
  29. test("path.get reaches the server and returns 200", async () => {
  30. await using tmp = await tmpdir({ git: true, config: { formatter: false, lsp: false } })
  31. const sdk = client(tmp.path)
  32. const result = await sdk.path.get()
  33. expect(result.error).toBeUndefined()
  34. expect(result.data).toBeDefined()
  35. })
  36. test("config.get reaches the server and returns 200", async () => {
  37. await using tmp = await tmpdir({ git: true, config: { formatter: false, lsp: false } })
  38. const sdk = client(tmp.path)
  39. const result = await sdk.config.get()
  40. expect(result.error).toBeUndefined()
  41. expect(result.data).toBeDefined()
  42. })
  43. test("session 404: result-tuple path returns the error body", async () => {
  44. await using tmp = await tmpdir({ git: true, config: { formatter: false, lsp: false } })
  45. const sdk = client(tmp.path)
  46. const result = await sdk.session.get({ path: { id: "ses_no_such" } as never })
  47. expect(result.error).toBeDefined()
  48. // wire body for 404 is NamedError-shaped
  49. expect(result.error).toMatchObject({ name: "NotFoundError" })
  50. })
  51. })