fb13457f6f
CI / Supply-chain scan (push) Has been cancelled
Docker Build, Test, and Publish / Detect affected areas (push) Has been cancelled
auto-fix lint issues & formatting / Generate eslint --fix patch (push) Has been cancelled
Nix flake check / Detect affected areas (push) Has been cancelled
Deploy Site / deploy-vercel (push) Has been cancelled
Deploy Site / deploy-docs (push) Has been cancelled
CI / Detect affected areas (push) Has been cancelled
Docker Build, Test, and Publish / build (amd64, type=gha,scope=docker-amd64, type=gha,mode=max,scope=docker-amd64, linux/amd64, ubuntu-latest-32-core) (push) Has been cancelled
CI / Desktop E2E (push) Has been cancelled
CI / Docs Site (push) Has been cancelled
CI / Deny unrelated histories (push) Has been cancelled
CI / Check contributors (push) Has been cancelled
Docker Build, Test, and Publish / build (arm64, type=gha,scope=docker-arm64, type=gha,mode=max,scope=docker-arm64, linux/arm64, ubuntu-latest-32-arm-core) (push) Has been cancelled
CI / Check uv.lock (push) Has been cancelled
CI / Check no committed infographics (push) Has been cancelled
CI / Profile artifact check (push) Has been cancelled
Docker Build, Test, and Publish / publish (amd64, type=gha,scope=docker-amd64, type=gha,mode=max,scope=docker-amd64, linux/amd64, ubuntu-latest-32-core) (push) Has been cancelled
Docker Build, Test, and Publish / publish (arm64, type=gha,scope=docker-arm64, type=gha,mode=max,scope=docker-arm64, linux/arm64, ubuntu-latest-32-arm-core) (push) Has been cancelled
Docker Build, Test, and Publish / merge (push) Has been cancelled
auto-fix lint issues & formatting / Apply patch (push) Has been cancelled
CI / Check no case-colliding filenames (push) Has been cancelled
CI / package-lock.json diff (push) Has been cancelled
CI / Lint Docker scripts (push) Has been cancelled
CI / Review label gate (push) Has been cancelled
CI / All required checks pass (push) Has been cancelled
CI / CI timing report (push) Has been cancelled
CI / Python tests (push) Has been cancelled
CI / OS-specific tests (push) Has been cancelled
CI / Python lints (push) Has been cancelled
CI / JS & TS checks (push) Has been cancelled
CI / Installer tests (push) Has been cancelled
CI / Rust tests (push) Has been cancelled
Nix flake check / nix flake check (push) Has been cancelled
104 lines
3.7 KiB
Python
104 lines
3.7 KiB
Python
"""Tests for providers config entry validation and normalization.
|
|
|
|
Covers Issue #9332: camelCase keys silently ignored, non-URL strings
|
|
accepted as base_url, and unknown keys go unreported.
|
|
"""
|
|
|
|
import logging
|
|
|
|
import pytest
|
|
|
|
from hermes_cli.config import (
|
|
_PROVIDER_NORMALIZE_WARNED,
|
|
_normalize_custom_provider_entry,
|
|
)
|
|
|
|
|
|
class TestNormalizeCustomProviderEntry:
|
|
"""Tests for _normalize_custom_provider_entry validation."""
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _reset_warn_cache(self):
|
|
"""The normalizer deduplicates its warnings via a process-lifetime
|
|
cache; clear it around each test so warning assertions are independent
|
|
of test order."""
|
|
_PROVIDER_NORMALIZE_WARNED.clear()
|
|
yield
|
|
_PROVIDER_NORMALIZE_WARNED.clear()
|
|
|
|
|
|
|
|
|
|
|
|
def test_unknown_keys_warned_once_per_signature(self, caplog):
|
|
"""Repeated normalization of the same entry (as happens on every
|
|
picker/inventory load) must warn only once — otherwise the warning
|
|
storms the log handler. Fix B."""
|
|
entry = {
|
|
"base_url": "https://api.example.com/v1",
|
|
"api_key": "***",
|
|
"unknownField": "value",
|
|
}
|
|
with caplog.at_level(logging.WARNING):
|
|
for _ in range(5):
|
|
_normalize_custom_provider_entry(
|
|
dict(entry), provider_key="test"
|
|
)
|
|
unknown_warnings = [
|
|
r for r in caplog.records
|
|
if "unknown config keys" in r.message.lower()
|
|
]
|
|
assert len(unknown_warnings) == 1
|
|
|
|
|
|
|
|
|
|
def test_desktop_bookkeeping_keys_do_not_warn(self, caplog):
|
|
"""``key_id`` is written by the Desktop FreeModel2API panel (which key it
|
|
last put in that provider's env slot) and is not runtime config; warning
|
|
about it on every picker load would be noise our own writer caused."""
|
|
entry = {
|
|
"discover_models": False,
|
|
"key_id": 81,
|
|
"models": ["gpt-5.5"],
|
|
}
|
|
with caplog.at_level(logging.WARNING):
|
|
_normalize_custom_provider_entry(dict(entry), provider_key="freemodel2api")
|
|
assert not [r for r in caplog.records if "unknown config keys" in r.message.lower()]
|
|
|
|
def test_env_var_placeholder_in_base_url_not_rejected(self):
|
|
"""A base_url that is an un-expanded ${ENV_VAR} placeholder must not be
|
|
rejected as an invalid URL — it is expanded at runtime, so a caller
|
|
reaching this normalizer with raw config would otherwise see the
|
|
provider silently dropped. Regression test for #14457."""
|
|
entry = {
|
|
"name": "PROVIDER_A",
|
|
"base_url": "${PROVIDER_A_BASE_URL}",
|
|
"key_env": "PROVIDER_A_API_KEY",
|
|
}
|
|
result = _normalize_custom_provider_entry(entry, provider_key="PROVIDER_A")
|
|
assert result is not None
|
|
assert result["base_url"] == "${PROVIDER_A_BASE_URL}"
|
|
|
|
|
|
def test_numeric_yaml_name_and_key_become_strings(self):
|
|
"""Unquoted YAML `name: 2070` / key 2070 must not be dropped as non-str."""
|
|
from hermes_cli.config import find_provider_entry, stringify_provider_map
|
|
|
|
result = _normalize_custom_provider_entry(
|
|
{"name": 2070, "base_url": "http://192.168.1.10:8082/v1"},
|
|
provider_key=2070,
|
|
)
|
|
assert result is not None
|
|
assert result["name"] == "2070"
|
|
assert result["provider_key"] == "2070"
|
|
|
|
mapped = stringify_provider_map({2070: {"base_url": "http://x"}})
|
|
assert list(mapped) == ["2070"]
|
|
|
|
stored, entry = find_provider_entry({2070: {"base_url": "http://x"}}, "2070")
|
|
assert stored == 2070
|
|
assert entry == {"base_url": "http://x"}
|
|
|
|
|