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.
This commit is contained in:
1 parent
42fedaf780
commit
53affd6936
3 files changed
+68
-12
No files matched your search
+1
-12
@@ -3196,18 +3196,7 @@ def _catalog_has_provider(
|
||||
provider_raw in raw_provider_ids
|
||||
or (provider_normalized and provider_normalized in raw_provider_ids)
|
||||
or (provider_normalized and provider_normalized in normalized_provider_ids)
|
||||
# Compound provider IDs like "custom:zenmux-relay" normalize to
|
||||
# "custom" which is a raw catalog provider_id. The three checks
|
||||
# above compare raw-vs-raw and normalized-vs-normalized but miss
|
||||
# normalized-vs-raw for compound hints. Without this, a
|
||||
# @custom:relay-name:model selection is silently reverted to the
|
||||
# profile default on every non-explicit turn because the catalog
|
||||
# lookup fails and the fallback branch at line ~3932 fires.
|
||||
or (
|
||||
provider_normalized
|
||||
and ":" in provider_raw
|
||||
and provider_normalized in raw_provider_ids
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -1281,6 +1281,7 @@ async function send(){
|
||||
const _isCrossProviderPick = _modelState.model
|
||||
&& _modelState.model_provider
|
||||
&& _defaultModel
|
||||
&& _activeProvider
|
||||
&& _modelState.model !== _defaultModel
|
||||
&& String(_modelState.model_provider||'') !== String(_activeProvider||'');
|
||||
const _explicitPick = _pendingPickMatch || _isCrossProviderPick;
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
"""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"},
|
||||
)
|
||||
Reference in new issue
Block a user