mcpStoreStatusList.test.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { describe, expect, it } from "vitest";
  2. import type { ZCodeMcpServer } from "@zcode/shared";
  3. import { mergeMcpServerStatusSnapshots } from "../src/store/mcpStoreStatusList.js";
  4. const server: ZCodeMcpServer = {
  5. config: { command: "node" },
  6. enabled: true,
  7. id: "zcodeagentmcp:demo",
  8. name: "demo",
  9. scope: "user",
  10. source: "zcodeagentmcp",
  11. status: "connecting",
  12. };
  13. describe("MCP store status diagnostics", () => {
  14. it("preserves structured diagnostics from the runtime snapshot", () => {
  15. expect(
  16. mergeMcpServerStatusSnapshots([server], {
  17. demo: {
  18. error: "raw english error",
  19. failureKind: "server_unavailable",
  20. serverRequestId: "req-1000",
  21. status: "failed",
  22. toolCount: 0,
  23. transport: "http",
  24. updatedAt: "2026-08-22T00:00:00.000Z",
  25. },
  26. })[0],
  27. ).toMatchObject({
  28. error: "raw english error",
  29. failureKind: "server_unavailable",
  30. serverRequestId: "req-1000",
  31. status: "error",
  32. });
  33. });
  34. it("uses status_unavailable without inventing a request id for a missing row", () => {
  35. expect(mergeMcpServerStatusSnapshots([server], {})[0]).toMatchObject({
  36. failureKind: "status_unavailable",
  37. status: "error",
  38. });
  39. expect(mergeMcpServerStatusSnapshots([server], {})[0]).not.toHaveProperty("serverRequestId");
  40. });
  41. it("clears stale diagnostics when a later snapshot is connected", () => {
  42. const failedServer: ZCodeMcpServer = {
  43. ...server,
  44. error: "old error",
  45. failureKind: "server_unavailable",
  46. serverRequestId: "old-request",
  47. status: "error",
  48. };
  49. expect(
  50. mergeMcpServerStatusSnapshots([failedServer], {
  51. demo: {
  52. status: "connected",
  53. toolCount: 2,
  54. transport: "http",
  55. updatedAt: "2026-08-22T00:01:00.000Z",
  56. },
  57. })[0],
  58. ).toMatchObject({ status: "connected", toolCount: 2 });
  59. expect(
  60. mergeMcpServerStatusSnapshots([failedServer], {
  61. demo: {
  62. status: "connected",
  63. toolCount: 2,
  64. transport: "http",
  65. updatedAt: "2026-08-22T00:01:00.000Z",
  66. },
  67. })[0],
  68. ).not.toHaveProperty("serverRequestId", "old-request");
  69. });
  70. });