Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

818 B
Raw Blame
import { describe, it, expect } from "vitest";
import { sanitizeToolId } from "../schemaCoercion.ts";

describe("sanitizeToolId", () => {
  it('sanitizes dots and colons to underscores: "call.abc:123" → "call_abc_123"', () => {
    expect(sanitizeToolId("call.abc:123")).toBe("call_abc_123");
  });

  it("generates a valid fallback ID for undefined input", () => {
    const result = sanitizeToolId(undefined);
    expect(result).toMatch(/^tool_[a-z0-9_]+$/);
  });

  it("generates a valid fallback ID for empty string input", () => {
    const result = sanitizeToolId("");
    expect(result).toMatch(/^tool_[a-z0-9_]+$/);
  });

  it("preserves already-valid IDs", () => {
    expect(sanitizeToolId("toolu_abc123")).toBe("toolu_abc123");
    expect(sanitizeToolId("call-xyz_789")).toBe("call-xyz_789");
  });
});