The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(tui_gateway): split turn_env into turn_stubs + inline Thread patch
kshitijk4poor7b1979dc5202
diff --git a/tests/tui_gateway/test_prompt_accept_logging.py b/tests/tui_gateway/test_prompt_accept_logging.pyindex dc8ce3da2d8..d77c83fb697 100644--- a/tests/tui_gateway/test_prompt_accept_logging.py+++ b/tests/tui_gateway/test_prompt_accept_logging.py@@ -64,9 +64,8 @@ def _session(agent=None, **extra):}@pytest.fixture()-def turn_env(monkeypatch, tmp_path):+def turn_stubs(monkeypatch, tmp_path):"""Neutralize the turn pipeline's environment-heavy side paths."""- monkeypatch.setattr(server.threading, "Thread", _InlineThread)monkeypatch.setattr(server, "_emit", lambda *a, **k: None)monkeypatch.setattr(server, "_wire_callbacks", lambda sid: None)monkeypatch.setattr(server, "_sync_agent_model_with_config", lambda sid, session: None)@@ -76,6 +75,11 @@ def turn_env(monkeypatch, tmp_path):monkeypatch.setattr(server, "_sync_session_key_after_compress", lambda *a, **k: None)monkeypatch.setattr(server, "_get_usage", lambda agent: {})+def turn_env(turn_stubs, monkeypatch):+ """``turn_stubs`` with the turn run inline on the caller's thread."""+ monkeypatch.setattr(server.threading, "Thread", _InlineThread)+def _records(caplog, needle):return [r for r in caplog.records if needle in r.getMessage()]@@ -107,7 +111,7 @@ def test_accepted_and_finished_records_on_success(turn_env, caplog):@pytest.mark.parametrize("settle_info_raises", [False, True])-def test_turn_settles_before_post_turn_trim(monkeypatch, caplog, settle_info_raises):+def test_turn_settles_before_post_turn_trim(turn_stubs, monkeypatch, caplog, settle_info_raises):"""A blocked post-turn trim must not hold the session running or its bookend (#131740);turn audio still ends BEFORE settlement, so a next turn admitted during the trim keeps its own."""import hermes_cli.mem_trim as mem_trim@@ -120,11 +124,6 @@ def test_turn_settles_before_post_turn_trim(monkeypatch, caplog, settle_info_rairelease.wait(timeout=10)monkeypatch.setattr(mem_trim, "trim_memory", blocking_trim)- for name in ("_emit", "_wire_callbacks", "_register_session_cwd", "_sync_session_key_after_compress"):- monkeypatch.setattr(server, name, lambda *a, **k: None)- monkeypatch.setattr(server, "_sync_agent_model_with_config", lambda sid, session: None)- monkeypatch.setattr(server, "_tts_stream_begin", lambda: None)- monkeypatch.setattr(server, "_get_usage", lambda agent: {})if settle_info_raises: # a raising settle step must not skip the post-turn trimmonkeypatch.setattr(server, "_emit_settled_session_info", lambda *a: 1 / 0)audio_end = [] # (event, session running at that moment)