From 2dc6530f2b40b520269cd6d22069400372837fc8 Mon Sep 17 00:00:00 2001 From: nesquena-hermes Date: Fri, 10 Jul 2026 16:49:18 +0000 Subject: [PATCH] test: guard optional hermes_cli import in fail-closed pricing test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The new test_openrouter_free_tier_pricing_fails_closed did an unguarded 'from hermes_cli import models', but hermes_cli (the agent package) is an optional dependency not installed in the WebUI CI test environment, so the test failed with ModuleNotFoundError on 4-5 shards (master green, PR head red). Wrap the import in the same try/except guard the sibling tests in this file already use — when hermes_cli is present we force its live-fetch to empty so the fail-closed static path is exercised; when absent, that static path is already the only one and the api/config.py fix under test still runs via the mocked urlopen. Verified: 10/10 with hermes_cli, 5/5 with it blocked. Co-authored-by: igorroncevic --- ...t_issue1426_openrouter_free_tier_live_fetch.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/test_issue1426_openrouter_free_tier_live_fetch.py b/tests/test_issue1426_openrouter_free_tier_live_fetch.py index 90f2a553..7b822d63 100644 --- a/tests/test_issue1426_openrouter_free_tier_live_fetch.py +++ b/tests/test_issue1426_openrouter_free_tier_live_fetch.py @@ -167,10 +167,17 @@ def test_openrouter_free_tier_pricing_fails_closed( lambda *_args, **_kwargs: _FakeResponse(fake_payload), ) - from hermes_cli import models as hermes_models - - monkeypatch.setattr(hermes_models, "fetch_openrouter_models", lambda **_kwargs: []) - monkeypatch.setattr(hermes_models, "provider_model_ids", lambda *_args, **_kwargs: []) + # hermes_cli (the agent package) is an optional dependency and is not + # installed in the WebUI CI test environment. Force its live-fetch to + # return empty when present so the fail-closed static path is exercised; + # when absent, that static path is already the only one — mirror the + # try/except guard the sibling tests in this file use. + try: + from hermes_cli import models as hermes_models + monkeypatch.setattr(hermes_models, "fetch_openrouter_models", lambda **_kwargs: []) + monkeypatch.setattr(hermes_models, "provider_model_ids", lambda *_args, **_kwargs: []) + except Exception: + pass grouped = _get_grouped_models() openrouter_group = next(