diff --git a/hermes_cli/main.py b/hermes_cli/main.py index 47534b36388..f450a76666f 100644 --- a/hermes_cli/main.py +++ b/hermes_cli/main.py @@ -12092,6 +12092,10 @@ def cmd_dashboard(args): print(" Pre-build first: npm install --workspace web && npm run build -w web") print(" Or unset HERMES_WEB_DIST to build and use the default web UI dist.") sys.exit(1) + # Write the expanded path back: web_server reads HERMES_WEB_DIST raw + # at import (no expanduser), so a validated "~/dist" would otherwise + # pass here and still 404 there. + os.environ["HERMES_WEB_DIST"] = str(_dist_root) print(f"→ Using web dist from HERMES_WEB_DIST: {_dist_root}") # Discover and load plugins so any DashboardAuthProvider plugin diff --git a/tests/hermes_cli/test_dashboard_web_dist_validation.py b/tests/hermes_cli/test_dashboard_web_dist_validation.py index 92c63fe3e35..d1d7a780840 100644 --- a/tests/hermes_cli/test_dashboard_web_dist_validation.py +++ b/tests/hermes_cli/test_dashboard_web_dist_validation.py @@ -111,3 +111,26 @@ def test_env_dist_with_index_starts_server(main_mod, monkeypatch, tmp_path): assert len(started) == 1 assert builds == [] + + +def test_env_dist_tilde_expanded_for_web_server(main_mod, monkeypatch, tmp_path): + """A '~/...' HERMES_WEB_DIST must be written back expanded so + web_server's raw os.environ read serves the validated path.""" + _wire_common(main_mod, monkeypatch) + home = tmp_path / "home" + dist = home / "mydist" + dist.mkdir(parents=True) + (dist / "index.html").write_text("", encoding="utf-8") + monkeypatch.setenv("HOME", str(home)) + monkeypatch.setenv("HERMES_WEB_DIST", "~/mydist") + + monkeypatch.setitem( + sys.modules, + "hermes_cli.web_server", + types.SimpleNamespace(start_server=lambda **k: None), + ) + + main_mod.cmd_dashboard(_args()) + + import os + assert os.environ["HERMES_WEB_DIST"] == str(dist)