Skip to content

The agent that grows with you

fix(webapp): a launch refused for a stale bundle asks for a build, not a gateway restart

emozillae7f275250220
diff --git a/hermes_cli/webapp_launcher.py b/hermes_cli/webapp_launcher.py
index c8940d13c7c..1138e902970 100644
--- a/hermes_cli/webapp_launcher.py
+++ b/hermes_cli/webapp_launcher.py
@@ -145,12 +145,19 @@ def _status(target: Path) -> int:
print(_off_message(target, f"run {RESTART_COMMAND}"))
else:
print(f"Unavailable: {status['reason']}")
- from gateway.webapp_listener import NOT_BUILT
- if not str(status["reason"]).startswith(NOT_BUILT): # a build is served without a restart
+ if _restart_applies(status["reason"]):
print(RETRY_AFTER_FIX)
return 0
+def _restart_applies(reason) -> bool:
+ """Whether fixing *reason* (why the gateway does not serve the Webapp) takes a gateway restart. A
+ missing or stale bundle does not: the gateway serves one as soon as it is built, and a restart
+ keeps the stale mark."""
+ from gateway.webapp_listener import NOT_BUILT
+ return not str(reason).startswith(NOT_BUILT)
+
+
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):
@@ -214,14 +221,14 @@ def _gateway_state(home: Path) -> str:
def _explain_refused_launch(target: Path, response: dict) -> int:
try:
- state = (_control(target, "webapp-status").get("result") or {}).get("state")
+ status = _control(target, "webapp-status").get("result") or {}
except GatewayUnreachable:
- state = None
- if state == "off":
+ status = {}
+ if status.get("state") == "off":
print(STARTED_BEFORE_ON)
else:
print(_refusal(response))
- if state == "unavailable":
+ if status.get("state") == "unavailable" and _restart_applies(status.get("reason")):
print(RETRY_AFTER_FIX)
return 1
diff --git a/tests/hermes_cli/test_webapp_launcher.py b/tests/hermes_cli/test_webapp_launcher.py
index 4da318f70a3..22311823024 100644
--- a/tests/hermes_cli/test_webapp_launcher.py
+++ b/tests/hermes_cli/test_webapp_launcher.py
@@ -136,6 +136,19 @@ def test_a_webapp_the_gateway_could_not_serve_reports_why_and_how_to_retry(world
assert reason in out and "hermes gateway restart" in out
+def test_a_launch_refused_for_a_stale_bundle_asks_for_a_build_not_a_restart(world, capsys):
+ """A bundle that is missing or that hermes update could not rebuild is served as soon as it is
+ built, and a restart keeps the stale mark: the refusal says to build it and never sends the user
+ to restart the gateway, as --status already does."""
+ from gateway.webapp_listener import NOT_REBUILT
+ world["answers"]["webapp-launch"] = {"ok": False, "error": f"RuntimeError: The Webapp is unavailable: {NOT_REBUILT}"}
+ world["answers"]["webapp-status"] = {"ok": True, "result": {"state": "unavailable", "url": None,
+ "reason": NOT_REBUILT}}
+ assert launcher.cmd_webapp(_args(skip_build=True)) == 1
+ out = capsys.readouterr().out
+ assert "Run hermes webapp to rebuild it." in out and launcher.RESTART_COMMAND not 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": {