Skip to content

The agent that grows with you

fix(webapp): sign-in fonts also resolve from the packaged dashboard dist

Teknium6890e38f9369
diff --git a/hermes_cli/web_server_dashboard.py b/hermes_cli/web_server_dashboard.py
index 6a9739815ca..6551e6f6f5b 100644
--- a/hermes_cli/web_server_dashboard.py
+++ b/hermes_cli/web_server_dashboard.py
@@ -288,7 +288,7 @@ def mount_spa(application: FastAPI):
):
return FileResponse(file_path)
if is_static_asset_path(full_path):
- font = public_font_file(dist, full_path)
+ font = public_font_file(dist, WEB_DIST, full_path)
if font is not None:
return FileResponse(font)
return JSONResponse({"error": "not found"}, status_code=404)
diff --git a/hermes_cli/web_server_static_assets.py b/hermes_cli/web_server_static_assets.py
index ac7abe694c4..1f8cd678407 100644
--- a/hermes_cli/web_server_static_assets.py
+++ b/hermes_cli/web_server_static_assets.py
@@ -2,8 +2,10 @@
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.
+dist, but the Webapp serves ``apps/desktop/dist-webapp`` and has no ``fonts/`` dir. A font missing
+from the served dist is read from the packaged dashboard dist (``HERMES_WEB_DIST`` / ``web_dist``,
+which is all a Nix or wheel install ships, since those exclude ``web/``), then from a source
+checkout's ``web/public``.
"""
from __future__ import annotations
@@ -20,13 +22,14 @@ 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."""
+def public_font_file(dist: Path, dashboard_dist: Path, full_path: str) -> Path | None:
+ """The served dist's copy of ``fonts/<name>`` (or ``fonts-terminal/<name>``), else the packaged
+ dashboard dist's, else the ``web/public`` copy the dashboard build takes it from; ``None`` when
+ none 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):
+ for root in (dist / folder, dashboard_dist / folder, _WEB_PUBLIC / folder):
candidate = root / name
if candidate.is_file() and candidate.resolve().is_relative_to(root.resolve()):
return candidate
diff --git a/tests/hermes_cli/test_spa_static_asset_misses.py b/tests/hermes_cli/test_spa_static_asset_misses.py
index 37e2eac939c..1682d11f90e 100644
--- a/tests/hermes_cli/test_spa_static_asset_misses.py
+++ b/tests/hermes_cli/test_spa_static_asset_misses.py
@@ -57,6 +57,28 @@ def test_a_font_in_the_served_bundle_wins(monkeypatch, tmp_path):
assert response.content == b"bundle copy"
+def test_sign_in_fonts_load_from_the_packaged_dashboard_without_a_source_tree(monkeypatch, tmp_path):
+ """Nix and wheel installs ship no ``web/public``; the packaged dashboard dist has the fonts."""
+ from hermes_cli import web_server as server
+ from hermes_cli import web_server_static_assets as static_assets
+
+ dashboard = tmp_path / "dashboard"
+ (dashboard / "fonts").mkdir(parents=True)
+ urls = _login_font_urls()
+ for url in urls:
+ (dashboard / url.lstrip("/")).write_bytes(b"packaged " + url.encode())
+ webapp = tmp_path / "webapp"
+ webapp.mkdir()
+ monkeypatch.setattr(static_assets, "_WEB_PUBLIC", tmp_path / "no-source-tree" / "web" / "public")
+ monkeypatch.setattr(server, "WEB_DIST", dashboard)
+ client = _spa(monkeypatch, webapp, surface="webapp")
+
+ for url in urls:
+ response = client.get(url)
+ assert response.status_code == 200, url
+ assert response.content == b"packaged " + url.encode()
+
+
@pytest.mark.parametrize("surface", ["webapp", None], ids=["webapp", "dashboard"])
@pytest.mark.parametrize("path", [
"/fonts/Missing-Regular.woff2",