Skip to content

The agent that grows with you

fix(webapp): the sign-in page loads its fonts instead of the app page

Teknium17c92390ef2d
diff --git a/hermes_cli/web_server_dashboard.py b/hermes_cli/web_server_dashboard.py
index cfa4c32eb59..6a9739815ca 100644
--- a/hermes_cli/web_server_dashboard.py
+++ b/hermes_cli/web_server_dashboard.py
@@ -122,6 +122,7 @@ def mount_spa(application: FastAPI):
from hermes_cli.web_server import WEB_DIST, _DASHBOARD_EMBEDDED_CHAT_ENABLED
from hermes_cli.web_deps import _server
from hermes_cli.web_server_surface import policy
+ from hermes_cli.web_server_static_assets import is_static_asset_path, public_font_file
# `hermes serve` is the headless backend: it must NEVER serve the browser SPA, even if a
# dist is lying around, so only the JSON-RPC/WS/API surface is reachable.
@@ -286,6 +287,11 @@ def mount_spa(application: FastAPI):
and file_path.is_file()
):
return FileResponse(file_path)
+ if is_static_asset_path(full_path):
+ font = public_font_file(dist, full_path)
+ if font is not None:
+ return FileResponse(font)
+ return JSONResponse({"error": "not found"}, status_code=404)
return _serve_index(prefix)
diff --git a/hermes_cli/web_server_static_assets.py b/hermes_cli/web_server_static_assets.py
new file mode 100644
index 00000000000..ac7abe694c4
--- /dev/null
+++ b/hermes_cli/web_server_static_assets.py
@@ -0,0 +1,33 @@
+"""Static asset lookups the SPA catch-all must not answer with ``index.html``.
+
+The sign-in page (``dashboard_auth/login_page.py``) loads its brand fonts from ``/fonts/``. Those
+files ship in the dashboard's ``web/public`` tree, which the dashboard build copies into its own
+dist, but the Webapp serves ``apps/desktop/dist-webapp`` and has no ``fonts/`` dir. Both surfaces
+run from the same tree, so a font missing from the served dist is read from ``web/public`` itself.
+"""
+from __future__ import annotations
+
+from pathlib import Path
+
+# Requests under these prefixes are files, never client-side routes, so a miss is a 404 rather
+# than the SPA shell (a font answered with HTML renders in a fallback face, silently).
+STATIC_ASSET_PREFIXES: tuple[str, ...] = ("assets/", "ds-assets/", "fonts/", "fonts-terminal/")
+_PUBLIC_FONT_DIRS: tuple[str, ...] = ("fonts", "fonts-terminal")
+_WEB_PUBLIC = Path(__file__).resolve().parent.parent / "web" / "public"
+
+
+def is_static_asset_path(full_path: str) -> bool:
+ return full_path.startswith(STATIC_ASSET_PREFIXES)
+
+
+def public_font_file(dist: Path, full_path: str) -> Path | None:
+ """The served dist's copy of ``fonts/<name>`` (or ``fonts-terminal/<name>``), else the
+ ``web/public`` copy the dashboard build takes it from; ``None`` when neither has it."""
+ folder, _, name = full_path.partition("/")
+ if folder not in _PUBLIC_FONT_DIRS or not name:
+ return None
+ for root in (dist / folder, _WEB_PUBLIC / folder):
+ candidate = root / name
+ if candidate.is_file() and candidate.resolve().is_relative_to(root.resolve()):
+ return candidate
+ return None
diff --git a/tests/hermes_cli/test_spa_static_asset_misses.py b/tests/hermes_cli/test_spa_static_asset_misses.py
new file mode 100644
index 00000000000..37e2eac939c
--- /dev/null
+++ b/tests/hermes_cli/test_spa_static_asset_misses.py
@@ -0,0 +1,80 @@
+"""Asset requests never get the SPA shell. The sign-in page's brand fonts load on the Webapp surface
+too, whose bundle carries no ``fonts/`` dir, and a missing file under a static asset prefix is a
+404 on both surfaces instead of ``index.html`` served as 200 ``text/html``."""
+import re
+from pathlib import Path
+
+import pytest
+from fastapi import FastAPI
+from fastapi.testclient import TestClient
+
+HTML = "<html><head></head><body>spa shell</body></html>"
+WEB_PUBLIC = Path(__file__).resolve().parents[2] / "web" / "public"
+
+
+def _spa(monkeypatch, dist: Path, *, surface) -> TestClient:
+ from hermes_cli import web_server as server
+ from hermes_cli.web_server_dashboard import mount_spa
+
+ (dist / "index.html").write_text(HTML)
+ (dist / "assets").mkdir(exist_ok=True)
+ app = FastAPI()
+ if surface is not None:
+ app.state.ui_surface = surface
+ app.state.web_dist = dist
+ monkeypatch.setattr(server, "app", app)
+ monkeypatch.delenv("HERMES_SERVE_HEADLESS", raising=False)
+ mount_spa(app)
+ return TestClient(app)
+
+
+def _login_font_urls() -> list[str]:
+ from hermes_cli.dashboard_auth.login_page import render_login_html
+
+ urls = re.findall(r"url\('(/fonts/[^']+)'\)", render_login_html())
+ assert urls
+ return sorted(set(urls))
+
+
[email protected]("surface", ["webapp", None], ids=["webapp", "dashboard"])
+def test_the_sign_in_page_fonts_load_as_fonts(monkeypatch, tmp_path, surface):
+ client = _spa(monkeypatch, tmp_path, surface=surface)
+
+ for url in _login_font_urls():
+ response = client.get(url)
+ assert response.status_code == 200, url
+ assert response.headers["content-type"] == "font/woff2", url
+ assert response.content == (WEB_PUBLIC / url.lstrip("/")).read_bytes()
+
+
+def test_a_font_in_the_served_bundle_wins(monkeypatch, tmp_path):
+ (tmp_path / "fonts").mkdir()
+ (tmp_path / "fonts" / "Collapse-Regular.woff2").write_bytes(b"bundle copy")
+
+ response = _spa(monkeypatch, tmp_path, surface="webapp").get("/fonts/Collapse-Regular.woff2")
+
+ assert response.status_code == 200
+ assert response.content == b"bundle copy"
+
+
[email protected]("surface", ["webapp", None], ids=["webapp", "dashboard"])
+ "/fonts/Missing-Regular.woff2",
+ "/fonts-terminal/missing.woff2",
+ "/ds-assets/missing.png",
+ "/assets/missing-abc123.js",
+ "/fonts/..%2f..%2fpyproject.toml",
+])
+def test_a_missing_asset_is_404_not_the_spa_shell(monkeypatch, tmp_path, surface, path):
+ response = _spa(monkeypatch, tmp_path, surface=surface).get(path)
+
+ assert response.status_code == 404
+ assert "spa shell" not in response.text
+
+
[email protected]("surface", ["webapp", None], ids=["webapp", "dashboard"])
+def test_client_routes_still_get_the_spa_shell(monkeypatch, tmp_path, surface):
+ response = _spa(monkeypatch, tmp_path, surface=surface).get("/chat/fonts-and-assets")
+
+ assert response.status_code == 200
+ assert "spa shell" in response.text