Files
hermes-webui/tests/test_issue1743_model_picker_race.py
T
mo7al876anyandClaude Fable 5 5f0cc6c567 test: read static assets as utf-8 so locale/render tests run on Windows
34 test files read static/*.js via read_text()/open() without an encoding,
so Python's cp1252 default on Windows choked on non-Latin1 bytes and errored
at collection (Ubuntu CI defaults to utf-8, so it never saw this). Add
explicit encoding="utf-8" to those reads — purely mechanical, no assertion
changes.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-04 16:04:23 +03:00

34 lines
1.3 KiB
Python

"""Regression coverage for #1743 model picker async catalog race."""
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
UI_JS = (ROOT / "static" / "ui.js").read_text(encoding="utf-8")
def _body_between(src: str, start: str, end: str) -> str:
start_idx = src.index(start)
end_idx = src.index(end, start_idx)
return src[start_idx:end_idx]
def test_model_picker_opens_before_async_model_catalog_finishes():
"""Opening the visible picker must not block on a slow /api/models request."""
body = _body_between(UI_JS, "async function toggleModelDropdown", "function closeModelDropdown")
assert "window._ensureModelDropdownReady" in body
render_idx = body.index("renderModelDropdown()")
open_idx = body.index("dd.classList.add('open')")
await_idx = body.find("await")
assert render_idx < open_idx
assert await_idx == -1 or open_idx < await_idx
def test_populate_model_dropdown_rerenders_if_picker_is_already_open():
"""If the async catalog finishes while open, refresh the visible custom rows."""
body = _body_between(UI_JS, "async function populateModelDropdown", "// Cache so we don't re-fetch")
assert "composerModelDropdown" in body
assert "classList.contains('open')" in body or 'classList.contains("open")' in body
assert "renderModelDropdown()" in body