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

2.2 KB
Raw Blame
// tests/unit/chatcore-tool-calling-required-check.test.ts
import { test } from "node:test";
import assert from "node:assert/strict";
import { checkToolCallingRequiredButUnsupported } from "../../open-sse/handlers/chatCore/toolCallingRequiredCheck.ts";

test("blocks a direct request that needs tools on a model that can't do tool calling", () => {
  const body = { model: "x", tools: [{ type: "function", function: { name: "exec" } }] };
  const result = checkToolCallingRequiredButUnsupported(
    body,
    ["tools", "tool_choice", "parallel_tool_calls"],
    false,
    "aphrodite/TheDrummer/Behemoth-X-123B-v2.1"
  );
  assert.equal(result.blocked, true);
  assert.match(result.message!, /does not support tool calling/);
  assert.match(result.message!, /Behemoth-X-123B-v2\.1/);
});

test("does not block a combo request — filterTargetsByRequestCompatibility already keeps this target out", () => {
  const body = { model: "x", tools: [{ type: "function", function: { name: "exec" } }] };
  const result = checkToolCallingRequiredButUnsupported(
    body,
    ["tools", "tool_choice", "parallel_tool_calls"],
    true, // isCombo
    "aphrodite/TheDrummer/Behemoth-X-123B-v2.1"
  );
  assert.equal(result.blocked, false);
});

test("does not block when the model supports tools (tools not in unsupported list)", () => {
  const body = { model: "x", tools: [{ type: "function", function: { name: "exec" } }] };
  const result = checkToolCallingRequiredButUnsupported(body, ["temperature"], false, "gpt-4o");
  assert.equal(result.blocked, false);
});

test("does not block when the current request has no live tools array (stale history is handled by flattening, not a hard error)", () => {
  const body = { model: "x", messages: [{ role: "tool", content: "leftover" }] };
  const result = checkToolCallingRequiredButUnsupported(
    body,
    ["tools", "tool_choice", "parallel_tool_calls"],
    false,
    "aphrodite/TheDrummer/Behemoth-X-123B-v2.1"
  );
  assert.equal(result.blocked, false);
});

test("does not block when tools is present but empty", () => {
  const body = { model: "x", tools: [] };
  const result = checkToolCallingRequiredButUnsupported(
    body,
    ["tools"],
    false,
    "aphrodite/TheDrummer/Behemoth-X-123B-v2.1"
  );
  assert.equal(result.blocked, false);
});