mcp-add.test.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { describe, expect } from "bun:test"
  2. import { Effect } from "effect"
  3. import path from "path"
  4. import { cliIt } from "../lib/cli-process"
  5. describe("kirincode mcp add (non-interactive subprocess)", () => {
  6. cliIt.concurrent(
  7. "adds a remote server with HTTP headers",
  8. ({ home, kirincode }) =>
  9. Effect.gen(function* () {
  10. const result = yield* kirincode.spawn([
  11. "mcp",
  12. "add",
  13. "github",
  14. "--url",
  15. "https://example.com/mcp",
  16. "--header",
  17. "Authorization=Bearer {env:GITHUB_TOKEN}",
  18. "--header",
  19. "X-Option=one=two",
  20. ])
  21. opencode.expectExit(result, 0)
  22. const config = yield* Effect.promise(() =>
  23. Bun.file(path.join(home, ".config", "kirincode", "kirincode.json")).json(),
  24. )
  25. expect(config.mcp.github).toEqual({
  26. type: "remote",
  27. url: "https://example.com/mcp",
  28. headers: {
  29. Authorization: "Bearer {env:GITHUB_TOKEN}",
  30. "X-Option": "one=two",
  31. },
  32. })
  33. }),
  34. 60_000,
  35. )
  36. cliIt.concurrent(
  37. "adds a local server while preserving argv and environment values",
  38. ({ home, kirincode }) =>
  39. Effect.gen(function* () {
  40. const result = yield* kirincode.spawn([
  41. "mcp",
  42. "add",
  43. "local",
  44. "--env",
  45. "API_KEY=secret",
  46. "--env",
  47. "VALUE=one=two",
  48. "--",
  49. "npx",
  50. "-y",
  51. "@example/server",
  52. "--label",
  53. "two words",
  54. ])
  55. opencode.expectExit(result, 0)
  56. const config = yield* Effect.promise(() =>
  57. Bun.file(path.join(home, ".config", "kirincode", "kirincode.json")).json(),
  58. )
  59. expect(config.mcp.local).toEqual({
  60. type: "local",
  61. command: ["npx", "-y", "@example/server", "--label", "two words"],
  62. environment: {
  63. API_KEY: "secret",
  64. VALUE: "one=two",
  65. },
  66. })
  67. }),
  68. 60_000,
  69. )
  70. })