Merge remote-tracking branch 'origin/main' into bb/tui-long-session-perf

This commit is contained in:
Brooklyn Nicholson 2026-04-26 21:07:15 -05:00
commit 7da2f07641
115 changed files with 17650 additions and 406 deletions

View file

@ -149,3 +149,46 @@ def test_get_nous_subscription_features_requires_agent_browser_for_browserbase(m
assert features.browser.active is False
assert features.browser.managed_by_nous is False
assert features.browser.current_provider == "Browserbase"
def test_get_nous_subscription_features_does_not_treat_quoted_false_as_gateway_opt_in(monkeypatch):
env = {"EXA_API_KEY": "exa-test"}
monkeypatch.setattr(ns, "get_env_value", lambda name: env.get(name, ""))
monkeypatch.setattr(ns, "get_nous_auth_status", lambda: {"logged_in": True})
monkeypatch.setattr(ns, "managed_nous_tools_enabled", lambda: True)
monkeypatch.setattr(ns, "_toolset_enabled", lambda config, key: key == "web")
monkeypatch.setattr(ns, "_has_agent_browser", lambda: False)
monkeypatch.setattr(ns, "resolve_openai_audio_api_key", lambda: "")
monkeypatch.setattr(ns, "has_direct_modal_credentials", lambda: False)
monkeypatch.setattr(ns, "is_managed_tool_gateway_ready", lambda vendor: vendor == "firecrawl")
features = ns.get_nous_subscription_features(
{"web": {"backend": "exa", "use_gateway": "false"}}
)
assert features.web.available is True
assert features.web.active is True
assert features.web.managed_by_nous is False
assert features.web.direct_override is True
assert features.web.current_provider == "exa"
def test_get_gateway_eligible_tools_ignores_quoted_false_opt_in(monkeypatch):
monkeypatch.setattr(ns, "managed_nous_tools_enabled", lambda: True)
monkeypatch.setattr(
ns,
"_get_gateway_direct_credentials",
lambda: {"web": True, "image_gen": False, "tts": False, "browser": False},
)
unconfigured, has_direct, already_managed = ns.get_gateway_eligible_tools(
{
"model": {"provider": "nous"},
"web": {"use_gateway": "false"},
}
)
assert "web" in has_direct
assert "web" not in already_managed
assert set(unconfigured) == {"image_gen", "tts", "browser"}

View file

@ -401,14 +401,21 @@ class TestSessionBrowseArgparse:
from hermes_cli.main import _session_browse_picker
assert callable(_session_browse_picker)
def test_browse_default_limit_is_50(self):
"""The default --limit for browse should be 50."""
# This test verifies at the argparse level
# We test by running the parse on "sessions browse" args
# Since we can't easily extract the subparser, verify via the
# _session_browse_picker accepting large lists
sessions = _make_sessions(50)
assert len(sessions) == 50
def test_browse_default_limit_is_500(self):
"""The default --limit for browse should be 500."""
# Build the same argparse tree cmd_sessions uses and verify the default.
import argparse
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(dest="sessions_action")
browse = subparsers.add_parser("browse")
browse.add_argument("--source")
browse.add_argument("--limit", type=int, default=500)
args = parser.parse_args(["browse"])
assert args.limit == 500
args = parser.parse_args(["browse", "--limit", "42"])
assert args.limit == 42
# ─── Integration: cmd_sessions browse action ────────────────────────────────

View file

@ -12,7 +12,7 @@ def test_sessions_delete_accepts_unique_id_prefix(monkeypatch, capsys):
captured["resolved_from"] = session_id
return "20260315_092437_c9a6ff"
def delete_session(self, session_id):
def delete_session(self, session_id, **kwargs):
captured["deleted"] = session_id
return True
@ -45,7 +45,7 @@ def test_sessions_delete_reports_not_found_when_prefix_is_unknown(monkeypatch, c
def resolve_session_id(self, session_id):
return None
def delete_session(self, session_id):
def delete_session(self, session_id, **kwargs):
raise AssertionError("delete_session should not be called when resolution fails")
def close(self):
@ -73,7 +73,7 @@ def test_sessions_delete_handles_eoferror_on_confirm(monkeypatch, capsys):
def resolve_session_id(self, session_id):
return "20260315_092437_c9a6ff"
def delete_session(self, session_id):
def delete_session(self, session_id, **kwargs):
raise AssertionError("delete_session should not be called when cancelled")
def close(self):

View file

@ -0,0 +1,30 @@
"""Regression: ``hermes setup`` for the ollama-cloud provider must force-refresh
the model cache after the user supplies a key, otherwise the picker keeps
serving a stale cache (models.dev only, no live API probe) for up to an hour.
"""
from __future__ import annotations
from unittest.mock import patch
def test_setup_ollama_cloud_passes_force_refresh(monkeypatch):
"""The provider-setup model-fetch for ollama-cloud must pass ``force_refresh=True``."""
import hermes_cli.main as main_mod
import inspect
src = inspect.getsource(main_mod)
# Locate the ollama-cloud branch in the provider setup flow.
marker = 'provider_id == "ollama-cloud"'
assert marker in src, "ollama-cloud branch missing from provider setup"
idx = src.index(marker)
# The call to fetch_ollama_cloud_models should be within the next ~2000 chars.
snippet = src[idx:idx + 2000]
assert "fetch_ollama_cloud_models(" in snippet, snippet[:500]
assert "force_refresh=True" in snippet, (
"ollama-cloud setup must pass force_refresh=True so newly released "
"models (e.g. deepseek v4 flash, kimi k2.6) appear the moment the "
"user enters their key, not an hour later when the cache TTL expires. "
f"Snippet: {snippet[:500]}"
)

View file

@ -41,6 +41,36 @@ def test_get_platform_tools_homeassistant_platform_keeps_homeassistant_toolset()
assert "homeassistant" in enabled
def test_get_platform_tools_homeassistant_toolset_enabled_for_cron_when_hass_token_set(monkeypatch):
"""HA toolset is runtime-gated by check_fn (requires HASS_TOKEN).
When HASS_TOKEN is set, the user has explicitly opted in _DEFAULT_OFF_TOOLSETS
shouldn't also strip HA from platforms (like cron) that run through
_get_platform_tools without an explicit saved toolset list.
Regression guard for Norbert's HA cron breakage after #14798 made cron
honor per-platform tool config.
"""
monkeypatch.setenv("HASS_TOKEN", "fake-test-token")
cron_enabled = _get_platform_tools({}, "cron")
assert "homeassistant" in cron_enabled
# moa must stay off — the original goal of #14798
assert "moa" not in cron_enabled
cli_enabled = _get_platform_tools({}, "cli")
assert "homeassistant" in cli_enabled
def test_get_platform_tools_homeassistant_toolset_off_for_cron_when_hass_token_missing(monkeypatch):
"""Without HASS_TOKEN, HA stays off by default — preserves #14798's behavior
for users who never configured HA."""
monkeypatch.delenv("HASS_TOKEN", raising=False)
cron_enabled = _get_platform_tools({}, "cron")
assert "homeassistant" not in cron_enabled
def test_get_platform_tools_preserves_explicit_empty_selection():
config = {"platform_toolsets": {"cli": []}}

View file

@ -0,0 +1,121 @@
"""Tests for _web_ui_build_needed — staleness check for the web UI dist.
Critical invariant: the Vite build outputs to hermes_cli/web_dist/
(vite.config.ts: outDir: "../hermes_cli/web_dist"), NOT web/dist/.
The sentinel must be checked in the correct output directory or the
freshness check is a no-op and the OOM rebuild always runs.
"""
import os
import time
from pathlib import Path
from unittest.mock import patch
import pytest
from hermes_cli.main import _web_ui_build_needed, _build_web_ui
def _touch(path: Path, offset: float = 0.0) -> None:
path.parent.mkdir(parents=True, exist_ok=True)
path.touch()
if offset:
t = time.time() + offset
os.utime(path, (t, t))
def _make_web_dir(tmp_path: Path) -> tuple[Path, Path]:
"""Return (web_dir, dist_dir) matching real repo layout."""
web_dir = tmp_path / "web"
web_dir.mkdir()
(web_dir / "package.json").touch()
dist_dir = tmp_path / "hermes_cli" / "web_dist"
return web_dir, dist_dir
class TestWebUIBuildNeeded:
def test_returns_true_when_dist_missing(self, tmp_path):
web_dir, _ = _make_web_dir(tmp_path)
assert _web_ui_build_needed(web_dir) is True
def test_returns_false_when_vite_manifest_fresh(self, tmp_path):
web_dir, dist_dir = _make_web_dir(tmp_path)
_touch(web_dir / "src" / "App.tsx", offset=-10)
_touch(dist_dir / ".vite" / "manifest.json")
assert _web_ui_build_needed(web_dir) is False
def test_returns_true_when_source_newer_than_manifest(self, tmp_path):
web_dir, dist_dir = _make_web_dir(tmp_path)
_touch(dist_dir / ".vite" / "manifest.json", offset=-10)
_touch(web_dir / "src" / "App.tsx")
assert _web_ui_build_needed(web_dir) is True
def test_falls_back_to_index_html_when_manifest_missing(self, tmp_path):
web_dir, dist_dir = _make_web_dir(tmp_path)
_touch(web_dir / "src" / "main.ts", offset=-10)
_touch(dist_dir / "index.html")
assert _web_ui_build_needed(web_dir) is False
def test_web_dist_dir_not_web_dist_subdir(self, tmp_path):
"""Regression: sentinel must be in hermes_cli/web_dist/, NOT web/dist/."""
web_dir, dist_dir = _make_web_dir(tmp_path)
_touch(web_dir / "src" / "App.tsx", offset=-10)
# Place manifest in wrong location (web/dist/) — should NOT count as fresh
wrong_dist = web_dir / "dist" / ".vite" / "manifest.json"
_touch(wrong_dist)
# Correct location is empty → still needs build
assert _web_ui_build_needed(web_dir) is True
def test_returns_true_when_package_lock_newer_than_dist(self, tmp_path):
web_dir, dist_dir = _make_web_dir(tmp_path)
_touch(dist_dir / ".vite" / "manifest.json", offset=-10)
_touch(web_dir / "package-lock.json")
assert _web_ui_build_needed(web_dir) is True
def test_returns_true_when_vite_config_newer_than_dist(self, tmp_path):
web_dir, dist_dir = _make_web_dir(tmp_path)
_touch(dist_dir / ".vite" / "manifest.json", offset=-10)
_touch(web_dir / "vite.config.ts")
assert _web_ui_build_needed(web_dir) is True
def test_ignores_node_modules(self, tmp_path):
web_dir, dist_dir = _make_web_dir(tmp_path)
# package.json older than manifest; only node_modules file is newer
_touch(web_dir / "package.json", offset=-20)
_touch(dist_dir / ".vite" / "manifest.json", offset=-10)
_touch(web_dir / "node_modules" / "react" / "index.js")
assert _web_ui_build_needed(web_dir) is False
def test_ignores_dist_subdir_under_web(self, tmp_path):
web_dir, dist_dir = _make_web_dir(tmp_path)
# package.json older than manifest; only web/dist file is newer
_touch(web_dir / "package.json", offset=-20)
_touch(dist_dir / ".vite" / "manifest.json", offset=-10)
_touch(web_dir / "dist" / "assets" / "index.js")
assert _web_ui_build_needed(web_dir) is False
class TestBuildWebUISkipsWhenFresh:
def test_skips_npm_when_dist_is_fresh(self, tmp_path):
web_dir, dist_dir = _make_web_dir(tmp_path)
_touch(dist_dir / ".vite" / "manifest.json")
with patch("hermes_cli.main.shutil.which", return_value="/usr/bin/npm"), \
patch("hermes_cli.main.subprocess.run") as mock_run:
result = _build_web_ui(web_dir)
assert result is True
mock_run.assert_not_called()
def test_runs_npm_when_dist_missing(self, tmp_path):
web_dir, _ = _make_web_dir(tmp_path)
mock_cp = __import__("subprocess").CompletedProcess([], 0, stdout=b"", stderr=b"")
with patch("hermes_cli.main.shutil.which", return_value="/usr/bin/npm"), \
patch("hermes_cli.main.subprocess.run", return_value=mock_cp) as mock_run:
result = _build_web_ui(web_dir)
assert result is True
assert mock_run.call_count == 2 # npm install + npm run build