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.3 KB
Raw Blame
import test from "node:test";
import assert from "node:assert/strict";
import {
  getConnectionScopedEffortTiers,
  getThinkingCapabilityFields,
} from "../../src/app/api/v1/models/catalogHelpers.ts";

// The last positional argument of both helpers carries MODELS_DEV_EFFORT_TIERS_ENABLED,
// read once per catalog build by catalog.ts. Default (omitted/false) = previous behavior.

test("flag off: an empty declared list falls through to the synced tiers (previous behavior)", () => {
  const fields = getThinkingCapabilityFields("glm", "glm-5", true, [], false, [
    "low",
    "medium",
    "high",
  ]);
  assert.deepEqual(fields.effort_tiers, ["low", "medium", "high"]);

  const explicitOff = getThinkingCapabilityFields(
    "glm",
    "glm-5",
    true,
    [],
    false,
    ["low", "medium", "high"],
    false
  );
  assert.deepEqual(explicitOff, fields);
});

test("flag on: an empty declared list blocks synced tiers in the catalog", () => {
  const declared = getThinkingCapabilityFields(
    "glm",
    "glm-5",
    true,
    [],
    false,
    ["low", "medium", "high"],
    true
  );
  assert.equal(declared.supportsThinking, true);
  assert.equal("effort_tiers" in declared, false);
});

test("an absent list still falls through to the synced tiers; flag on narrows unknown names", () => {
  const synced = ["low", "medium", "high", "turbo", "max"];
  const off = getThinkingCapabilityFields(
    "anthropic",
    "claude-haiku-5-5",
    true,
    undefined,
    false,
    synced
  );
  assert.deepEqual(off.effort_tiers, synced);

  const on = getThinkingCapabilityFields(
    "anthropic",
    "claude-haiku-5-5",
    true,
    undefined,
    false,
    synced,
    true
  );
  assert.deepEqual(on.effort_tiers, ["low", "medium", "high", "max"]);
});

test("a connection with an empty effort list takes the fallback only when the flag is off", () => {
  const modelsByConnection = {
    empty: [{ id: "glm-5", supportsThinking: true, supportedThinkingEfforts: [] }],
  };
  assert.deepEqual(
    getConnectionScopedEffortTiers("glm-5", {}, ["empty"], modelsByConnection, undefined, [
      "low",
      "high",
    ]),
    ["low", "high"]
  );
  assert.deepEqual(
    getConnectionScopedEffortTiers(
      "glm-5",
      {},
      ["empty"],
      modelsByConnection,
      undefined,
      ["low", "high"],
      true
    ),
    []
  );
});