Files
OmniRoute/tests/unit/qianfan-provider.test.ts
Diego Rodrigues de Sa e Souza fbea867d11 test: realign catalog snapshot tests to current deliberate catalog state (#8386)
* test: realign catalog snapshot tests to current deliberate catalog state

Six catalog/snapshot tests drifted behind deliberate catalog changes that
were already validated by newer sibling tests. No production code touched;
every change aligns a stale snapshot to behavior already validated by newer
sibling tests.

Root causes (all confirmed against the current code before editing):

- tests/unit/providers-constants-split.test.ts: APIKEY_PROVIDERS grew from
  187 to 195 entries via #8077 (clova-studio/internlm/ant-ling, regional),
  #8161 (sarvam/plamo → regional, writer → frontier-labs) and #8170
  (typhoon → regional, inception → frontier-labs). Family counts verified
  to sum to 195 (gateways 60, frontier-labs 24, inference-hosts 28,
  enterprise-cloud 17, regional 40, specialty-media 26) with no duplicates.
  Updated the two assertions and extended the changelog comment.

- tests/unit/qianfan-provider.test.ts: the expected Baidu Qianfan website
  URL was the pre-#8128 wenxinworkshop path. #8128/#6271 moved it to
  https://cloud.baidu.com/product-s/qianfan_home, already locked by the
  sibling regression test tests/unit/baidu-qianfan-website-urls-6271.test.ts.

- tests/unit/t31-t33-t34-t38-model-specs.test.ts and
  tests/unit/auto-combo-credentialed-model-pool.test.ts: the Antigravity
  catalog refactor (#8013) retired gemini-3-pro-preview/claude-sonnet-5 and
  renamed the Gemini 3.5 Flash tiers (low/medium/high ->
  extra-low/low/gemini-3-flash-agent), confirmed against
  ANTIGRAVITY_PUBLIC_MODELS and tests/unit/antigravity-retired-public-models.test.ts.
  Swapped the retired IDs for currently-registered ones
  (gemini-3.6-flash-high, claude-sonnet-4-6, gemini-3-flash-agent,
  gemini-3.5-flash-low/extra-low) and moved the wildcard-exclusion prefix
  test from the now-2-tier "gemini-3.5-*" group to "gemini-3.6-*", which has
  3 real tiers today (same >=3 semantics, just pointed at a prefix that
  still has 3 members).

- tests/unit/model-alias-seed.test.ts: getModelInfo("gemini-3.1-pro") now
  canonicalizes through ALIAS_TO_PROVIDER_ID["agy"] = "antigravity" (#8050),
  the same pattern already applied to opencode -> opencode-zen. Updated the
  expected provider id.

- tests/unit/video-dashscope.test.ts (deleted, 216 lines): #8266
  reorganized the Alibaba video catalog so the flat wan2.7-t2v id no longer
  exists under the plain "alibaba" provider (only the dated
  wan2.7-t2v-2026-06-12 does); the flat id now lives only under
  "qwen-cloud". All 6 tests in the file failed because they built  requests
  against alibaba/wan2.7-t2v, which the new allowlist now rejects with 400
  ("unsupported alibaba video model") - verified directly against
  VIDEO_PROVIDERS in open-sse/config/videoRegistry.ts. Coverage already
  exists and was confirmed passing pre-deletion in
  tests/unit/alibaba-video-media.test.ts (including an explicit
  "Alibaba rejects video models outside its own allowlist" case for this
  exact id) and tests/unit/qwen-cloud-video-media.test.ts (covers the same
  id under qwen-cloud). Note: the deleted file's DashScope upstream
  error-path assertions (401 missing credentials, 502 missing task_id, 502
  FAILED status, 504 poll timeout) don't have a byte-for-byte equivalent in
  the two replacement files, though the shared dashscopeHandler.ts code
  path they exercise remains covered by several sibling *-media.test.ts
  files for the happy path and local validation.

- tests/unit/authz/spawn-capable-prefixes-client-safe.test.ts: #7892 added
  /api/vnc-session to the SPAWN_CAPABLE_PREFIXES deny-list (Hard Rules
  #15/#17 hardening). Bumped the expected length 10 -> 11 and added the
  entry to the test's named list for documentation.

Refs #8013, #8050, #8266, #7892, #8128

* chore(quality): allowlist the video-dashscope.test.ts deletion with its replacements

check:test-masking (pr-test-policy CI gate) requires a _deletedWithReplacement
entry for any deleted test file, even when the deletion is a verified-legitimate
supersession. Documents the same #8266 rationale from the prior commit in the
machine-checked allowlist so the deletion is not flagged as unexplained masking.

Refs #8266
2026-07-24 09:59:08 -03:00

71 lines
3.1 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import { existsSync } from "node:fs";
import { join } from "node:path";
import { REGISTRY, getRegistryEntry } from "../../open-sse/config/providerRegistry.ts";
import { PROVIDERS } from "../../open-sse/config/constants.ts";
import { getModelsByProviderId, isValidModel } from "../../src/shared/constants/models.ts";
import { APIKEY_PROVIDERS } from "../../src/shared/constants/providers.ts";
import { validateBody, createProviderSchema } from "../../src/shared/validation/schemas.ts";
test("qianfan registers Baidu ERNIE as an OpenAI-compatible API key provider", () => {
const registryEntry = getRegistryEntry("qianfan");
assert.ok(registryEntry, "qianfan should be in the provider registry");
assert.equal(registryEntry, REGISTRY.qianfan);
assert.equal(registryEntry.id, "qianfan");
assert.equal(registryEntry.alias, "qianfan");
assert.equal(registryEntry.format, "openai");
assert.equal(registryEntry.executor, "default");
assert.equal(registryEntry.authType, "apikey");
assert.equal(registryEntry.authHeader, "bearer");
assert.equal(registryEntry.baseUrl, "https://qianfan.baidubce.com/v2/chat/completions");
assert.equal(registryEntry.defaultContextLength, 128000);
assert.equal(registryEntry.passthroughModels, undefined);
assert.ok(APIKEY_PROVIDERS.qianfan, "qianfan should be visible in API key providers");
assert.equal(APIKEY_PROVIDERS.qianfan.name, "Baidu Qianfan");
assert.equal(APIKEY_PROVIDERS.qianfan.website, "https://cloud.baidu.com/product-s/qianfan_home");
assert.equal(APIKEY_PROVIDERS.qianfan.passthroughModels, undefined);
assert.equal(PROVIDERS.qianfan.baseUrl, registryEntry.baseUrl);
assert.equal(PROVIDERS.qianfan.format, "openai");
assert.equal("modelsUrl" in PROVIDERS.qianfan, false);
assert.equal("passthroughModels" in PROVIDERS.qianfan, false);
});
test("qianfan exposes ERNIE chat models in the local model catalog", () => {
const models = getModelsByProviderId("qianfan");
const modelIds = models.map((model) => model.id);
assert.ok(modelIds.includes("ernie-5.1"));
assert.ok(modelIds.includes("ernie-5.0-thinking-latest"));
assert.ok(modelIds.includes("ernie-x1.1"));
assert.equal(models.find((model) => model.id === "ernie-x1.1")?.contextLength, 64000);
assert.ok(models.every((model) => typeof model.name === "string" && model.name.length > 0));
});
test("qianfan accepts known model IDs", () => {
assert.equal(isValidModel("qianfan", "ernie-5.1"), true);
assert.equal(isValidModel("qianfan", "future-qianfan-openai-compatible-model"), false);
});
test("qianfan provider creation schema accepts API-key connections", () => {
const validation = validateBody(createProviderSchema, {
provider: "qianfan",
apiKey: "bce-v3/test-key",
name: "Baidu Qianfan",
});
assert.equal(validation.success, true);
if (validation.success) {
assert.equal(validation.data.provider, "qianfan");
assert.equal(validation.data.apiKey, "bce-v3/test-key");
}
});
test("qianfan has a static provider icon asset", () => {
assert.equal(existsSync(join(process.cwd(), "public/providers/qianfan.svg")), true);
});