fix: read dashboard spa assets as utf-8

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
LeonSGP43
2026-06-14 02:31:04 -07:00
committed by Teknium
co-authored by Paperclip
parent 7b9dc7cd0a
commit 89bdb1e546
2 changed files with 41 additions and 2 deletions
+39
View File
@@ -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