// Unit tests for context7_bridge.ts pure helpers (slice 2 backfill). // Run: bun test mcp-server/context7_bridge.test.ts // // The HTTP-bound functions (resolveLibraryId, fetchDocsText, // getCurrent) need network access and are exercised by the hybrid // fixture on the auditor side — not re-tested here to avoid // duplicating what's already integration-covered. This file only // exercises the pure, deterministic helpers. import { test, expect } from "bun:test"; import { normalizeTool, hashContent } from "./context7_bridge.ts"; test("normalizeTool lowercases + trims", () => { expect(normalizeTool("Docker")).toBe("docker"); expect(normalizeTool(" TERRAFORM ")).toBe("terraform"); expect(normalizeTool("Next.JS")).toBe("next.js"); }); test("normalizeTool preserves internal chars + dashes", () => { expect(normalizeTool("react-dom")).toBe("react-dom"); expect(normalizeTool("@anthropic/sdk")).toBe("@anthropic/sdk"); }); test("hashContent is deterministic", () => { const a = hashContent("hello world"); const b = hashContent("hello world"); expect(a).toBe(b); }); test("hashContent is sensitive to single-char change", () => { const a = hashContent("docker run -it ubuntu bash"); const b = hashContent("docker run -it ubuntu bashh"); // extra h expect(a).not.toBe(b); }); test("hashContent returns 16 hex chars", () => { const h = hashContent("any input"); expect(h).toMatch(/^[0-9a-f]{16}$/); }); test("hashContent differs for empty vs whitespace", () => { const a = hashContent(""); const b = hashContent(" "); expect(a).not.toBe(b); });