mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-06-12 08:51:53 +00:00
* feat(dashboard): unify multi-profile management — one machine dashboard, global profile switcher The dashboard becomes a machine-level management surface with one write-target selector, replacing per-profile dashboard fragmentation. Backend: - profile param (query or body) on /api/config (get/put/raw), /api/env (get/put/delete/reveal), /api/mcp/servers (list/add/remove/test/enabled), /api/mcp/catalog (list/install), /api/model/info, /api/model/set — all scoped through the existing _profile_scope() context manager - model/set restructured: expensive-model warning (await) runs before the scope; the config write runs sync inside the scope in a worker thread - MCP catalog installs + git-bootstrap entries spawn 'hermes -p <profile>' - chat PTY: ?profile= on /api/pty points the child's HERMES_HOME at the profile dir (its own gateway subprocess, config/skills/memory/state.db all profile-bound); in-process gateway attach skipped when scoped CLI launch unification: - '<profile> dashboard' routes to the machine dashboard: attach (open browser at ?profile=) when one is listening, else re-exec pinned to the default profile with --open-profile preselecting the launcher - --isolated preserves the old dedicated per-profile server behavior - start_server(initial_profile=...) appends ?profile= to the auto-open URL Frontend: - ProfileProvider + sidebar ProfileSwitcher: ONE global selector, URL- persisted (?profile=), mirrored into fetchJSON which auto-appends the param to the scoped endpoint families (explicit params win) - app-wide amber banner names the managed profile - SkillsPage's page-local selector (from the skills-scoping PR) folded into the global context — single source of truth - ChatPage threads the scope into the PTY WS URL; switching profiles remounts the terminal into a fresh scoped session Omitted profile keeps legacy behavior everywhere. * docs(dashboard): document machine-level multi-profile management - web-dashboard.md: 'Managing multiple profiles' section (switcher, URL deep-links, unified launch, --isolated, scoped Chat, what stays per-profile) + --isolated in the options table - profiles.md: 'From the dashboard' subsection + set-as-active vs switcher clarification - cli-commands.md: --isolated flag + profile-alias launch example * fix(dashboard): address profile-unification review findings Review findings (dev review on PR #44007): 1. HIGH — stale page state on profile switch: pages load data on mount and didn't consume the profile scope, so a page opened under profile A kept showing A's state while writes silently targeted the newly selected B. Fixed structurally: ProfileKeyedRoutes wraps the routed page tree and keys it by the selected profile, remounting every page (fresh state + refetch) on switch. ChatPage keeps its own remount (channel keyed on scopedProfile). 2. HIGH — /api/model/auxiliary read was unscoped while /api/model/set wrote scoped (Models page could show default's aux pins while editing worker's). Endpoint now takes profile + _profile_scope, added to PROFILE_SCOPED_PREFIXES, HTTPException re-raise so ghost profiles 404 instead of 500. Regression test asserts read/write symmetry with differing worker/default aux config. 3. MEDIUM — tools post-setup spawned unscoped from the profile-aware drawer. Now spawns 'hermes -p <profile> tools post-setup <key>' (same mechanism as hub installs); drawer threads its profile prop. Most hooks install machine-level artifacts where the scope is inert, but hooks reading config/env now see the drawer's HERMES_HOME. 4. LOW — ty warnings: env Optional asserts before subscript/membership, fastapi import replaced with web_server.HTTPException re-use. 298 tests green across the four affected suites; tsc -b + vite build green; aux scoping E2E-verified with real imports. * fix(dashboard): address second profile-unification review (gille) 1. BLOCKER — profile scope dropped on sidebar navigation: ProfileProvider derived the selection from the current URL, and nav links are bare paths, so clicking Config from /skills?profile=worker silently reset the write target. State is now the source of truth; an effect re-asserts ?profile= onto the new location after every navigation (URL stays a synchronized projection for deep links/refresh), and an incoming URL param (e.g. 'Manage skills & tools' links) still wins. 2. BLOCKER — /api/model/options unscoped while model/set wrote scoped: the picker context (current model/provider, custom providers, per-profile .env auth state) now loads inside _profile_scope; added to PROFILE_SCOPED_PREFIXES. Test: a worker-only current-model pin appears in the scoped payload and not the unscoped one. 3. BLOCKER — MCP test-server probe escaped the scope after the config read: the probe now re-enters _profile_scope inside the worker thread so env-placeholder expansion resolves against the selected profile's .env. Known limit (documented): the probe's dedicated MCP event-loop thread doesn't inherit the contextvar (OAuth token paths). Test asserts get_hermes_home() inside the probe == the worker profile dir. 4. BLOCKER — broad excepts swallowed unknown-profile 404s: /api/model/info degraded to 200-with-empty-model-info and /api/mcp/catalog to a silently-empty catalog. Both re-raise HTTPException; 404 regression tests added for info/options/catalog. Polish: scope banner clears the fixed mobile header (mt-14 lg:mt-0); --open-profile hidden via argparse.SUPPRESS (internal re-exec flag); attach-path test now asserts the opened ?profile= URL. (Stale-page-state + /api/model/auxiliary findings from this review were already fixed in92bcd1568— the review ran againste600f6951.) 35 tests in the two new suites + 274 in the adjacent ones, all green; tsc -b + vite build green; scoping E2E-verified with real imports. * docs(dashboard)+fix: self-review pass — Profiles page section, REST profile-param tip, body-beats-query precedence Docs: - web-dashboard.md: add the missing 'Profiles' subsection to Pages (cards, create/builder, manage-skills jump, set-as-active vs switcher distinction, editors); REST API section gets a profile-scoped-endpoints tip documenting ?profile= / body profile / 404 semantics / /api/pty - (profiles.md + cli-commands.md were already updated ine600f6951) Precedence fix: scoped endpoints taking BOTH a query param and a body field now resolve body.profile first. The SPA's fetchJSON injects the query param from the GLOBAL switcher; an explicit body.profile (e.g. Profile Builder flows writing into a specific new profile) is the more specific intent and must not be overridden by whatever the sidebar happens to be set to. Matches the documented 'explicit beats global' contract in api.ts. Verified: 304 tests green across the four suites; tsc -b + vite build green; docusaurus build green (only pre-existing broken-link warnings, none from this PR's pages).
130 lines
5.2 KiB
Python
130 lines
5.2 KiB
Python
"""Tests for the unified profile→machine dashboard launch routing.
|
|
|
|
`<profile> dashboard` routes to ONE machine-level dashboard instead of
|
|
spawning a per-profile server: attach (open browser at ?profile=) when one
|
|
is already listening, else re-exec as the machine dashboard with the
|
|
launching profile preselected. `--isolated` opts out.
|
|
"""
|
|
import sys
|
|
import types
|
|
import pytest
|
|
|
|
|
|
@pytest.fixture
|
|
def main_mod():
|
|
import hermes_cli.main as main_mod
|
|
return main_mod
|
|
|
|
|
|
def _args(**kw):
|
|
defaults = dict(
|
|
status=False, stop=False, host="127.0.0.1", port=9119,
|
|
no_open=True, insecure=False, skip_build=False,
|
|
isolated=False, open_profile="",
|
|
)
|
|
defaults.update(kw)
|
|
return types.SimpleNamespace(**defaults)
|
|
|
|
|
|
class TestUnifiedDashboardRouting:
|
|
def test_profile_launch_attaches_to_running_dashboard(self, main_mod, monkeypatch):
|
|
monkeypatch.setattr(
|
|
"hermes_cli.profiles.get_active_profile_name", lambda: "worker_x"
|
|
)
|
|
monkeypatch.setattr(main_mod, "_dashboard_listening", lambda host, port: True)
|
|
execs = []
|
|
monkeypatch.setattr(main_mod.os, "execvpe", lambda *a, **k: execs.append(a))
|
|
|
|
with pytest.raises(SystemExit) as exc:
|
|
main_mod.cmd_dashboard(_args())
|
|
assert exc.value.code == 0
|
|
assert execs == [] # attached, never re-exec'd
|
|
|
|
def test_profile_launch_attach_opens_scoped_url(self, main_mod, monkeypatch):
|
|
"""The attach path must open the browser at ?profile=<name> — that
|
|
URL is the entire point of attaching (preselects the switcher)."""
|
|
monkeypatch.setattr(
|
|
"hermes_cli.profiles.get_active_profile_name", lambda: "worker_x"
|
|
)
|
|
monkeypatch.setattr(main_mod, "_dashboard_listening", lambda host, port: True)
|
|
opened = []
|
|
import webbrowser
|
|
monkeypatch.setattr(webbrowser, "open", lambda url: opened.append(url))
|
|
|
|
with pytest.raises(SystemExit) as exc:
|
|
main_mod.cmd_dashboard(_args(no_open=False))
|
|
assert exc.value.code == 0
|
|
assert opened == ["http://127.0.0.1:9119/?profile=worker_x"]
|
|
|
|
def test_profile_launch_reexecs_machine_dashboard(self, main_mod, monkeypatch):
|
|
monkeypatch.setattr(
|
|
"hermes_cli.profiles.get_active_profile_name", lambda: "worker_x"
|
|
)
|
|
monkeypatch.setattr(main_mod, "_dashboard_listening", lambda host, port: False)
|
|
execs = []
|
|
|
|
def fake_exec(exe, argv, env):
|
|
execs.append((exe, argv, env))
|
|
raise SystemExit(0) # execvpe never returns
|
|
|
|
monkeypatch.setattr(main_mod.os, "execvpe", fake_exec)
|
|
|
|
with pytest.raises(SystemExit):
|
|
main_mod.cmd_dashboard(_args())
|
|
|
|
assert len(execs) == 1
|
|
exe, argv, env = execs[0]
|
|
assert exe == sys.executable
|
|
# Pinned to the default profile + launching profile preselected.
|
|
assert "-p" in argv and argv[argv.index("-p") + 1] == "default"
|
|
assert "--open-profile" in argv
|
|
assert argv[argv.index("--open-profile") + 1] == "worker_x"
|
|
# Profile HERMES_HOME dropped so the child binds the machine root.
|
|
assert "HERMES_HOME" not in env
|
|
|
|
def test_isolated_flag_skips_routing(self, main_mod, monkeypatch):
|
|
monkeypatch.setattr(
|
|
"hermes_cli.profiles.get_active_profile_name", lambda: "worker_x"
|
|
)
|
|
listening_calls = []
|
|
monkeypatch.setattr(
|
|
main_mod, "_dashboard_listening",
|
|
lambda host, port: listening_calls.append(1) or True,
|
|
)
|
|
# With --isolated the routing block is skipped entirely; the command
|
|
# proceeds to dependency checks. Make the first post-routing step
|
|
# bail so the test doesn't actually start a server.
|
|
monkeypatch.setitem(sys.modules, "fastapi", None)
|
|
|
|
with pytest.raises((SystemExit, AttributeError, ImportError, TypeError)):
|
|
main_mod.cmd_dashboard(_args(isolated=True))
|
|
assert listening_calls == []
|
|
|
|
def test_default_profile_launch_skips_routing(self, main_mod, monkeypatch):
|
|
monkeypatch.setattr(
|
|
"hermes_cli.profiles.get_active_profile_name", lambda: "default"
|
|
)
|
|
listening_calls = []
|
|
monkeypatch.setattr(
|
|
main_mod, "_dashboard_listening",
|
|
lambda host, port: listening_calls.append(1) or True,
|
|
)
|
|
monkeypatch.setitem(sys.modules, "fastapi", None)
|
|
|
|
with pytest.raises((SystemExit, AttributeError, ImportError, TypeError)):
|
|
main_mod.cmd_dashboard(_args())
|
|
assert listening_calls == []
|
|
|
|
def test_reexec_child_does_not_reroute(self, main_mod, monkeypatch):
|
|
"""The re-exec'd child carries --open-profile; the guard must treat
|
|
that as 'already routed' and never re-exec again (no exec loop)."""
|
|
monkeypatch.setattr(
|
|
"hermes_cli.profiles.get_active_profile_name", lambda: "worker_x"
|
|
)
|
|
execs = []
|
|
monkeypatch.setattr(main_mod.os, "execvpe", lambda *a, **k: execs.append(a))
|
|
monkeypatch.setitem(sys.modules, "fastapi", None)
|
|
|
|
with pytest.raises((SystemExit, AttributeError, ImportError, TypeError)):
|
|
main_mod.cmd_dashboard(_args(open_profile="worker_x"))
|
|
assert execs == []
|