Skip to content

The agent that grows with you

fix(webapp): hermes webapp says a Webapp turned off in config is still served until a restart

emozilla58375f7b7750
diff --git a/hermes_cli/webapp_launcher.py b/hermes_cli/webapp_launcher.py
index 1138e902970..406e8248b30 100644
--- a/hermes_cli/webapp_launcher.py
+++ b/hermes_cli/webapp_launcher.py
@@ -139,6 +139,10 @@ def _status(target: Path) -> int:
status = response["result"]
if status["state"] == "serving":
print(f"Serving at {status['url']}")
+ from gateway.webapp_listener import webapp_settings
+ if not webapp_settings(target).enabled:
+ print(f"{target / 'config.yaml'} no longer turns the Webapp on: it stops at the next gateway restart "
+ f"({RESTART_COMMAND}).")
elif status["state"] == "starting":
print("The gateway is still starting the Webapp. Run hermes webapp --status again in a moment.")
elif status["state"] == "off":
@@ -158,6 +162,20 @@ def _restart_applies(reason) -> bool:
return not str(reason).startswith(NOT_BUILT)
+def _still_served(target: Path) -> str | None:
+ """What to say when *target*'s config no longer turns the Webapp on but its running gateway, which
+ reads the config only when it starts, still serves it; None otherwise. Never starts a gateway."""
+ try:
+ response = _control(target, "webapp-status")
+ except GatewayUnreachable:
+ return None
+ status = (response.get("result") or {}) if response.get("ok") else {}
+ if status.get("state") != "serving":
+ return None
+ return (f"{target / 'config.yaml'} no longer turns the Webapp on, but the running gateway still serves it at "
+ f"{status['url']} until it restarts. Run {RESTART_COMMAND} to apply the config.")
+
+
def _signed_out_summary(result: dict) -> str:
"""What a gateway's ``webapp-sign-out`` answer says it did, for the user."""
if not result.get("serving", True):
@@ -248,7 +266,7 @@ def cmd_webapp(args) -> int:
if args.sign_out:
return _sign_out(target)
if not args.build_only and not webapp_settings(target).enabled:
- print(_off_message(target, "run hermes webapp again"))
+ print(_still_served(target) or _off_message(target, "run hermes webapp again"))
return 1
try:
_build(args)
diff --git a/tests/hermes_cli/test_webapp_launcher.py b/tests/hermes_cli/test_webapp_launcher.py
index 22311823024..aa5be9ca680 100644
--- a/tests/hermes_cli/test_webapp_launcher.py
+++ b/tests/hermes_cli/test_webapp_launcher.py
@@ -106,6 +106,7 @@ def test_a_standalone_profile_opens_the_webapp_of_its_own_gateway(world):
def test_the_launcher_says_how_to_turn_the_webapp_on(world, capsys):
(world["root"] / "config.yaml").write_text("", encoding="utf-8")
+ world["answers"]["webapp-status"] = {"ok": True, "result": {"state": "off", "url": None, "reason": None}}
assert launcher.cmd_webapp(_args()) == 1
out = capsys.readouterr().out
assert "webapp.enabled: true" in out and str(world["root"] / "config.yaml") in out
@@ -149,6 +150,30 @@ def test_a_launch_refused_for_a_stale_bundle_asks_for_a_build_not_a_restart(worl
assert "Run hermes webapp to rebuild it." in out and launcher.RESTART_COMMAND not in out
+SERVING = {"ok": True, "result": {"state": "serving", "url": "http://127.0.0.1:9120", "reason": None}}
+
+
+def test_a_webapp_turned_off_in_config_but_still_served_says_a_restart_stops_it(world, capsys):
+ """The gateway reads webapp: only when it starts. After the config turns the Webapp off, the running
+ gateway still serves it (on the LAN for a wildcard host) until it restarts: hermes webapp says so,
+ instead of "The Webapp is off", and opens nothing."""
+ (world["root"] / "config.yaml").write_text("webapp:\n enabled: false\n host: 0.0.0.0\n", encoding="utf-8")
+ world["answers"]["webapp-status"] = SERVING
+ assert launcher.cmd_webapp(_args()) == 1
+ out = capsys.readouterr().out
+ assert "The Webapp is off" not in out
+ assert "http://127.0.0.1:9120" in out and launcher.RESTART_COMMAND in out
+ assert (world["calls"]["build"], world["calls"]["ensure"], world["calls"]["opened"]) == (0, [], [])
+
+
+def test_status_of_a_webapp_served_after_the_config_turned_it_off_says_a_restart_stops_it(world, capsys):
+ (world["root"] / "config.yaml").write_text("webapp:\n enabled: false\n", encoding="utf-8")
+ world["answers"]["webapp-status"] = SERVING
+ assert launcher.cmd_webapp(_args(status=True)) == 0
+ out = capsys.readouterr().out
+ assert "Serving at http://127.0.0.1:9120" in out and launcher.RESTART_COMMAND in out
+
+
def test_behind_the_dashboard_sign_in_the_launcher_opens_the_webapp_to_sign_in(world, capsys):
url = "http://127.0.0.1:9120/"
world["answers"]["webapp-launch"] = {"ok": True, "result": {