From f5bc18f9011745b7fb0bb0e72c7b5b756ffd686f Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Thu, 9 Jul 2026 14:48:50 +0530 Subject: [PATCH] fix: write expanded HERMES_WEB_DIST back for web_server's raw read MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Phase-2 review finding: the validation branch expanduser()s the path but web_server.py reads os.environ['HERMES_WEB_DIST'] raw at import — a '~/dist' value would validate here and still 404 there. Write the expanded path back before the web_server import. Adds a regression test asserting the env var holds the expanded path after cmd_dashboard. --- hermes_cli/main.py | 4 ++++ .../test_dashboard_web_dist_validation.py | 23 +++++++++++++++++++ 2 files changed, 27 insertions(+) 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)