KeiSeiKit-1.0/_ts_packages/packages/gmail-adapter/test/tools.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

43 lines
1.6 KiB
TypeScript

import { describe, it, expect, vi } from "vitest";
import { GmailClient, type GmailSurface } from "../src/client.js";
import { buildGmailTools } from "../src/tools.js";
function mkSurface(): GmailSurface {
return {
list: vi.fn(async () => [{ id: "m1" }]),
get: vi.fn(async () => ({ id: "m1", snippet: "hello", payload: { headers: [] } })),
modify: vi.fn(async () => undefined),
trash: vi.fn(async () => undefined),
};
}
describe("gmail tool surface", () => {
it("registers 6 tools", () => {
const c = new GmailClient({ clientId: "", clientSecret: "", refreshToken: "", gmailSurface: mkSurface() });
const names = buildGmailTools(c).map((t) => t.name);
expect(names).toEqual([
"gmail_list_unread",
"gmail_get_message",
"gmail_search",
"gmail_label_message",
"gmail_archive",
"gmail_trash",
]);
});
it("gmail_list_unread formats empty list", async () => {
const surface: GmailSurface = { ...mkSurface(), list: vi.fn(async () => []) };
const c = new GmailClient({ clientId: "", clientSecret: "", refreshToken: "", gmailSurface: surface });
const tool = buildGmailTools(c).find((t) => t.name === "gmail_list_unread");
const out = await tool!.handler({});
expect(out).toBe("No messages.");
});
it("gmail_trash returns ok string", async () => {
const surface = mkSurface();
const c = new GmailClient({ clientId: "", clientSecret: "", refreshToken: "", gmailSurface: surface });
const tool = buildGmailTools(c).find((t) => t.name === "gmail_trash");
const out = await tool!.handler({ id: "m1" });
expect(out).toContain("trashed m1");
});
});