diff --git a/tests/test_memory_tool_mode.py b/tests/test_memory_tool_mode.py index 6f5e86237..b87c2217f 100644 --- a/tests/test_memory_tool_mode.py +++ b/tests/test_memory_tool_mode.py @@ -108,13 +108,27 @@ def test_tool_mode_skip_emits_structured_log(caplog: Any) -> None: Realignment build constraint: every cache-affecting decision is logged in the ``event=foo key=val`` style so operators can audit routing. + + NOTE: caplog captures at the root logger via propagation. When other + tests in the suite trigger proxy startup, ``_setup_file_logging`` sets + ``headroom.propagate=False`` and attaches a file handler. The conftest + autouse reset is fragile against fixture ordering, so we attach + ``caplog.handler`` directly to the target logger here. That way the + capture works regardless of propagation state. """ handler, _backend = _build_tool_mode_handler() - with caplog.at_level(logging.INFO, logger="headroom.proxy.memory_handler"): + target_logger = logging.getLogger("headroom.proxy.memory_handler") + previous_level = target_logger.level + target_logger.setLevel(logging.INFO) + target_logger.addHandler(caplog.handler) + try: result = asyncio.run( handler.search_and_format_context("alpha", [{"role": "user", "content": "hi"}]) ) + finally: + target_logger.removeHandler(caplog.handler) + target_logger.setLevel(previous_level) assert result is None skip_records = [r for r in caplog.records if "event=memory_mode_skip" in r.getMessage()] diff --git a/tests/test_proxy_anthropic_cache_stability.py b/tests/test_proxy_anthropic_cache_stability.py index 6daa01c1b..a085c326b 100644 --- a/tests/test_proxy_anthropic_cache_stability.py +++ b/tests/test_proxy_anthropic_cache_stability.py @@ -459,6 +459,9 @@ def test_ccr_system_instruction_injection_disabled_when_prefix_frozen(monkeypatc def process_request(self, messages, tools): # noqa: ANN001 return messages, tools, False + def scan_for_markers(self, messages): # noqa: ANN001 + return [] + monkeypatch.setattr("headroom.ccr.CCRToolInjector", _FakeInjector) async def _fake_retry(method, url, headers, body, stream=False, **kwargs): # noqa: ANN001 @@ -523,6 +526,9 @@ def test_ccr_tool_injection_disabled_when_prefix_frozen(monkeypatch) -> None: def process_request(self, messages, tools): # noqa: ANN001 return messages, tools, False + def scan_for_markers(self, messages): # noqa: ANN001 + return [] + monkeypatch.setattr("headroom.ccr.CCRToolInjector", _FakeInjector) async def _fake_retry(method, url, headers, body, stream=False, **kwargs): # noqa: ANN001