mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-06-21 10:22:18 +00:00
fix: read dashboard spa assets as utf-8
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
parent
7b9dc7cd0a
commit
89bdb1e546
2 changed files with 41 additions and 2 deletions
|
|
@ -10656,7 +10656,7 @@ def mount_spa(application: FastAPI):
|
|||
``__HERMES_AUTH_REQUIRED__`` flag lets the SPA pick the right
|
||||
auth scheme for /api/pty and /api/ws (ticket vs token).
|
||||
"""
|
||||
html = _index_path.read_text()
|
||||
html = _index_path.read_text(encoding="utf-8")
|
||||
chat_js = "true" if _DASHBOARD_EMBEDDED_CHAT_ENABLED else "false"
|
||||
gated = bool(getattr(app.state, "auth_required", False))
|
||||
gated_js = "true" if gated else "false"
|
||||
|
|
@ -10706,7 +10706,7 @@ def mount_spa(application: FastAPI):
|
|||
):
|
||||
return JSONResponse({"error": "not found"}, status_code=404)
|
||||
prefix = _normalise_prefix(request.headers.get("x-forwarded-prefix"))
|
||||
css = css_path.read_text()
|
||||
css = css_path.read_text(encoding="utf-8")
|
||||
if prefix:
|
||||
for asset_dir in ("/fonts/", "/fonts-terminal/", "/ds-assets/", "/assets/"):
|
||||
css = css.replace(f"url({asset_dir}", f"url({prefix}{asset_dir}")
|
||||
|
|
|
|||
|
|
@ -1857,6 +1857,45 @@ class TestWebServerEndpoints:
|
|||
if resp.status_code == 200:
|
||||
assert "FastAPI" not in resp.text # Should not serve the actual source
|
||||
|
||||
def test_spa_assets_are_read_as_utf8(self, monkeypatch, tmp_path):
|
||||
from fastapi import FastAPI
|
||||
from starlette.testclient import TestClient
|
||||
import hermes_cli.web_server as ws
|
||||
|
||||
dist = tmp_path / "web_dist"
|
||||
assets = dist / "assets"
|
||||
assets.mkdir(parents=True)
|
||||
index_path = dist / "index.html"
|
||||
css_path = assets / "app.css"
|
||||
index_path.write_text("<html><head></head><body>cafe cafe</body></html>", encoding="utf-8")
|
||||
css_path.write_text("body::before { content: 'cafe'; }", encoding="utf-8")
|
||||
|
||||
original_read_text = Path.read_text
|
||||
seen_encodings = {}
|
||||
|
||||
def tracking_read_text(path_self, *args, **kwargs):
|
||||
if path_self == index_path:
|
||||
seen_encodings["index"] = kwargs.get("encoding")
|
||||
elif path_self == css_path:
|
||||
seen_encodings["css"] = kwargs.get("encoding")
|
||||
return original_read_text(path_self, *args, **kwargs)
|
||||
|
||||
monkeypatch.setattr(ws, "WEB_DIST", dist)
|
||||
monkeypatch.setattr(Path, "read_text", tracking_read_text)
|
||||
spa_app = FastAPI()
|
||||
ws.mount_spa(spa_app)
|
||||
spa_client = TestClient(spa_app)
|
||||
|
||||
index_resp = spa_client.get("/chat")
|
||||
assert index_resp.status_code == 200
|
||||
assert "cafe cafe" in index_resp.text
|
||||
|
||||
css_resp = spa_client.get("/assets/app.css", headers={"x-forwarded-prefix": "/hermes"})
|
||||
assert css_resp.status_code == 200
|
||||
assert "content: 'cafe';" in css_resp.text
|
||||
|
||||
assert seen_encodings == {"index": "utf-8", "css": "utf-8"}
|
||||
|
||||
def test_set_model_main_nous_applies_gateway_defaults(self, monkeypatch):
|
||||
"""Switching the main provider to Nous calls apply_nous_managed_defaults
|
||||
(mirroring the CLI's post-model-selection Tool Gateway routing) and
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue