Files
hermes-agent/tests/hermes_cli/test_web_recommended_default_profile.py
teknium1 a3ad3c0c58 test(dashboard): the Nous recommended-default test uses the hermetic home fixture (#124283, salvage #124284)
The salvaged fixture set HERMES_HOME under tmp_path and ran the TestClient lifespan, which
read the checkout manifest and tripped the home-I/O guard; the unknown-profile case folds
into the one invariant test (the non-Nous branch is covered by test_web_unknown_profile_404).
2026-09-28 12:18:58 -07:00

50 lines
2.0 KiB
Python

"""``GET /api/model/recommended-default?provider=nous`` answers for the requested profile.
The Nous branch returned before the route entered the profile scope, so ``?profile=b`` got the
tier read, Portal URL and caches of the profile that launched the dashboard, and an unknown
profile answered 200 instead of the scope's 404. Only the Portal account read is stubbed.
"""
from types import SimpleNamespace
import pytest
pytest.importorskip("fastapi")
from fastapi.testclient import TestClient # noqa: E402
@pytest.fixture()
def client(_isolate_hermes_home, monkeypatch):
from hermes_cli import profiles as profiles_mod
freebie = profiles_mod.get_profile_dir("freebie")
freebie.mkdir(parents=True, exist_ok=True)
(freebie / "config.yaml").write_text("model: {}\n", encoding="utf-8")
from hermes_constants import get_hermes_home
import hermes_cli.nous_account as nous_account
# The launch profile's account is paid, the "freebie" profile's is free tier.
monkeypatch.setattr(nous_account, "get_nous_portal_account_info", lambda **_k: SimpleNamespace(
is_free_tier=get_hermes_home().name == "freebie"))
from hermes_cli.web_server import app, _SESSION_HEADER_NAME, _SESSION_TOKEN
c = TestClient(app, raise_server_exceptions=False)
c.headers[_SESSION_HEADER_NAME] = _SESSION_TOKEN
return c
def test_nous_recommendation_reads_the_requested_profile(client):
launch = client.get("/api/model/recommended-default", params={"provider": "nous"})
named = client.get("/api/model/recommended-default",
params={"provider": "nous", "profile": "freebie"})
unknown = client.get("/api/model/recommended-default",
params={"provider": "nous", "profile": "no-such-profile"})
assert launch.status_code == named.status_code == 200
assert launch.json()["free_tier"] is False
assert named.json()["free_tier"] is True
assert unknown.status_code == 404, unknown.text
assert "no-such-profile" in unknown.json()["detail"]