refactor(inventory): make force_fresh_nous_tier keyword-only + pin contract

Follow-up to the salvaged perf fix. The new force_fresh_nous_tier param was
inserted into list_authenticated_providers between custom_providers and
max_models. Make it keyword-only (*) so a positional caller passing max_models
as the 5th arg can never silently mis-bind it to the tier-refresh flag, and
add a signature-contract test that fails if the keyword-only separator is
later dropped. All in-repo callers already use keyword args; verified no
caller breaks.
This commit is contained in:
kshitijk4poor 2026-06-07 13:02:30 +05:30 committed by kshitij
parent eb70ab894b
commit 44c0c2d4ac
2 changed files with 19 additions and 0 deletions

View file

@ -1178,6 +1178,7 @@ def list_authenticated_providers(
current_base_url: str = "",
user_providers: dict = None,
custom_providers: list | None = None,
*,
force_fresh_nous_tier: bool = False,
max_models: int = 8,
current_model: str = "",

View file

@ -217,6 +217,24 @@ def test_build_models_payload_can_force_fresh_nous_tier():
assert mock_list.call_args.kwargs["force_fresh_nous_tier"] is True
def test_list_authenticated_providers_force_fresh_is_keyword_only():
"""``force_fresh_nous_tier`` must be keyword-only on the public listing API.
It was inserted between ``custom_providers`` and ``max_models``; making it
keyword-only ensures no positional caller passing ``max_models`` as the 5th
arg silently mis-binds it to the tier-refresh flag. Pin the contract so a
future signature edit that drops the ``*`` separator is caught.
"""
import inspect
from hermes_cli.model_switch import list_authenticated_providers
sig = inspect.signature(list_authenticated_providers)
param = sig.parameters["force_fresh_nous_tier"]
assert param.kind is inspect.Parameter.KEYWORD_ONLY
assert param.default is False
def test_pricing_uses_cached_nous_tier_by_default():
rows = [_nous_row()]
ctx = _empty_ctx(provider="nous", model="openai/gpt-5.5")