From ef7238421733fb089b58e5f276994b6635aaca5a Mon Sep 17 00:00:00 2001 From: nesquena-hermes Date: Fri, 24 Apr 2026 11:41:17 -0700 Subject: [PATCH] fix: harden _accepts_gzip + update stale test assertions post-#959 (#981) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes introduced when absorbing PR #959 (fast conversation switching): - _accepts_gzip() now uses getattr() to tolerate _FakeHandler and any synthesised handler that lacks a .headers attribute (fixes 2 test failures in test_sprint46.py) - test_issue401: updated assertion to accept both minified and reformatted forms of the tool_calls fallback guard (PR reformatted the code) - test_regressions: updated activeStreamId assertion — PR refactored data.session references to S.session for direct state access Co-authored-by: nesquena-hermes --- api/helpers.py | 5 ++++- tests/test_issue401.py | 6 ++++-- tests/test_regressions.py | 3 ++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/api/helpers.py b/api/helpers.py index be137f89..477d52ae 100644 --- a/api/helpers.py +++ b/api/helpers.py @@ -57,7 +57,10 @@ def _security_headers(handler): def _accepts_gzip(handler) -> bool: """Check if the client accepts gzip encoding.""" - ae = handler.headers.get('Accept-Encoding', '') + headers = getattr(handler, 'headers', None) + if not headers: + return False + ae = headers.get('Accept-Encoding', '') return 'gzip' in ae diff --git a/tests/test_issue401.py b/tests/test_issue401.py index 737c11bc..174645e4 100644 --- a/tests/test_issue401.py +++ b/tests/test_issue401.py @@ -28,8 +28,10 @@ def test_loadsession_preserves_tool_rows(): def test_loadsession_uses_session_toolcalls_only_as_fallback(): """Session summaries are the fallback, not the primary reload source.""" - assert "if(!hasMessageToolMetadata&&data.session.tool_calls&&data.session.tool_calls.length)" in SESSIONS_JS - assert "S.toolCalls=(data.session.tool_calls||[]).map(tc=>({...tc,done:true}));" in SESSIONS_JS + assert ("if(!hasMessageToolMetadata&&data.session.tool_calls&&data.session.tool_calls.length)" in SESSIONS_JS or + "if (!hasMessageToolMetadata && data.session.tool_calls && data.session.tool_calls.length)" in SESSIONS_JS) + assert ("S.toolCalls=(data.session.tool_calls||[]).map(tc=>({...tc,done:true}));" in SESSIONS_JS or + "S.toolCalls = data.session.tool_calls.map(tc => ({...tc, done: true}));" in SESSIONS_JS) assert "S.toolCalls=[];" in SESSIONS_JS diff --git a/tests/test_regressions.py b/tests/test_regressions.py index 915591b6..66a9c2ac 100644 --- a/tests/test_regressions.py +++ b/tests/test_regressions.py @@ -531,7 +531,8 @@ def test_reload_path_restores_pending_message_and_reattaches_live_stream(cleanup assert 'pending_user_message' in ui_src assert 'function attachLiveStream' in messages_src assert 'const pendingMsg=typeof getPendingSessionMessage' in sessions_src - assert 'const activeStreamId=data.session.active_stream_id||null;' in sessions_src + assert ('const activeStreamId=data.session.active_stream_id||null;' in sessions_src or + 'const activeStreamId=S.session.active_stream_id||null;' in sessions_src) assert 'attachLiveStream(sid, activeStreamId' in sessions_src assert 'if (S.activeStreamId && S.activeStreamId === streamId) return;' in ui_src