mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-11-30 19:26:59 +08:00
Per-model Fast covers what "Keep official Fast tier" did and also works in aggregation, so drop the card switch from the form. Cards saved with the old switch are migrated when the form opens: GPT rows without their own Fast setting get Fast on, and saving stores only the per-model values. Until a card is saved again (or when it comes from an older device) the backend still honors officialSpeedTiers, so nothing changes for users who never reopen the form. The Fast help tip now carries the desktop sign-in note from the old switch, and both per-model defaults read "Default (off)". All eight locales updated.
165 lines
5.6 KiB
TypeScript
165 lines
5.6 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
||
import { normalizeCodexCatalogModelsForSave } from "@/components/providers/forms/ProviderForm";
|
||
import {
|
||
mapCodexCatalogModelForForm,
|
||
migrateLegacyOfficialSpeedTiers,
|
||
} from "@/components/providers/forms/hooks/useCodexConfigState";
|
||
|
||
describe("ProviderForm Codex catalog helpers", () => {
|
||
it("normalizes catalog rows and removes empty or duplicate models", () => {
|
||
expect(
|
||
normalizeCodexCatalogModelsForSave([
|
||
{ model: " deepseek-v4-flash ", displayName: " DeepSeek " },
|
||
{ model: "deepseek-v4-flash", displayName: "Duplicate" },
|
||
{ model: "", displayName: "Empty" },
|
||
{ model: "kimi-k2", contextWindow: "128000 tokens" },
|
||
]),
|
||
).toEqual([
|
||
{ model: "deepseek-v4-flash", displayName: "DeepSeek" },
|
||
{ model: "kimi-k2", contextWindow: 128000 },
|
||
]);
|
||
});
|
||
|
||
it("preserves native-profile overrides (parallel tool calls + input modalities + base instructions)", () => {
|
||
expect(
|
||
normalizeCodexCatalogModelsForSave([
|
||
{
|
||
model: "MiniMax-M3",
|
||
displayName: "MiniMax-M3",
|
||
contextWindow: 1000000,
|
||
supportsParallelToolCalls: true,
|
||
inputModalities: ["text", "image"],
|
||
baseInstructions:
|
||
" You are Codex, a coding agent based on MiniMax-M3. ",
|
||
},
|
||
// false must be preserved (not dropped as falsy); empty modalities dropped;
|
||
// empty/whitespace baseInstructions dropped
|
||
{
|
||
model: "mimo-v2.5-pro",
|
||
supportsParallelToolCalls: false,
|
||
inputModalities: [],
|
||
baseInstructions: " ",
|
||
},
|
||
]),
|
||
).toEqual([
|
||
{
|
||
model: "MiniMax-M3",
|
||
displayName: "MiniMax-M3",
|
||
contextWindow: 1000000,
|
||
supportsParallelToolCalls: true,
|
||
inputModalities: ["text", "image"],
|
||
baseInstructions: "You are Codex, a coding agent based on MiniMax-M3.",
|
||
},
|
||
{ model: "mimo-v2.5-pro", supportsParallelToolCalls: false },
|
||
]);
|
||
});
|
||
|
||
it("preserves per-model reasoning levels and default level", () => {
|
||
expect(
|
||
normalizeCodexCatalogModelsForSave([
|
||
{
|
||
model: "deepseek-v4-flash",
|
||
displayName: "DeepSeek V4 Flash",
|
||
reasoningLevels: ["none", "low", "medium", "high", "xhigh", "max"],
|
||
defaultReasoningLevel: " xhigh ",
|
||
},
|
||
// empty levels / whitespace default are dropped
|
||
{
|
||
model: "plain-model",
|
||
reasoningLevels: [],
|
||
defaultReasoningLevel: " ",
|
||
},
|
||
]),
|
||
).toEqual([
|
||
{
|
||
model: "deepseek-v4-flash",
|
||
displayName: "DeepSeek V4 Flash",
|
||
reasoningLevels: ["none", "low", "medium", "high", "xhigh", "max"],
|
||
defaultReasoningLevel: "xhigh",
|
||
},
|
||
{ model: "plain-model" },
|
||
]);
|
||
});
|
||
|
||
it("round-trips reasoning levels through load and save without loss", () => {
|
||
// load→save 回环:加载映射(mapCodexCatalogModelForForm)与保存归一化
|
||
// (normalizeCodexCatalogModelsForSave)各锁半边时,回环丢字段两边都测不出——
|
||
// 而编辑保存丢表会让依赖逐模型档位的功能(zen 钳制)静默失效且 UI 无可察觉。
|
||
const stored = [
|
||
{
|
||
model: "glm-5.2",
|
||
displayName: "GLM 5.2",
|
||
reasoningLevels: ["high", "max"],
|
||
},
|
||
// 手写/旧数据可能是 snake_case,加载侧兼容后保存侧同样要留住
|
||
{ model: "deepseek-v4-flash", reasoning_levels: ["low", "high", "max"] },
|
||
{ model: "glm-5.1" }, // toggle 型:无表,全程不得凭空造表
|
||
];
|
||
|
||
const roundTripped = normalizeCodexCatalogModelsForSave(
|
||
stored.map(mapCodexCatalogModelForForm),
|
||
);
|
||
|
||
expect(roundTripped).toEqual([
|
||
{
|
||
model: "glm-5.2",
|
||
displayName: "GLM 5.2",
|
||
reasoningLevels: ["high", "max"],
|
||
},
|
||
{ model: "deepseek-v4-flash", reasoningLevels: ["low", "high", "max"] },
|
||
{ model: "glm-5.1" },
|
||
]);
|
||
});
|
||
|
||
it("round-trips per-model Fast and Lite flags without affecting other rows", () => {
|
||
const stored = [
|
||
{ model: "fast-lite", fast: true, lite: true },
|
||
{ model: "disabled", fast: false, lite: false },
|
||
{ model: "legacy" },
|
||
];
|
||
expect(
|
||
normalizeCodexCatalogModelsForSave(
|
||
stored.map(mapCodexCatalogModelForForm),
|
||
),
|
||
).toEqual(stored);
|
||
});
|
||
|
||
// 卡上旧的「保留官方 Fast 档」换成逐行 Fast:只补没单独设过的 GPT 模型。
|
||
it("turns the legacy card Fast switch into per-model Fast on GPT rows", () => {
|
||
const rows = [
|
||
{ model: "gpt-6-sol" },
|
||
{ model: "openai/gpt-5.5" },
|
||
{ model: "gpt-6", fast: false },
|
||
{ model: "glm-5" },
|
||
];
|
||
expect(migrateLegacyOfficialSpeedTiers(rows, true)).toEqual([
|
||
{ model: "gpt-6-sol", fast: true },
|
||
{ model: "openai/gpt-5.5", fast: true },
|
||
{ model: "gpt-6", fast: false },
|
||
{ model: "glm-5" },
|
||
]);
|
||
expect(migrateLegacyOfficialSpeedTiers(rows, false)).toBe(rows);
|
||
});
|
||
|
||
it("ignores non-boolean tier values", () => {
|
||
const stored = [
|
||
{ model: "invalid", fast: "true", lite: "false" },
|
||
{ model: "absent", fast: 1, lite: null },
|
||
];
|
||
expect(
|
||
normalizeCodexCatalogModelsForSave(
|
||
stored.map(mapCodexCatalogModelForForm),
|
||
),
|
||
).toEqual([{ model: "invalid" }, { model: "absent" }]);
|
||
});
|
||
|
||
it("trims reasoning level values on save", () => {
|
||
// 手编 JSON 里的 " high " 不得原样落库/发给上游。
|
||
expect(
|
||
normalizeCodexCatalogModelsForSave([
|
||
{ model: "glm-5.2", reasoningLevels: [" high ", "max"] },
|
||
]),
|
||
).toEqual([{ model: "glm-5.2", reasoningLevels: ["high", "max"] }]);
|
||
});
|
||
});
|