Files
hermes-webui/tests/test_catalog_has_provider_compound_ids.py
T
jja881 53affd6936 fix: address review feedback — remove redundant clause, add guard and tests
- Remove the redundant 4th OR clause from _catalog_has_provider() — the
  existing C1–C3 already handle compound provider IDs correctly (C2 IS
  a normalized-vs-raw comparison; the 4th clause was a strict subset).
- Add && _activeProvider guard to _isCrossProviderPick in messages.js
  to prevent spurious True when the profile has no configured default
  provider (reviewer's optional hardening suggestion).
- Add test_catalog_has_provider_compound_ids.py verifying that compound
  provider IDs like 'custom:glm-free-relay' are correctly recognized by
  the existing C1–C3 clauses.
2026-06-20 18:44:25 +00:00

67 lines
1.9 KiB
Python

"""Tests for _catalog_has_provider() with compound provider IDs.
Compound provider IDs like "custom:zenmux-relay" or "custom:glm-free-relay"
normalize to "custom" via _normalize_provider_id(). The existing three
clauses in _catalog_has_provider() already handle these correctly:
C1: exact raw match ("custom:zenmux-relay" ∈ raw_ids)
C2: normalized ∈ raw_ids ("custom" ∈ raw_ids)
C3: normalized ∈ norm_ids ("custom" ∈ norm_ids)
This test guards against regressions and verifies that no 4th clause is
needed for compound IDs.
"""
from __future__ import annotations
from api.routes import _catalog_has_provider
def test_compound_provider_exact_raw_match():
"""C1: exact raw match for a compound ID like 'custom:zenmux-relay'."""
assert _catalog_has_provider(
"custom:zenmux-relay",
"custom",
{"custom:zenmux-relay"},
{"custom"},
)
def test_compound_provider_normalized_in_raw_ids():
"""C2: normalized form 'custom' found in raw_provider_ids."""
assert _catalog_has_provider(
"custom:zenmux-relay",
"custom",
{"custom"},
{"custom"},
)
def test_compound_provider_normalized_in_norm_ids():
"""C3: normalized form 'custom' found in normalized_provider_ids."""
assert _catalog_has_provider(
"custom:zenmux-relay",
"custom",
{"other"},
{"custom"},
)
def test_compound_provider_not_found():
"""Returns False when neither raw nor normalized form is in the catalog."""
assert not _catalog_has_provider(
"custom:unknown-relay",
"custom",
{"openrouter", "nous"},
{"openrouter", "nous"},
)
def test_compound_provider_glm_free_relay():
"""Real-world case: custom:glm-free-relay providing z-ai/glm-5.2-free."""
assert _catalog_has_provider(
"custom:glm-free-relay",
"custom",
{"custom:glm-free-relay"},
{"custom"},
)