KeiSeiKit-1.0/_ts_packages/packages/mcp-server/test/errors.test.ts
Parfii-bot c21943e40b feat(ts-packages): 6 TS packages — MCP server + 5 external-API adapters
Total 1465 LOC + 616 test LOC, 78/78 tests pass.
- @keisei/mcp-server (25 tests) — Rust-CLI bridge via execa, stdio+HTTP, HMAC auth, kei() meta-tool
- @keisei/telegram-adapter (16 tests) — grammy Bot, 7 tools
- @keisei/recall-adapter (8 tests) — Zoom via Recall.ai, 5 tools
- @keisei/grok-adapter (6 tests) — xAI OpenAI-compatible, 2 tools
- @keisei/gmail-adapter (11 tests) — googleapis OAuth2, 6 tools (new — LBM gap)
- @keisei/youtube-adapter (12 tests) — YouTube Data API v3, 5 tools (new — LBM gap)

RULE 0.2 exception #4 (TS for MCP/API layer documented in _ts_packages/README.md).
RULE 0.8 — env vars only (TELEGRAM_BOT_TOKEN, XAI_API_KEY, GMAIL_*, YOUTUBE_API_KEY).
Strict TypeScript: strict + exactOptionalPropertyTypes + noUncheckedIndexedAccess.
Genesis-scan clean (0 hits).
2026-04-22 12:45:19 +08:00

54 lines
1.5 KiB
TypeScript

import { describe, it, expect } from "vitest";
import {
AuthError,
McpServerError,
RustBridgeError,
SchemaError,
ToolNotFoundError,
TimeoutError,
isMcpError,
toErrorPayload,
} from "../src/errors.js";
describe("errors hierarchy", () => {
it("AuthError has JSON-RPC code -32001", () => {
const e = new AuthError();
expect(e).toBeInstanceOf(McpServerError);
expect(e.code).toBe(-32001);
expect(isMcpError(e)).toBe(true);
});
it("ToolNotFoundError carries the tool name in data", () => {
const e = new ToolNotFoundError("kei-foo");
expect(e.code).toBe(-32601);
expect((e.data as { tool: string }).tool).toBe("kei-foo");
});
it("RustBridgeError prefixes message", () => {
const e = new RustBridgeError("spawn failed");
expect(e.message).toContain("rust bridge");
});
it("SchemaError has JSON-RPC code -32602", () => {
const e = new SchemaError("bad input");
expect(e.code).toBe(-32602);
});
it("TimeoutError records ms and tool", () => {
const e = new TimeoutError("kei-ledger", 1234);
expect(e.code).toBe(-32003);
expect((e.data as { ms: number }).ms).toBe(1234);
});
it("toErrorPayload handles MCP errors", () => {
const p = toErrorPayload(new AuthError("nope"));
expect(p.code).toBe(-32001);
expect(p.message).toBe("nope");
});
it("toErrorPayload handles plain Errors", () => {
const p = toErrorPayload(new Error("boom"));
expect(p.code).toBe(-32000);
expect(p.message).toBe("boom");
});
});