Files
cc-switch/tests/components/GptContextWindowHint.test.tsx
Jason 8d7a741540 fix(models): cap only borrowed GPT windows and warn on oversized entries
The 272K GPT cap (v4.0.13) applied to every window the metadata lookup
returned, so platforms that really serve the 1.05M OpenAI API window
(OpenRouter and other providers models.dev recognizes by address) were
capped too. The risk the cap guards against is narrower: a relay that
models.dev does not know falls back to the vendor's own entry, and its
1.05M lands on a model that is often served from a ChatGPT subscription
with a 272K window.

- Same-endpoint presets and the models.dev provider matched by address
  keep their own windows; only the window borrowed from the vendor entry
  (including when the matched provider lists none) is capped at 272K.
- A window the user types is kept as is. When a GPT model's window is
  above 272K, the Codex, Hermes, OpenClaw, OpenCode and Pi forms show a
  note under the field: relay GPT usually has the subscription window, and
  an oversized one delays compaction until the upstream rejects the turn.
  Text added in zh / en / ja / zh-TW.

Existing rows are not migrated. Codex GPT rows saved before v4.0.13 with
an auto-filled 1.05M now take effect since #8385; the note shows when the
form is opened.
2026-10-19 18:01:47 +08:00

22 lines
813 B
TypeScript

import { render } from "@testing-library/react";
import { describe, expect, it } from "vitest";
import { GptContextWindowHint } from "@/components/providers/forms/shared";
const hint = (modelId: string | undefined, contextWindow: unknown) =>
render(
<GptContextWindowHint modelId={modelId} contextWindow={contextWindow} />,
).container.textContent;
describe("GptContextWindowHint", () => {
it("warns only when a GPT window exceeds the subscription window", () => {
expect(hint("gpt-6-astra", "1050000")).toContain("272K");
expect(hint("openai/gpt-6.1-sol", 500000)).toContain("272K");
expect(hint("gpt-6-astra", "272000")).toBe("");
expect(hint("gpt-6-astra", "")).toBe("");
expect(hint("deepseek-v4", 1000000)).toBe("");
expect(hint(undefined, 1050000)).toBe("");
});
});