From ce9ddd35e7922594ef6fc2a468bbf3b3b5765c86 Mon Sep 17 00:00:00 2001 From: chelsealong Date: Sun, 23 Aug 2026 03:15:43 +0000 Subject: [PATCH] fix(gateway): fix 3-tuple/4-tuple arity crash in get_gateway_eligible_tools MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The early "fail closed" returns (account fetch error, not entitled, non-nous provider) still returned 3-element tuples after the function's happy path and every caller moved to a 4-tuple, crashing prompt_enable_tool_gateway with ValueError for any logged-in Nous account that isn't paid or pool-entitled — the common case, hit unconditionally from `hermes model`. --- hermes_cli/nous_subscription.py | 6 +++--- tests/hermes_cli/test_nous_subscription.py | 23 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/hermes_cli/nous_subscription.py b/hermes_cli/nous_subscription.py index a6fe82ac0e..115865ea8b 100644 --- a/hermes_cli/nous_subscription.py +++ b/hermes_cli/nous_subscription.py @@ -1073,9 +1073,9 @@ def get_gateway_eligible_tools( try: account_info = get_nous_portal_account_info(force_fresh=force_fresh) except Exception: - return [], [], [] + return [], [], [], [] if not (account_info and account_info.logged_in and account_info.tool_gateway_entitled): - return [], [], [] + return [], [], [], [] if config is None: config = load_config() or {} @@ -1083,7 +1083,7 @@ def get_gateway_eligible_tools( # Quick provider check without the heavy get_nous_subscription_features call model_cfg = config.get("model") if not isinstance(model_cfg, dict) or str(model_cfg.get("provider") or "").strip().lower() != "nous": - return [], [], [] + return [], [], [], [] direct = _get_gateway_direct_credentials() diff --git a/tests/hermes_cli/test_nous_subscription.py b/tests/hermes_cli/test_nous_subscription.py index 7a83150113..5ba44836d6 100644 --- a/tests/hermes_cli/test_nous_subscription.py +++ b/tests/hermes_cli/test_nous_subscription.py @@ -228,6 +228,29 @@ def test_get_gateway_eligible_tools_treats_explicit_backend_as_configured(monkey assert "web" not in already_managed +def test_get_gateway_eligible_tools_not_entitled_returns_four_empty_lists(monkeypatch): + """A logged-in Nous account with no paid access and no free tool pool + must fail closed with a 4-tuple, not a 3-tuple — regression for a crash + where the early 'not entitled' return still had the pre-refactor arity + while the happy path and every caller had moved to 4 values.""" + monkeypatch.setattr(ns, "get_nous_portal_account_info", lambda **kw: _account(logged_in=True, paid=False)) + + config = {"model": {"provider": "nous"}} + result = ns.get_gateway_eligible_tools(config) + + assert result == ([], [], [], []) + + +def test_prompt_enable_tool_gateway_not_entitled_does_not_crash(monkeypatch): + """The unconditional call site in model_setup_flows (no try/except) must + not raise when a Nous account is logged in but not entitled to the Tool + Gateway (i.e. an ordinary non-paid, non-pool account).""" + monkeypatch.setattr(ns, "get_nous_portal_account_info", lambda **kw: _account(logged_in=True, paid=False)) + + config = {"model": {"provider": "nous"}} + assert ns.prompt_enable_tool_gateway(config) == set() + + def test_prompt_enable_tool_gateway_never_offers_explicit_backend(monkeypatch): """The checklist itself must not list (let alone pre-check) a tool with an explicit non-nous selection, so it can never be silently overwritten