From e46072c699a29122aae78bf1a984ce6f82a63645 Mon Sep 17 00:00:00 2001 From: Ed Date: Mon, 25 May 2026 16:29:31 +0200 Subject: [PATCH 1/3] fix: update opencode-go base_url in provider overlap tests api.opencode.ai/v1 -> opencode.ai/zen/go/v1 (canonical per hermes_cli/auth.py) --- tests/test_issue1894_provider_overlap.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test_issue1894_provider_overlap.py b/tests/test_issue1894_provider_overlap.py index af1440016d..7dcc225bbf 100644 --- a/tests/test_issue1894_provider_overlap.py +++ b/tests/test_issue1894_provider_overlap.py @@ -55,7 +55,7 @@ def test_selected_opencode_go_wins_over_custom_provider_overlap(): # custom endpoint. import api.config as cfg_mod old_model, old_custom = _apply_config_overrides(cfg_mod, { - 'base_url': 'https://api.opencode.ai/go/v1', + 'base_url': 'https://opencode.ai/zen/go/v1', }) cfg_mod.cfg['custom_providers'] = [{ 'name': 'ds2api', @@ -71,7 +71,7 @@ def test_selected_opencode_go_wins_over_custom_provider_overlap(): f'Expected provider=opencode-go, got provider={provider!r}. ' f'WebUI was routed to custom provider instead.' ) - assert base_url == 'https://api.opencode.ai/go/v1', ( + assert base_url == 'https://opencode.ai/zen/go/v1', ( f'Expected base_url from opencode-go config, got {base_url!r}' ) assert model == 'deepseek-v4-pro' @@ -84,7 +84,7 @@ def test_selected_opencode_go_wins_direct_resolve(): # resolver path directly with a bare model id. import api.config as cfg_mod old_model, old_custom = _apply_config_overrides(cfg_mod, { - 'base_url': 'https://api.opencode.ai/go/v1', + 'base_url': 'https://opencode.ai/zen/go/v1', }) cfg_mod.cfg['custom_providers'] = [{ 'name': 'ds2api', @@ -96,7 +96,7 @@ def test_selected_opencode_go_wins_direct_resolve(): assert provider == 'opencode-go', ( f'Expected provider=opencode-go, got provider={provider!r}' ) - assert base_url == 'https://api.opencode.ai/go/v1' + assert base_url == 'https://opencode.ai/zen/go/v1' finally: _restore_config(cfg_mod, old_model, old_custom) @@ -110,7 +110,7 @@ def test_custom_only_model_still_routes_to_custom_provider(): # correctly when no explicit provider prefix is given. import api.config as cfg_mod old_model, old_custom = _apply_config_overrides(cfg_mod, { - 'base_url': 'https://api.opencode.ai/go/v1', + 'base_url': 'https://opencode.ai/zen/go/v1', }) cfg_mod.cfg['custom_providers'] = [{ 'name': 'ds2api', From 38db6199b8d6697f39503cb44ddcd4bf5fd36c20 Mon Sep 17 00:00:00 2001 From: Ed Date: Tue, 26 May 2026 16:36:53 +0200 Subject: [PATCH 2/3] =?UTF-8?q?chore:=20clean=20up=20test=5Fissue1894=5Fpr?= =?UTF-8?q?ovider=5Foverlap=20=E2=80=94=20remove=20vestigial=20noqa,=20add?= =?UTF-8?q?=20docstrings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_issue1894_provider_overlap.py | 41 +++++++++++++++--------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/tests/test_issue1894_provider_overlap.py b/tests/test_issue1894_provider_overlap.py index 7dcc225bbf..7f09e95c02 100644 --- a/tests/test_issue1894_provider_overlap.py +++ b/tests/test_issue1894_provider_overlap.py @@ -1,8 +1,6 @@ # Copyright 2025 the Hermes WebUI contributors # SPDX-License-Identifier: MIT -# noqa: N801 - # Regression tests for GitHub issue #1894. # # Symptom: when the WebUI's configured provider (e.g. `opencode-go`) and a @@ -44,15 +42,14 @@ def _restore_config(cfg_module, old_model, old_custom): cfg_module.cfg['custom_providers'] = old_custom -# --------------------------------------------------------------------------- -# Case 1 — overlap: selected non-custom provider should win -# --------------------------------------------------------------------------- - def test_selected_opencode_go_wins_over_custom_provider_overlap(): - # opencode-go and a custom DeepSeek-compatible endpoint both serve - # deepseek-v4-pro. With opencode-go configured as the active provider, - # selection of deepseek-v4-pro must route to opencode-go, not to the - # custom endpoint. + """Case 1 — overlap: selected non-custom provider should win. + + OpenCode Go and a custom DeepSeek-compatible endpoint both serve + deepseek-v4-pro. With opencode-go configured as the active provider, + selection of deepseek-v4-pro must route to opencode-go, not to the + custom endpoint. + """ import api.config as cfg_mod old_model, old_custom = _apply_config_overrides(cfg_mod, { 'base_url': 'https://opencode.ai/zen/go/v1', @@ -80,8 +77,11 @@ def test_selected_opencode_go_wins_over_custom_provider_overlap(): def test_selected_opencode_go_wins_direct_resolve(): - # Same scenario but bypassing model_with_provider_context to test the - # resolver path directly with a bare model id. + """Case 1 variant — same overlap scenario via direct resolve path. + + Bypasses model_with_provider_context to test the resolver path directly + with a bare model id. + """ import api.config as cfg_mod old_model, old_custom = _apply_config_overrides(cfg_mod, { 'base_url': 'https://opencode.ai/zen/go/v1', @@ -106,8 +106,11 @@ def test_selected_opencode_go_wins_direct_resolve(): # --------------------------------------------------------------------------- def test_custom_only_model_still_routes_to_custom_provider(): - # A model that exists only in a custom provider must still be routed - # correctly when no explicit provider prefix is given. + """Case 2 — custom-only model routing must stay intact. + + A model that exists only in a custom provider must still be routed + correctly when no explicit provider prefix is given. + """ import api.config as cfg_mod old_model, old_custom = _apply_config_overrides(cfg_mod, { 'base_url': 'https://opencode.ai/zen/go/v1', @@ -132,7 +135,10 @@ def test_custom_only_model_still_routes_to_custom_provider(): # --------------------------------------------------------------------------- def test_explicit_custom_provider_selection_intact(): - # @custom:: syntax must not be swallowed by the new guard. + """Case 3 — explicit custom provider selection still works. + + The @custom:: syntax must not be swallowed by the new guard. + """ model, provider, base_url = resolve_model_provider('@custom:ds2api:deepseek-v4-pro') assert provider == 'custom:ds2api', f'Expected provider=custom:ds2api, got {provider!r}' assert model == 'deepseek-v4-pro' @@ -143,6 +149,11 @@ def test_explicit_custom_provider_selection_intact(): # --------------------------------------------------------------------------- def test_openrouter_suffix_still_works(): + """Case 4 — existing suffix syntax is preserved. + + Ensures the openrouter suffix syntax (e.g. model_name:free) still routes + correctly through model_with_provider_context. + """ import api.config as cfg_mod old_model, old_custom = _apply_config_overrides(cfg_mod, { 'provider': 'anthropic', # non-openrouter so prefix is needed From 9bb5842530f0844d7b254119e43363bdeccb84a1 Mon Sep 17 00:00:00 2001 From: Ed Date: Tue, 26 May 2026 16:54:34 +0200 Subject: [PATCH 3/3] =?UTF-8?q?chore:=20address=20audit=20findings=20?= =?UTF-8?q?=E2=80=94=20module=20docstring=20+=20consistent=20section=20sep?= =?UTF-8?q?arators?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_issue1894_provider_overlap.py | 45 +++++++++--------------- 1 file changed, 17 insertions(+), 28 deletions(-) diff --git a/tests/test_issue1894_provider_overlap.py b/tests/test_issue1894_provider_overlap.py index 7f09e95c02..847d2dfe87 100644 --- a/tests/test_issue1894_provider_overlap.py +++ b/tests/test_issue1894_provider_overlap.py @@ -1,21 +1,22 @@ # Copyright 2025 the Hermes WebUI contributors # SPDX-License-Identifier: MIT -# Regression tests for GitHub issue #1894. -# -# Symptom: when the WebUI's configured provider (e.g. `opencode-go`) and a -# `custom_providers[]` entry both expose the same bare model id (e.g. -# `deepseek-v4-pro`), the resolver was routing to `custom:` instead of -# the configured `opencode-go` endpoint. -# -# Root cause: `resolve_model_provider()` in `api/config.py` guarded the custom- -# provider skip only when `model_id == model.default`. If `model.default` -# was a different model (e.g. `glm-5.1`), the overlap was not detected and -# `deepseek-v4-pro` was matched against `custom_providers[]` first, routing -# the WebUI to the wrong endpoint. -# -# Fix: widen the guard so an explicit non-custom provider wins for any model -# it owns in `_PROVIDER_MODELS[config_provider]`. +"""Regression tests for GitHub issue #1894. + +Symptom: when the WebUI's configured provider (e.g. ``opencode-go``) and a +``custom_providers[]`` entry both expose the same bare model id (e.g. +``deepseek-v4-pro``), the resolver was routing to ``custom:`` instead of +the configured ``opencode-go`` endpoint. + +Root cause: ``resolve_model_provider()`` in ``api/config.py`` guarded the +custom-provider skip only when ``model_id == model.default``. If +``model.default`` was a different model (e.g. ``glm-5.1``), the overlap was +not detected and ``deepseek-v4-pro`` was matched against +``custom_providers[]`` first, routing the WebUI to the wrong endpoint. + +Fix: widen the guard so an explicit non-custom provider wins for any model +it owns in ``_PROVIDER_MODELS[config_provider]``. +""" from api.config import resolve_model_provider, model_with_provider_context @@ -101,10 +102,6 @@ def test_selected_opencode_go_wins_direct_resolve(): _restore_config(cfg_mod, old_model, old_custom) -# --------------------------------------------------------------------------- -# Case 2 — custom-only model: custom provider routing must stay intact -# --------------------------------------------------------------------------- - def test_custom_only_model_still_routes_to_custom_provider(): """Case 2 — custom-only model routing must stay intact. @@ -130,10 +127,6 @@ def test_custom_only_model_still_routes_to_custom_provider(): _restore_config(cfg_mod, old_model, old_custom) -# --------------------------------------------------------------------------- -# Case 3 — explicit custom provider selection still works -# --------------------------------------------------------------------------- - def test_explicit_custom_provider_selection_intact(): """Case 3 — explicit custom provider selection still works. @@ -144,10 +137,6 @@ def test_explicit_custom_provider_selection_intact(): assert model == 'deepseek-v4-pro' -# --------------------------------------------------------------------------- -# Case 4 — existing suffix syntax is preserved -# --------------------------------------------------------------------------- - def test_openrouter_suffix_still_works(): """Case 4 — existing suffix syntax is preserved. @@ -165,4 +154,4 @@ def test_openrouter_suffix_still_works(): assert provider == 'openrouter' assert model == 'tencent/hy3-preview:free' finally: - _restore_config(cfg_mod, old_model, old_custom) \ No newline at end of file + _restore_config(cfg_mod, old_model, old_custom)