Files
hermes-webui/tests/test_issue856_active_session_read_state.py
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

54 lines
2.5 KiB
Python

"""Regression checks for #856 active-session unread state handling."""
from pathlib import Path
MESSAGES_JS = (Path(__file__).resolve().parent.parent / "static" / "messages.js").read_text(encoding="utf-8")
def test_messages_js_defines_active_session_viewed_helper():
assert "function _markSessionViewed(" in MESSAGES_JS, (
"messages.js should define a helper that marks the active session as viewed"
)
assert "_setSessionViewedCount" in MESSAGES_JS, (
"active-session viewed helper must delegate to the sidebar viewed-count store"
)
def test_done_path_marks_active_session_as_viewed():
done_idx = MESSAGES_JS.find("source.addEventListener('done'")
assert done_idx != -1, "done handler not found in messages.js"
done_block = MESSAGES_JS[done_idx:MESSAGES_JS.find("source.addEventListener('stream_end'", done_idx)]
assert "const completedSid=completedSession.session_id||activeSid;" in done_block
assert "_markSessionViewed(completedSid" in done_block, (
"done handler must mark the final active session id as viewed so unread dot "
"does not linger after compression rotates session_id"
)
def test_cancel_path_marks_active_session_as_viewed():
cancel_idx = MESSAGES_JS.find("source.addEventListener('cancel'")
assert cancel_idx != -1, "cancel handler not found in messages.js"
restore_marker = "async function _restoreSettledSession(source"
cancel_block = MESSAGES_JS[cancel_idx:MESSAGES_JS.find(restore_marker, cancel_idx)]
assert "_markSessionViewed(activeSid" in cancel_block, (
"cancel handler must mark the active session as viewed after settling messages"
)
def test_restore_and_error_paths_mark_active_session_as_viewed():
restore_idx = MESSAGES_JS.find("async function _restoreSettledSession(source")
assert restore_idx != -1, "_restoreSettledSession(source) not found in messages.js"
restore_block = MESSAGES_JS[restore_idx:MESSAGES_JS.find("function _handleStreamError(source)", restore_idx)]
assert "const completedSid=session.session_id||activeSid;" in restore_block
assert "_markSessionViewed(completedSid" in restore_block, (
"_restoreSettledSession() must mark the final session id as viewed"
)
error_idx = MESSAGES_JS.find("function _handleStreamError(source)")
assert error_idx != -1, "_handleStreamError(source) not found in messages.js"
error_block = MESSAGES_JS[error_idx:]
assert "_markSessionViewed(activeSid" in error_block, (
"_handleStreamError() must mark the active session as viewed"
)