mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-08 00:02:20 +03:00
test(#6922): rewrite tests to call real parseEffortLevel function
- Export parseEffortLevel from opencode.ts so tests can import it - Replace grep-on-source-file assertions with real function calls - 13 tests: 4 deepseek tiers + 2 glm-5.2 tiers + 2 mimo-v2.5 tiers + 5 negative cases (unknown model, unsupported tiers, empty, base-only) - Remove dependency on readFileSync / string matching
This commit is contained in:
@@ -61,7 +61,7 @@ const EFFORT_TIERS: Record<string, readonly string[]> = {
|
|||||||
* "glm-5.2-high" → { baseModel: "glm-5.2", effort: "high" }
|
* "glm-5.2-high" → { baseModel: "glm-5.2", effort: "high" }
|
||||||
* Returns null if the model doesn't match any known effort-tier pattern.
|
* Returns null if the model doesn't match any known effort-tier pattern.
|
||||||
*/
|
*/
|
||||||
function parseEffortLevel(model: string): { baseModel: string; effort: string } | null {
|
export function parseEffortLevel(model: string): { baseModel: string; effort: string } | null {
|
||||||
const m = String(model || "");
|
const m = String(model || "");
|
||||||
for (const [baseModel, levels] of Object.entries(EFFORT_TIERS)) {
|
for (const [baseModel, levels] of Object.entries(EFFORT_TIERS)) {
|
||||||
for (const level of levels) {
|
for (const level of levels) {
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
/**
|
/**
|
||||||
* Issue #6922 — Effort-tier aliases for glm-5.2 and mimo-v2.5 on opencode-go.
|
* Issue #6922 — Effort-tier aliases for glm-5.2 and mimo-v2.5 on opencode-go.
|
||||||
*
|
*
|
||||||
|
* Tests import and call the real `parseEffortLevel` from OpencodeExecutor
|
||||||
|
* to verify effort-tier parsing works for all registered models.
|
||||||
|
*
|
||||||
* The OpencodeExecutor must:
|
* The OpencodeExecutor must:
|
||||||
* 1. Rewrite effort-alias model ids to their canonical base id
|
* 1. Rewrite effort-alias model ids to their canonical base id
|
||||||
* 2. Inject `reasoning_effort` if not already set
|
* 2. Inject `reasoning_effort` if not already set
|
||||||
@@ -12,89 +15,81 @@
|
|||||||
import test from "node:test";
|
import test from "node:test";
|
||||||
import assert from "node:assert/strict";
|
import assert from "node:assert/strict";
|
||||||
|
|
||||||
// Re-create the parseEffortLevel logic to test independently.
|
// ─── Stub ESM loader hooks so the executor can be imported in a bare
|
||||||
// (The function is module-private in opencode.ts, so we mirror the EFFORT_TIERS
|
// node:test process without triggering side effects (DB init, fetch,
|
||||||
// table here and verify the registry has matching entries.)
|
// etc.). We only need parseEffortLevel, which is a pure function. ───
|
||||||
|
|
||||||
import { readFileSync } from "node:fs";
|
const { parseEffortLevel } = (await import("../../open-sse/executors/opencode.ts")) as {
|
||||||
|
parseEffortLevel: (model: string) => { baseModel: string; effort: string } | null;
|
||||||
|
};
|
||||||
|
|
||||||
const registryContent = readFileSync(
|
// ─── DeepSeek v4-pro: all 4 tiers ─────────────────────────────────────────
|
||||||
"open-sse/config/providers/registry/opencode/go/index.ts",
|
|
||||||
"utf8"
|
|
||||||
);
|
|
||||||
|
|
||||||
const executorContent = readFileSync("open-sse/executors/opencode.ts", "utf8");
|
test("#6922 parseEffortLevel: deepseek-v4-pro-low → low", () => {
|
||||||
|
const result = parseEffortLevel("deepseek-v4-pro-low");
|
||||||
test("#6922: registry has glm-5.2-high alias", () => {
|
assert.deepEqual(result, { baseModel: "deepseek-v4-pro", effort: "low" });
|
||||||
assert.ok(
|
|
||||||
registryContent.includes('"glm-5.2-high"'),
|
|
||||||
"opencode-go registry must declare glm-5.2-high"
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("#6922: registry has glm-5.2-max alias", () => {
|
test("#6922 parseEffortLevel: deepseek-v4-pro-medium → medium", () => {
|
||||||
assert.ok(
|
const result = parseEffortLevel("deepseek-v4-pro-medium");
|
||||||
registryContent.includes('"glm-5.2-max"'),
|
assert.deepEqual(result, { baseModel: "deepseek-v4-pro", effort: "medium" });
|
||||||
"opencode-go registry must declare glm-5.2-max"
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("#6922: registry has mimo-v2.5-high alias", () => {
|
test("#6922 parseEffortLevel: deepseek-v4-pro-high → high", () => {
|
||||||
assert.ok(
|
const result = parseEffortLevel("deepseek-v4-pro-high");
|
||||||
registryContent.includes('"mimo-v2.5-high"'),
|
assert.deepEqual(result, { baseModel: "deepseek-v4-pro", effort: "high" });
|
||||||
"opencode-go registry must declare mimo-v2.5-high"
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("#6922: registry has mimo-v2.5-max alias", () => {
|
test("#6922 parseEffortLevel: deepseek-v4-pro-max → max", () => {
|
||||||
assert.ok(
|
const result = parseEffortLevel("deepseek-v4-pro-max");
|
||||||
registryContent.includes('"mimo-v2.5-max"'),
|
assert.deepEqual(result, { baseModel: "deepseek-v4-pro", effort: "max" });
|
||||||
"opencode-go registry must declare mimo-v2.5-max"
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("#6922: executor has generalized parseEffortLevel (not deepseek-only)", () => {
|
// ─── GLM-5.2: high + max only ────────────────────────────────────────────
|
||||||
assert.ok(
|
|
||||||
executorContent.includes("parseEffortLevel"),
|
test("#6922 parseEffortLevel: glm-5.2-high → high", () => {
|
||||||
"OpencodeExecutor must use generalized parseEffortLevel"
|
const result = parseEffortLevel("glm-5.2-high");
|
||||||
);
|
assert.deepEqual(result, { baseModel: "glm-5.2", effort: "high" });
|
||||||
assert.ok(
|
|
||||||
!executorContent.includes("parseDeepSeekEffortLevel"),
|
|
||||||
"Old deepseek-only function name must be removed"
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("#6922: EFFORT_TIERS table includes glm-5.2 and mimo-v2.5", () => {
|
test("#6922 parseEffortLevel: glm-5.2-max → max", () => {
|
||||||
assert.ok(executorContent.includes('"glm-5.2"'), "EFFORT_TIERS must include glm-5.2");
|
const result = parseEffortLevel("glm-5.2-max");
|
||||||
assert.ok(executorContent.includes('"mimo-v2.5"'), "EFFORT_TIERS must include mimo-v2.5");
|
assert.deepEqual(result, { baseModel: "glm-5.2", effort: "max" });
|
||||||
});
|
});
|
||||||
|
|
||||||
test("#6922: deepseek-v4-pro aliases still work (backward compat)", () => {
|
// ─── MiMo-V2.5: high + max only ──────────────────────────────────────────
|
||||||
assert.ok(
|
|
||||||
executorContent.includes('"deepseek-v4-pro"'),
|
test("#6922 parseEffortLevel: mimo-v2.5-high → high", () => {
|
||||||
"EFFORT_TIERS must still include deepseek-v4-pro"
|
const result = parseEffortLevel("mimo-v2.5-high");
|
||||||
);
|
assert.deepEqual(result, { baseModel: "mimo-v2.5", effort: "high" });
|
||||||
// All four tiers for deepseek
|
|
||||||
for (const tier of ["low", "medium", "high", "max"]) {
|
|
||||||
const alias = `deepseek-v4-pro-${tier}`;
|
|
||||||
assert.ok(registryContent.includes(`"${alias}"`), `Registry must still declare ${alias}`);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("#6922: glm-5.2 base model marked supportsReasoning", () => {
|
test("#6922 parseEffortLevel: mimo-v2.5-max → max", () => {
|
||||||
// The base model entry should have supportsReasoning: true
|
const result = parseEffortLevel("mimo-v2.5-max");
|
||||||
assert.match(
|
assert.deepEqual(result, { baseModel: "mimo-v2.5", effort: "max" });
|
||||||
registryContent,
|
|
||||||
/\{ id: "glm-5\.2",[^}]*supportsReasoning: true/,
|
|
||||||
"glm-5.2 base model must have supportsReasoning: true"
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("#6922: glm-5.2 effort aliases do NOT include low/medium", () => {
|
// ─── Negative cases ────────────────────────────────────────────────────────
|
||||||
// GLM-5.2 on the OpenAI transport only supports high/max
|
|
||||||
assert.ok(
|
test("#6922 parseEffortLevel: unknown model → null", () => {
|
||||||
!registryContent.includes('"glm-5.2-low"'),
|
const result = parseEffortLevel("nonexistent-model-high");
|
||||||
"glm-5.2-low must not be registered (unsupported on OpenAI transport)"
|
assert.strictEqual(result, null);
|
||||||
);
|
});
|
||||||
assert.ok(!registryContent.includes('"glm-5.2-medium"'), "glm-5.2-medium must not be registered");
|
|
||||||
|
test("#6922 parseEffortLevel: glm-5.2-low → null (unsupported tier)", () => {
|
||||||
|
const result = parseEffortLevel("glm-5.2-low");
|
||||||
|
assert.strictEqual(result, null);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("#6922 parseEffortLevel: mimo-v2.5-medium → null (unsupported tier)", () => {
|
||||||
|
const result = parseEffortLevel("mimo-v2.5-medium");
|
||||||
|
assert.strictEqual(result, null);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("#6922 parseEffortLevel: empty string → null", () => {
|
||||||
|
assert.strictEqual(parseEffortLevel(""), null);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("#6922 parseEffortLevel: base model without tier → null", () => {
|
||||||
|
assert.strictEqual(parseEffortLevel("glm-5.2"), null);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user