Files
hermes-agent/tests/hermes_cli/test_anon_picker.py
T
Siddharth Balyan 3b01b4ce0f feat(desktop): Nous free tier on Hermes Desktop (#105260)
* feat(desktop): free-tier state over RPC, status routes that name it, and a sign-in that keeps connectors

The desktop learns about the Nous free tier by reading local auth state (pull): free_tier.status
answers has_guest / enabled / carries_inference / notice_pending with zero network, and
free_tier.ack_notice persists the one-time notice flag on the identity itself. setup.runtime_check
reports free_tier for the selected route; /api/portal, the Nous card in /api/providers/oauth and
billing.state carry free_tier (billing answers the free tier locally instead of a portal call that
can only fail). The free-tier picker row carries an explicit free_tier_row flag and is never priced or
locked. POST /api/providers/oauth/nous/start over a free-tier identity registers the connector
transfer and returns its code and consent URL; the poller waits for the transfer before the token
grant, persists the account, runs settle_after_upgrade, and the poll response gains reason,
account_email and model.

* feat(desktop): free tier on Hermes Desktop: ready screen, notice strip, status chip, Billing view, one sign-in dialog

The renderer reads the free tier from free_tier.status (pull) into one store; the first-launch
intro is the same state rendered two ways, keyed on the backend's one-time flag: the onboarding
overlay opens on a ready screen when the free tier carries inference, else a one-time strip above
the composer. Settings > Billing gains a free_tier view (notice with one Sign in, Plan / Model /
Connectors summary, plan card, footnote; no payment or usage rows). A status-bar chip names the
tier and model while it carries inference. Every entry point opens one claimed sign-in dialog that
drives the extended oauth/nous route and maps the poll's status and reason to the ruled screens;
Done settles billing, model options, providers and re-homes a session still on nous/welcome. The
picker badge also fires on free_tier_row. Docs: Desktop section in the free-tier guide, AGENTS notes.

* fix(desktop): free_tier.status starts the free tier's background setup when no identity exists

A served backend has no session-setup moment like the CLI's, so beside an explicit provider the free
tier was never set up on the desktop: no connectors, no notice strip. The first status read now
starts the same one-attempt background setup; the call itself never waits.

* fix(desktop): one Sign in on the Billing page; Settings > Providers names the free tier, never Connected

The free-tier plan card is the what-you-get text alone (the notice carries the page's one Sign in).
The Nous provider row reads Nous · free tier with a Free tier tag while the identity is the free
tier, instead of Nous Portal · Connected.

* fix(desktop): Settings > Providers never files the free tier under Connected

* fix(desktop): the intro's shape is keyed on the route, not on the identity

free_tier.status reports available (an identity exists and the tier is on); whether inference
runs on the free tier is setup.runtime_check.free_tier, keyed on the resolved endpoint. The ready
screen shows when that route is the free tier; the composer strip when the user's own provider
carries inference. An own-key install used to get the ready screen.

* docs(desktop): say what the free-tier chip is keyed on

* fix(desktop): the featured Nous row's pitch on the free tier says what signing in adds

* fix(desktop): a cancelled or superseded sign-in attempt can no longer change the identity or hide the intro

Four lifecycle holes from review. The Nous poller checks the session's cancelled flag after the
transfer wait, after the token grant, and once more under the session lock together with the
save, so a sign-in the user abandoned never persists. The renderer's sign-in store carries an
attempt generation that every continuation checks after each await, so a poll from a closed
attempt cannot publish over the one on screen (and its backend session is cancelled). The ready
screen comes down only after the backend recorded the acknowledgement. A composer still mounted
takes over the notice claim when its owner unmounts. One thin test per hole.
2026-09-11 03:45:32 +05:30

107 lines
4.7 KiB
Python

"""Model pickers under a Nous free-tier identity.
A guest identity carrying inference shows one row, "Nous · free tier", with the single model
``nous/welcome``; the same guest with ``nous.guest: false`` shows no Nous row at all. The rule lives
in one helper (``_free_tier_nous_row``) and this file exercises it through the real row builders
against a temp ``HERMES_HOME`` with the network catalog fetch stubbed.
"""
from __future__ import annotations
import os
from pathlib import Path
import pytest
from hermes_cli.auth import _save_auth_store
GUEST_STATE = {
"auth_method": "anonymous",
"account_tier": "anonymous",
"anon_token": "anon_t",
"access_token": "aaa.bbb.ccc",
"expires_at": "2030-01-01T00:00:00+00:00",
"inference_base_url": "https://welcome-api.nousresearch.com/v1",
}
@pytest.fixture
def guest_home(monkeypatch, tmp_path):
"""Seed a guest identity as the only Nous state and keep every row builder offline."""
monkeypatch.setenv("HERMES_SHARED_AUTH_DIR", str(tmp_path / "shared-store"))
monkeypatch.delenv("HERMES_FORCE_GUEST", raising=False)
for var in ("OPENROUTER_API_KEY", "OPENAI_API_KEY", "ANTHROPIC_API_KEY", "NOUS_API_KEY", "LM_API_KEY", "LM_BASE_URL"):
monkeypatch.delenv(var, raising=False)
_save_auth_store({"active_provider": "nous", "providers": {"nous": dict(GUEST_STATE)}})
# No network from any lap: models.dev, the Portal catalog, and Ollama Cloud all stubbed.
from agent import models_dev
from hermes_cli import models as models_mod
from hermes_cli import model_switch_providers as msp
monkeypatch.setattr(models_dev, "fetch_models_dev", lambda *a, **k: {})
monkeypatch.setattr(models_mod, "get_curated_nous_model_ids", lambda *a, **k: ["anthropic/claude-x", "openai/gpt-y"])
monkeypatch.setattr(models_mod, "fetch_ollama_cloud_models", lambda *a, **k: [])
monkeypatch.setattr(msp, "_nous_picker_model_ids", lambda *a, **k: pytest.fail("guest must not fetch the Portal catalog"))
return Path(os.environ["HERMES_HOME"])
def _write_config(monkeypatch, home: Path, text: str) -> None:
(home / "config.yaml").write_text(text)
from hermes_cli import config as cfg_mod
for attr in ("_config_cache", "_cached_config"):
if hasattr(cfg_mod, attr):
monkeypatch.setattr(cfg_mod, attr, None, raising=False)
def _nous_rows(rows):
return [r for r in rows if str(r.get("slug", "")).lower() == "nous"]
def _cli_nous_rows(config):
from hermes_cli.main_provider_setup import _build_provider_picker_rows
ordered, _ = _build_provider_picker_rows(config, "nous", {}, {})
return [(key, label) for key, label, _members in ordered if key == "nous"]
def test_guest_identity_shows_free_tier_row_with_only_welcome_model(guest_home, monkeypatch):
from hermes_cli.model_switch_providers import list_picker_providers
rows = _nous_rows(list_picker_providers("nous", "", None, None, 50, "nous/welcome"))
assert len(rows) == 1
row = rows[0]
assert "free tier" in row["name"]
assert row["models"] == ["nous/welcome"]
assert row["total_models"] == 1
rendered = repr(row).lower()
assert "guest" not in rendered and "anonymous" not in rendered
# The `hermes model` provider picker applies the same rule from the same helper.
cli_rows = _cli_nous_rows({})
assert len(cli_rows) == 1
assert "free tier" in cli_rows[0][1]
assert "guest" not in cli_rows[0][1].lower() and "anonymous" not in cli_rows[0][1].lower()
def test_guest_identity_with_guest_off_hides_the_nous_row(guest_home, monkeypatch):
_write_config(monkeypatch, guest_home, "nous:\n guest: false\n")
from hermes_cli import anon_auth
assert anon_auth.has_guest() and not anon_auth.guest_enabled()
from hermes_cli.model_switch_providers import list_picker_providers
assert _nous_rows(list_picker_providers("nous", "", None, None, 50, "nous/welcome")) == []
assert _cli_nous_rows({"nous": {"guest": False}}) == []
def test_desktop_picker_payload_never_locks_the_free_tier_row(guest_home, monkeypatch):
"""``model.options`` (the desktop's path) prices rows from caches on a normal open; the free-tier
row has no Portal pricing and no entitlement to read, so it must be left alone rather than locked."""
from hermes_cli import inventory
monkeypatch.setattr(inventory, "_prewarm_pricing_async", lambda *a, **k: None)
payload = inventory.build_model_options_payload(inventory.load_picker_context())
rows = _nous_rows(payload["providers"])
assert len(rows) == 1
row = rows[0]
assert row["free_tier_row"] is True
assert row["models"] == ["nous/welcome"]
assert row.get("unavailable_models", []) == []
assert not row.get("free_tier_pending") and not row.get("pricing_pending")