fix: write expanded HERMES_WEB_DIST back for web_server's raw read

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.
This commit is contained in:
kshitijk4poor 2026-07-09 14:48:50 +05:30
parent d928017742
commit f5bc18f901
2 changed files with 27 additions and 0 deletions

View file

@ -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

View file

@ -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("<html></html>", 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)