fix(inventory): avoid fresh Nous tier checks in picker payloads
This commit is contained in:
@@ -141,6 +141,18 @@ def _list_auth_returning(rows: list[dict]):
|
||||
)
|
||||
|
||||
|
||||
def _nous_row(model: str = "openai/gpt-5.5") -> dict:
|
||||
return {
|
||||
"slug": "nous",
|
||||
"name": "Nous",
|
||||
"models": [model],
|
||||
"total_models": 1,
|
||||
"is_current": True,
|
||||
"is_user_defined": False,
|
||||
"source": "built-in",
|
||||
}
|
||||
|
||||
|
||||
def test_build_models_payload_returns_expected_shape():
|
||||
rows = [
|
||||
{"slug": "openrouter", "name": "OpenRouter", "models": ["m1"],
|
||||
@@ -173,6 +185,80 @@ def test_build_models_payload_does_not_call_provider_model_ids():
|
||||
mock_pm.assert_not_called()
|
||||
|
||||
|
||||
def test_build_models_payload_uses_cached_nous_tier_by_default():
|
||||
"""Picker payloads should not force fresh Nous account checks.
|
||||
|
||||
Desktop/status picker opens are request/response UI paths. They can hit
|
||||
the short free-tier cache; explicit model/auth flows can still opt into a
|
||||
fresh account check when needed.
|
||||
"""
|
||||
ctx = _empty_ctx(provider="nous", model="openai/gpt-5.5")
|
||||
rows = [_nous_row()]
|
||||
with patch(
|
||||
"hermes_cli.model_switch.list_authenticated_providers",
|
||||
return_value=rows,
|
||||
) as mock_list:
|
||||
build_models_payload(ctx)
|
||||
|
||||
mock_list.assert_called_once()
|
||||
assert mock_list.call_args.kwargs["force_fresh_nous_tier"] is False
|
||||
|
||||
|
||||
def test_build_models_payload_can_force_fresh_nous_tier():
|
||||
ctx = _empty_ctx(provider="nous", model="openai/gpt-5.5")
|
||||
rows = [_nous_row()]
|
||||
with patch(
|
||||
"hermes_cli.model_switch.list_authenticated_providers",
|
||||
return_value=rows,
|
||||
) as mock_list:
|
||||
build_models_payload(ctx, force_fresh_nous_tier=True)
|
||||
|
||||
mock_list.assert_called_once()
|
||||
assert mock_list.call_args.kwargs["force_fresh_nous_tier"] is True
|
||||
|
||||
|
||||
def test_pricing_uses_cached_nous_tier_by_default():
|
||||
rows = [_nous_row()]
|
||||
ctx = _empty_ctx(provider="nous", model="openai/gpt-5.5")
|
||||
with (
|
||||
_list_auth_returning(rows),
|
||||
patch(
|
||||
"hermes_cli.models.get_pricing_for_provider",
|
||||
return_value={
|
||||
"openai/gpt-5.5": {
|
||||
"prompt": "0.000001",
|
||||
"completion": "0.000002",
|
||||
},
|
||||
},
|
||||
),
|
||||
patch("hermes_cli.models.check_nous_free_tier", return_value=False) as mock_free,
|
||||
):
|
||||
build_models_payload(ctx, pricing=True)
|
||||
|
||||
mock_free.assert_called_once_with(force_fresh=False)
|
||||
|
||||
|
||||
def test_pricing_can_force_fresh_nous_tier():
|
||||
rows = [_nous_row()]
|
||||
ctx = _empty_ctx(provider="nous", model="openai/gpt-5.5")
|
||||
with (
|
||||
_list_auth_returning(rows),
|
||||
patch(
|
||||
"hermes_cli.models.get_pricing_for_provider",
|
||||
return_value={
|
||||
"openai/gpt-5.5": {
|
||||
"prompt": "0.000001",
|
||||
"completion": "0.000002",
|
||||
},
|
||||
},
|
||||
),
|
||||
patch("hermes_cli.models.check_nous_free_tier", return_value=False) as mock_free,
|
||||
):
|
||||
build_models_payload(ctx, pricing=True, force_fresh_nous_tier=True)
|
||||
|
||||
mock_free.assert_called_once_with(force_fresh=True)
|
||||
|
||||
|
||||
def test_include_unconfigured_appends_canonical_skeletons():
|
||||
"""include_unconfigured=True adds CANONICAL_PROVIDERS rows that
|
||||
list_authenticated_providers didn't emit. Skeleton rows have empty
|
||||
|
||||
Reference in New Issue
Block a user