test: align new chat guard static coverage

Update the older #1432 static regression to assert the extracted reusable-empty helper owns the message-count and in-flight checks, while both New Chat entry points call the helper. This keeps the test aligned with the shared guard introduced in PR #5206.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
Frank SongandPaperclip authored and nesquena-hermes committed 2026-06-29 18:38:25 +00:00
1 parent 28c2c37c1c
commit fbb1e9567c
1 file changed
+35 -18
@@ -14,6 +14,13 @@ def _read(filename):
return open(os.path.join(STATIC_DIR, filename), encoding='utf-8').read()
def _current_session_is_reusable_empty_chat_body(src):
start = src.find("function _currentSessionIsReusableEmptyChat()")
end = src.find("$('fileInput').onchange", start)
assert start >= 0 and end >= 0, "empty-session reuse helper not found in boot.js"
return src[start:end]
class TestIssue1432NewChatGuardInFlight:
"""`+` button and Cmd/Ctrl+K must create a new chat even while the current
session is still streaming. The empty-session guard from #1171 was checking
@@ -26,38 +33,48 @@ class TestIssue1432NewChatGuardInFlight:
def test_btnNewChat_handler_checks_in_flight_state(self):
src = _read('boot.js')
# Locate the btnNewChat onclick handler
helper = _current_session_is_reusable_empty_chat_body(src)
# The empty-session guard must check all three in-flight signals.
assert 'message_count' in helper, \
"shared New Chat guard missing message_count check"
assert 'S.busy' in helper, \
"shared New Chat guard missing S.busy check (#1432)"
assert 'active_stream_id' in helper, \
"shared New Chat guard missing active_stream_id check (#1432)"
assert 'pending_user_message' in helper, \
"shared New Chat guard missing pending_user_message check (#1432)"
# Locate the btnNewChat onclick handler and verify it uses the helper.
m = re.search(
r"\$\('btnNewChat'\)\.onclick=async\(\)=>\{(.*?)\};",
src, re.DOTALL,
)
assert m, "btnNewChat onclick handler not found in boot.js"
body = m.group(1)
# The empty-session guard must check all three in-flight signals
assert 'message_count' in body, \
"btnNewChat guard missing message_count check"
assert 'S.busy' in body, \
"btnNewChat guard missing S.busy check (#1432)"
assert 'active_stream_id' in body, \
"btnNewChat guard missing active_stream_id check (#1432)"
assert 'pending_user_message' in body, \
"btnNewChat guard missing pending_user_message check (#1432)"
assert '_currentSessionIsReusableEmptyChat()' in body, \
"btnNewChat handler must use the shared empty-session guard"
def test_cmdK_handler_checks_in_flight_state(self):
src = _read('boot.js')
helper = _current_session_is_reusable_empty_chat_body(src)
assert 'message_count' in helper, \
"shared New Chat guard missing message_count check"
assert 'S.busy' in helper, \
"shared New Chat guard missing S.busy check (#1432)"
assert 'active_stream_id' in helper, \
"shared New Chat guard missing active_stream_id check (#1432)"
assert 'pending_user_message' in helper, \
"shared New Chat guard missing pending_user_message check (#1432)"
# Locate the Cmd/Ctrl+K branch — it sits inside a keydown listener
idx = src.find("(e.metaKey||e.ctrlKey)&&e.key==='k'")
assert idx >= 0, "Cmd/Ctrl+K handler not found in boot.js"
# Read the next ~1500 chars (handler body)
body = src[idx:idx + 1500]
assert 'message_count' in body, \
"Cmd/Ctrl+K guard missing message_count check"
assert 'S.busy' in body, \
"Cmd/Ctrl+K guard missing S.busy check (#1432)"
assert 'active_stream_id' in body, \
"Cmd/Ctrl+K guard missing active_stream_id check (#1432)"
assert 'pending_user_message' in body, \
"Cmd/Ctrl+K guard missing pending_user_message check (#1432)"
assert '_currentSessionIsReusableEmptyChat()' in body, \
"Cmd/Ctrl+K handler must use the shared empty-session guard"
def test_in_flight_signal_matches_restoreSettledSession(self):
"""The new in-flight check uses the same signal as the canonical