mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-26 09:52:11 +03:00
DefaultExecutor.buildUrl()'s "zai"/"glm-coding-apikey" case always returned the Anthropic Messages URL, ignoring a per-model targetFormat override (custom-model dropdown, #2905) that resolves to "openai" — e.g. for a vision model like glm-4.6v. chatCore/executionCredentials.ts now threads the resolved override onto providerSpecificData.targetFormat so buildUrl (via the new default/zaiFormatOverride.ts helper, extracted to respect the file-size ratchet) can route to the OpenAI-compatible endpoint instead. Separately, custom-model id lookup (lookupCustomModelMeta in src/sse/services/model.ts, getCustomModelRow in src/lib/db/models.ts) did an exact, case-sensitive match, so a model saved as "glm-4.6v" was invisible when looked up as "glm-4.6V". Both now fall back to a case-insensitive match after the exact match fails. Regression tests: tests/unit/zai-glm-target-format-override.test.ts (reused from the triage plan-file's RED probe) and tests/unit/zai-execution-credentials-target-format-7364.test.ts (production wiring in executionCredentials.ts). Gates run: check-file-size, check-complexity, check-cognitive-complexity, typecheck:core, eslint (suppressions), tests/unit/zai-glm-target-format-override.test.ts, tests/unit/zai-execution-credentials-target-format-7364.test.ts, tests/unit/executor-default-base.test.ts, tests/unit/custom-model-target-format.test.ts, tests/unit/chatcore-execution-credentials.test.ts, tests/unit/chatcore-target-format.test.ts, tests/unit/model-resolver.test.ts, tests/unit/model-alias-provider-resolution.test.ts, tests/unit/combo-custom-provider-resolution.test.ts — all green. Refs #7364
53 lines
2.1 KiB
TypeScript
53 lines
2.1 KiB
TypeScript
// tests/unit/zai-execution-credentials-target-format-7364.test.ts
|
|
// #7364 Defect A: resolveExecutionCredentials must thread a resolved "openai"
|
|
// targetFormat onto providerSpecificData for the "zai"/"glm-coding-apikey" providers,
|
|
// so DefaultExecutor.buildUrl()'s zai branch (open-sse/executors/default/zaiFormatOverride.ts)
|
|
// can see the per-model custom-model targetFormat override (#2905) and route to the
|
|
// OpenAI-compatible endpoint instead of the default Anthropic Messages URL.
|
|
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { resolveExecutionCredentials } from "../../open-sse/handlers/chatCore/executionCredentials.ts";
|
|
|
|
const base = {
|
|
credentials: { providerSpecificData: { foo: "bar" } } as Record<string, unknown>,
|
|
nativeCodexPassthrough: false,
|
|
endpointPath: "/v1/messages",
|
|
ccSessionId: null,
|
|
};
|
|
|
|
test("zai + resolved openai targetFormat threads providerSpecificData.targetFormat", () => {
|
|
const out = resolveExecutionCredentials({
|
|
...base,
|
|
provider: "zai",
|
|
targetFormat: "openai",
|
|
}) as Record<string, unknown>;
|
|
assert.deepEqual(out.providerSpecificData, { foo: "bar", targetFormat: "openai" });
|
|
});
|
|
|
|
test("glm-coding-apikey + resolved openai targetFormat threads providerSpecificData.targetFormat", () => {
|
|
const out = resolveExecutionCredentials({
|
|
...base,
|
|
provider: "glm-coding-apikey",
|
|
targetFormat: "openai",
|
|
}) as Record<string, unknown>;
|
|
assert.deepEqual(out.providerSpecificData, { foo: "bar", targetFormat: "openai" });
|
|
});
|
|
|
|
test("zai + default claude targetFormat does NOT inject a targetFormat override", () => {
|
|
const out = resolveExecutionCredentials({
|
|
...base,
|
|
provider: "zai",
|
|
targetFormat: "claude",
|
|
}) as Record<string, unknown>;
|
|
assert.deepEqual(out.providerSpecificData, { foo: "bar" });
|
|
});
|
|
|
|
test("unrelated provider (openai) with targetFormat=openai is untouched by the zai branch", () => {
|
|
const out = resolveExecutionCredentials({
|
|
...base,
|
|
provider: "openai",
|
|
targetFormat: "openai",
|
|
}) as Record<string, unknown>;
|
|
assert.deepEqual(out.providerSpecificData, { foo: "bar" });
|
|
});
|