"""Observability: a chat follow-up's prior-context build logs its mode + size. The summary path is otherwise silent (no token-counter entry), so a follow-up looked like an unexplained pause. One info line per follow-up records what ran. """ from src.local_deep_research.chat.context import ChatContextManager _LOGGER = "src.local_deep_research.chat.context.logger" def _conversation(): return [ {"role": "user", "content": "What is X?", "message_type": "query"}, { "role": "assistant", "content": "X is a thing with several properties.", "message_type": "response", "research_id": "r1", }, ] class TestFollowupContextLogging: def test_logs_mode_and_size_on_followup(self, mocker): log = mocker.patch(_LOGGER) manager = ChatContextManager( session_id="s1", messages=_conversation(), accumulated_context={}, settings_snapshot={"chat.followup_context_mode": "raw"}, ) manager.build_research_context(current_query="tell me more") log.info.assert_called_once() fmt, *values = log.info.call_args.args assert "mode=" in fmt assert "raw" in values # the resolved mode is logged def test_first_turn_does_not_log(self, mocker): log = mocker.patch(_LOGGER) manager = ChatContextManager( session_id="s1", messages=[ {"role": "user", "content": "First", "message_type": "query"} ], accumulated_context={}, ) manager.build_research_context(current_query="First") # No prior work on the first turn → no context-build log line. log.info.assert_not_called()