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

1.5 KB
Raw Blame
import test from "node:test";
import assert from "node:assert/strict";

import { glmMonthlyRemainingPercentage } from "../../../open-sse/services/usage.ts";

// #3580 — z.ai/GLM coding plans have no monthly cap (only 5-hour windows), so the
// quota API reports the TIME_LIMIT ("Monthly") entry with total=0. The previous
// `total > 0 ? … : 0` fallback rendered that as a misleading "Monthly 0% remaining",
// which can skew downstream model-choice. With no absolute cap we now fall back to the
// percentage-derived remaining (full/100% when 0% used).

test("#3580 no monthly cap (total=0), 0% used → 100% remaining (was 0%)", () => {
  assert.equal(glmMonthlyRemainingPercentage(0, 100), 100);
});

test("#3580 no monthly cap (total=0), no usage signal → defaults to full (100)", () => {
  // remaining defaults to max(0, 100 - percentage); 0% used → 100
  assert.equal(glmMonthlyRemainingPercentage(0, 100), 100);
});

test("#3580 absolute monthly cap still computes remaining/total", () => {
  assert.equal(glmMonthlyRemainingPercentage(1000, 500), 50);
  assert.equal(glmMonthlyRemainingPercentage(1000, 1000), 100);
  assert.equal(glmMonthlyRemainingPercentage(1000, 0), 0);
});

test("#3580 clamps out-of-range values to [0,100]", () => {
  assert.equal(glmMonthlyRemainingPercentage(0, 250), 100); // no cap, absolute remaining > 100 → clamp full
  assert.equal(glmMonthlyRemainingPercentage(1000, 5000), 100);
  assert.equal(glmMonthlyRemainingPercentage(0, -5), 0);
});