headroom/tests/test_memory_tool_mode.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

180 lines
6 KiB
Python
Raw Normal View History

fix: B6 — memory injection moves to live-zone user-tail PR-A2 locked the system prompt and routed Anthropic memory injection to the latest non-frozen user turn. PR-B6 finishes the job: every provider handler that auto-injects memory context now does so via the live-zone tail, and a new MemoryMode enum makes the routing explicit and configurable. What changed ------------ * New `MemoryMode` enum in `headroom/proxy/memory_handler.py` with two values: - `AUTO_TAIL` (default) — retrieval results auto-append to the latest user message. The cache hot zone (system / instructions / frozen prefix) is never mutated. - `TOOL` — auto-injection is disabled entirely. The model must call `memory_search` to retrieve. Memory is opt-in and visible. * `MemoryConfig.mode: MemoryMode = MemoryMode.AUTO_TAIL` propagates into `search_and_format_context`, which now short-circuits to `None` in `TOOL` mode. This is the single chokepoint that gates every provider — Anthropic /v1/messages, OpenAI /v1/chat/completions, OpenAI /v1/responses, and Gemini all funnel through it, so flipping a deployment to tool mode does not require auditing every handler. * New `MemoryHandler._append_to_latest_user_tail(messages, context_text, provider=..., frozen_message_count=...)` static helper provides the unified tail-append entry point and dispatches to the existing provider-specific helpers (`AnthropicHandlerMixin._append_context_to_latest_non_frozen_user_turn` for Anthropic, `append_text_to_latest_user_chat_message` for OpenAI). * Gemini handler swapped from auto-prepending memory as a system message (the old P2-24 cache-hot-zone mutation pattern) to using `_append_to_latest_user_tail(provider="openai")`. * `ProxyConfig.memory_mode: Literal["auto_tail", "tool"] = "auto_tail"` surfaces the mode for deployment configuration. Server constructs the enum via `MemoryMode(config.memory_mode)` and raises loudly on unknown values (no silent fallback). * OpenAI Chat Completions, OpenAI Responses, and Anthropic handlers were already routing to the live-zone tail via PR-A2/A3 — no code change needed beyond inheriting the `TOOL`-mode skip from the chokepoint. Tests ----- * `tests/test_memory_auto_tail.py` (6 tests): - `test_memory_appears_in_latest_user_message_tail` — Anthropic shape. - `test_memory_appears_in_latest_user_message_tail_openai_shape` — OpenAI string + list-content shapes. - `test_memory_does_not_modify_system_or_tools` — system prompt and tools list are never touched; frozen-prefix tail is a no-op. - `test_same_query_byte_identical_across_runs` — two independent runs with identical inputs produce byte-identical mutated message lists (determinism gate). - `test_default_mode_is_auto_tail` — fresh `MemoryConfig` defaults to `AUTO_TAIL`. - `test_unknown_provider_raises` — invalid provider strings raise loudly per the no-silent-fallback policy. * `tests/test_memory_tool_mode.py` (4 tests): - `test_tool_mode_skips_auto_injection` — `search_and_format_context` returns `None` and the backend is never queried. - `test_tool_mode_skip_emits_structured_log` — skip emits the `event=memory_mode_skip` log line for routing-decision auditability. - `test_auto_tail_mode_does_query_backend` — inverse contrast pinning down that AUTO_TAIL still works end-to-end while TOOL skips. - `test_tool_mode_enum_value_is_stable` — string round-trip is pinned so deployment configs do not drift on rename. Determinism ----------- Tests stub the backend with a fixed, ordered result set so the byte-identical assertion isolates the tail-injection layer from upstream search non- determinism. The vector-search layer itself (LocalBackend / HNSW) is deterministic per-process for the same inputs but has thread-scheduling variability across processes; per the realignment plan, request-time determinism is guaranteed by the formatter and the tail-append helpers (this PR's responsibility), and the backend layer's determinism stays out-of-scope for B6. Per-PR-B6 plan: REALIGNMENT/04-phase-B-live-zone.md.
2026-05-02 16:37:54 -07:00
"""PR-B6: tests that MemoryMode.TOOL fully disables auto-injection.
In Tool mode, the memory subsystem must be invisible to the prompt-construction
path. The model can still call ``memory_search`` explicitly (the tool is
registered through the existing tool-injection plumbing), but
``search_and_format_context`` the auto-injection chokepoint that returns
text for the proxy to splice into the latest user turn must return
``None`` unconditionally.
This is the load-bearing guarantee that lets us flip a deployment from
``auto_tail`` to ``tool`` without auditing every handler.
"""
from __future__ import annotations
import asyncio
import logging
from dataclasses import dataclass
from typing import Any
from headroom.proxy.memory_handler import MemoryConfig, MemoryHandler, MemoryMode
@dataclass
class _StubMemory:
id: str
content: str
metadata: dict[str, Any]
@dataclass
class _StubResult:
memory: _StubMemory
score: float
related_entities: list[str]
class _LoudBackend:
"""Backend that fails the test if it is queried.
Tool mode must short-circuit *before* the backend is touched. If
``search_memories`` runs, the chokepoint is broken.
"""
def __init__(self) -> None:
self.calls = 0
async def search_memories(self, **_: Any) -> list[_StubResult]:
self.calls += 1
# Return data that would be appended in AutoTail mode — if Tool
# mode incorrectly auto-injects we can detect via the text content.
return [
_StubResult(
memory=_StubMemory(
id="leaked_001",
content="LEAK: this content must not appear in TOOL mode",
metadata={},
),
score=0.99,
related_entities=[],
)
]
def _build_tool_mode_handler() -> tuple[MemoryHandler, _LoudBackend]:
config = MemoryConfig(
enabled=True,
backend="local",
inject_context=True,
inject_tools=True,
top_k=5,
min_similarity=0.3,
mode=MemoryMode.TOOL,
)
handler = MemoryHandler(config)
backend = _LoudBackend()
handler._backend = backend
handler._initialized = True
return handler, backend
def test_tool_mode_skips_auto_injection() -> None:
"""``search_and_format_context`` must return ``None`` in TOOL mode.
This is the single chokepoint enforcement: every provider handler
(Anthropic /v1/messages, OpenAI /v1/chat/completions and /v1/responses,
Gemini) calls this method. If it returns ``None``, no tail-injection
happens anywhere without per-handler audit.
"""
handler, backend = _build_tool_mode_handler()
messages = [
{"role": "user", "content": "What do you remember about me?"},
]
result = asyncio.run(handler.search_and_format_context("alpha", messages))
assert result is None, "TOOL mode must skip auto-injection (return None)"
# Defense-in-depth: the backend must NOT have been queried. If it had
# been, we would have wasted compute and burned cache lines reading
# data that would never be used.
assert backend.calls == 0, (
f"TOOL mode must not even query the backend; saw {backend.calls} calls"
)
def test_tool_mode_skip_emits_structured_log(caplog: Any) -> None:
"""The skip must emit a structured ``event=memory_mode_skip`` log line.
Realignment build constraint: every cache-affecting decision is logged
in the ``event=foo key=val`` style so operators can audit routing.
fix: integrate B6+B7 — fix cross-test contamination + injector mock parity Two follow-ups surfaced when B6 and B7 were merged onto the megamerge branch and the full suite ran: 1. tests/test_proxy_anthropic_cache_stability.py PR-B7 added `injector.scan_for_markers(optimized_messages)` to the Anthropic handler so the always-on tool-registration logic can see detected hashes for the current request. The two pre-existing `_FakeInjector` mocks (`test_ccr_system_instruction_injection_disabled_*` and `test_ccr_tool_injection_disabled_*`) didn't implement that method. Added a no-op `scan_for_markers` returning [] to both mocks — matches the real injector's contract for the not-yet-compressed request shape these tests exercise. 2. tests/test_memory_tool_mode.py::test_tool_mode_skip_emits_structured_log The B6 caplog assertion passed in isolation but failed in the full suite. Root cause: when an earlier test triggers proxy startup, `_setup_file_logging` flips `headroom.propagate=False` and attaches a RotatingFileHandler to the headroom logger. caplog captures via propagation to root, so log records stop reaching it. The conftest autouse fixture that resets `propagate=True` before every test gets shadowed by fixture-ordering edge cases. Principled fix: attach `caplog.handler` directly to `headroom.proxy.memory_handler` for the duration of the test so the capture is independent of propagation state. Restore the original level + remove the handler in `finally` to keep the test hermetic. Both B6 and B7 cherry-picks themselves are unmodified. This commit only adjusts test harness code so the pre-existing mocks/capture stay consistent with the new code paths.
2026-05-02 17:05:58 -07:00
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.
fix: B6 — memory injection moves to live-zone user-tail PR-A2 locked the system prompt and routed Anthropic memory injection to the latest non-frozen user turn. PR-B6 finishes the job: every provider handler that auto-injects memory context now does so via the live-zone tail, and a new MemoryMode enum makes the routing explicit and configurable. What changed ------------ * New `MemoryMode` enum in `headroom/proxy/memory_handler.py` with two values: - `AUTO_TAIL` (default) — retrieval results auto-append to the latest user message. The cache hot zone (system / instructions / frozen prefix) is never mutated. - `TOOL` — auto-injection is disabled entirely. The model must call `memory_search` to retrieve. Memory is opt-in and visible. * `MemoryConfig.mode: MemoryMode = MemoryMode.AUTO_TAIL` propagates into `search_and_format_context`, which now short-circuits to `None` in `TOOL` mode. This is the single chokepoint that gates every provider — Anthropic /v1/messages, OpenAI /v1/chat/completions, OpenAI /v1/responses, and Gemini all funnel through it, so flipping a deployment to tool mode does not require auditing every handler. * New `MemoryHandler._append_to_latest_user_tail(messages, context_text, provider=..., frozen_message_count=...)` static helper provides the unified tail-append entry point and dispatches to the existing provider-specific helpers (`AnthropicHandlerMixin._append_context_to_latest_non_frozen_user_turn` for Anthropic, `append_text_to_latest_user_chat_message` for OpenAI). * Gemini handler swapped from auto-prepending memory as a system message (the old P2-24 cache-hot-zone mutation pattern) to using `_append_to_latest_user_tail(provider="openai")`. * `ProxyConfig.memory_mode: Literal["auto_tail", "tool"] = "auto_tail"` surfaces the mode for deployment configuration. Server constructs the enum via `MemoryMode(config.memory_mode)` and raises loudly on unknown values (no silent fallback). * OpenAI Chat Completions, OpenAI Responses, and Anthropic handlers were already routing to the live-zone tail via PR-A2/A3 — no code change needed beyond inheriting the `TOOL`-mode skip from the chokepoint. Tests ----- * `tests/test_memory_auto_tail.py` (6 tests): - `test_memory_appears_in_latest_user_message_tail` — Anthropic shape. - `test_memory_appears_in_latest_user_message_tail_openai_shape` — OpenAI string + list-content shapes. - `test_memory_does_not_modify_system_or_tools` — system prompt and tools list are never touched; frozen-prefix tail is a no-op. - `test_same_query_byte_identical_across_runs` — two independent runs with identical inputs produce byte-identical mutated message lists (determinism gate). - `test_default_mode_is_auto_tail` — fresh `MemoryConfig` defaults to `AUTO_TAIL`. - `test_unknown_provider_raises` — invalid provider strings raise loudly per the no-silent-fallback policy. * `tests/test_memory_tool_mode.py` (4 tests): - `test_tool_mode_skips_auto_injection` — `search_and_format_context` returns `None` and the backend is never queried. - `test_tool_mode_skip_emits_structured_log` — skip emits the `event=memory_mode_skip` log line for routing-decision auditability. - `test_auto_tail_mode_does_query_backend` — inverse contrast pinning down that AUTO_TAIL still works end-to-end while TOOL skips. - `test_tool_mode_enum_value_is_stable` — string round-trip is pinned so deployment configs do not drift on rename. Determinism ----------- Tests stub the backend with a fixed, ordered result set so the byte-identical assertion isolates the tail-injection layer from upstream search non- determinism. The vector-search layer itself (LocalBackend / HNSW) is deterministic per-process for the same inputs but has thread-scheduling variability across processes; per the realignment plan, request-time determinism is guaranteed by the formatter and the tail-append helpers (this PR's responsibility), and the backend layer's determinism stays out-of-scope for B6. Per-PR-B6 plan: REALIGNMENT/04-phase-B-live-zone.md.
2026-05-02 16:37:54 -07:00
"""
handler, _backend = _build_tool_mode_handler()
fix: integrate B6+B7 — fix cross-test contamination + injector mock parity Two follow-ups surfaced when B6 and B7 were merged onto the megamerge branch and the full suite ran: 1. tests/test_proxy_anthropic_cache_stability.py PR-B7 added `injector.scan_for_markers(optimized_messages)` to the Anthropic handler so the always-on tool-registration logic can see detected hashes for the current request. The two pre-existing `_FakeInjector` mocks (`test_ccr_system_instruction_injection_disabled_*` and `test_ccr_tool_injection_disabled_*`) didn't implement that method. Added a no-op `scan_for_markers` returning [] to both mocks — matches the real injector's contract for the not-yet-compressed request shape these tests exercise. 2. tests/test_memory_tool_mode.py::test_tool_mode_skip_emits_structured_log The B6 caplog assertion passed in isolation but failed in the full suite. Root cause: when an earlier test triggers proxy startup, `_setup_file_logging` flips `headroom.propagate=False` and attaches a RotatingFileHandler to the headroom logger. caplog captures via propagation to root, so log records stop reaching it. The conftest autouse fixture that resets `propagate=True` before every test gets shadowed by fixture-ordering edge cases. Principled fix: attach `caplog.handler` directly to `headroom.proxy.memory_handler` for the duration of the test so the capture is independent of propagation state. Restore the original level + remove the handler in `finally` to keep the test hermetic. Both B6 and B7 cherry-picks themselves are unmodified. This commit only adjusts test harness code so the pre-existing mocks/capture stay consistent with the new code paths.
2026-05-02 17:05:58 -07:00
target_logger = logging.getLogger("headroom.proxy.memory_handler")
previous_level = target_logger.level
target_logger.setLevel(logging.INFO)
target_logger.addHandler(caplog.handler)
try:
fix: B6 — memory injection moves to live-zone user-tail PR-A2 locked the system prompt and routed Anthropic memory injection to the latest non-frozen user turn. PR-B6 finishes the job: every provider handler that auto-injects memory context now does so via the live-zone tail, and a new MemoryMode enum makes the routing explicit and configurable. What changed ------------ * New `MemoryMode` enum in `headroom/proxy/memory_handler.py` with two values: - `AUTO_TAIL` (default) — retrieval results auto-append to the latest user message. The cache hot zone (system / instructions / frozen prefix) is never mutated. - `TOOL` — auto-injection is disabled entirely. The model must call `memory_search` to retrieve. Memory is opt-in and visible. * `MemoryConfig.mode: MemoryMode = MemoryMode.AUTO_TAIL` propagates into `search_and_format_context`, which now short-circuits to `None` in `TOOL` mode. This is the single chokepoint that gates every provider — Anthropic /v1/messages, OpenAI /v1/chat/completions, OpenAI /v1/responses, and Gemini all funnel through it, so flipping a deployment to tool mode does not require auditing every handler. * New `MemoryHandler._append_to_latest_user_tail(messages, context_text, provider=..., frozen_message_count=...)` static helper provides the unified tail-append entry point and dispatches to the existing provider-specific helpers (`AnthropicHandlerMixin._append_context_to_latest_non_frozen_user_turn` for Anthropic, `append_text_to_latest_user_chat_message` for OpenAI). * Gemini handler swapped from auto-prepending memory as a system message (the old P2-24 cache-hot-zone mutation pattern) to using `_append_to_latest_user_tail(provider="openai")`. * `ProxyConfig.memory_mode: Literal["auto_tail", "tool"] = "auto_tail"` surfaces the mode for deployment configuration. Server constructs the enum via `MemoryMode(config.memory_mode)` and raises loudly on unknown values (no silent fallback). * OpenAI Chat Completions, OpenAI Responses, and Anthropic handlers were already routing to the live-zone tail via PR-A2/A3 — no code change needed beyond inheriting the `TOOL`-mode skip from the chokepoint. Tests ----- * `tests/test_memory_auto_tail.py` (6 tests): - `test_memory_appears_in_latest_user_message_tail` — Anthropic shape. - `test_memory_appears_in_latest_user_message_tail_openai_shape` — OpenAI string + list-content shapes. - `test_memory_does_not_modify_system_or_tools` — system prompt and tools list are never touched; frozen-prefix tail is a no-op. - `test_same_query_byte_identical_across_runs` — two independent runs with identical inputs produce byte-identical mutated message lists (determinism gate). - `test_default_mode_is_auto_tail` — fresh `MemoryConfig` defaults to `AUTO_TAIL`. - `test_unknown_provider_raises` — invalid provider strings raise loudly per the no-silent-fallback policy. * `tests/test_memory_tool_mode.py` (4 tests): - `test_tool_mode_skips_auto_injection` — `search_and_format_context` returns `None` and the backend is never queried. - `test_tool_mode_skip_emits_structured_log` — skip emits the `event=memory_mode_skip` log line for routing-decision auditability. - `test_auto_tail_mode_does_query_backend` — inverse contrast pinning down that AUTO_TAIL still works end-to-end while TOOL skips. - `test_tool_mode_enum_value_is_stable` — string round-trip is pinned so deployment configs do not drift on rename. Determinism ----------- Tests stub the backend with a fixed, ordered result set so the byte-identical assertion isolates the tail-injection layer from upstream search non- determinism. The vector-search layer itself (LocalBackend / HNSW) is deterministic per-process for the same inputs but has thread-scheduling variability across processes; per the realignment plan, request-time determinism is guaranteed by the formatter and the tail-append helpers (this PR's responsibility), and the backend layer's determinism stays out-of-scope for B6. Per-PR-B6 plan: REALIGNMENT/04-phase-B-live-zone.md.
2026-05-02 16:37:54 -07:00
result = asyncio.run(
handler.search_and_format_context("alpha", [{"role": "user", "content": "hi"}])
)
fix: integrate B6+B7 — fix cross-test contamination + injector mock parity Two follow-ups surfaced when B6 and B7 were merged onto the megamerge branch and the full suite ran: 1. tests/test_proxy_anthropic_cache_stability.py PR-B7 added `injector.scan_for_markers(optimized_messages)` to the Anthropic handler so the always-on tool-registration logic can see detected hashes for the current request. The two pre-existing `_FakeInjector` mocks (`test_ccr_system_instruction_injection_disabled_*` and `test_ccr_tool_injection_disabled_*`) didn't implement that method. Added a no-op `scan_for_markers` returning [] to both mocks — matches the real injector's contract for the not-yet-compressed request shape these tests exercise. 2. tests/test_memory_tool_mode.py::test_tool_mode_skip_emits_structured_log The B6 caplog assertion passed in isolation but failed in the full suite. Root cause: when an earlier test triggers proxy startup, `_setup_file_logging` flips `headroom.propagate=False` and attaches a RotatingFileHandler to the headroom logger. caplog captures via propagation to root, so log records stop reaching it. The conftest autouse fixture that resets `propagate=True` before every test gets shadowed by fixture-ordering edge cases. Principled fix: attach `caplog.handler` directly to `headroom.proxy.memory_handler` for the duration of the test so the capture is independent of propagation state. Restore the original level + remove the handler in `finally` to keep the test hermetic. Both B6 and B7 cherry-picks themselves are unmodified. This commit only adjusts test harness code so the pre-existing mocks/capture stay consistent with the new code paths.
2026-05-02 17:05:58 -07:00
finally:
target_logger.removeHandler(caplog.handler)
target_logger.setLevel(previous_level)
fix: B6 — memory injection moves to live-zone user-tail PR-A2 locked the system prompt and routed Anthropic memory injection to the latest non-frozen user turn. PR-B6 finishes the job: every provider handler that auto-injects memory context now does so via the live-zone tail, and a new MemoryMode enum makes the routing explicit and configurable. What changed ------------ * New `MemoryMode` enum in `headroom/proxy/memory_handler.py` with two values: - `AUTO_TAIL` (default) — retrieval results auto-append to the latest user message. The cache hot zone (system / instructions / frozen prefix) is never mutated. - `TOOL` — auto-injection is disabled entirely. The model must call `memory_search` to retrieve. Memory is opt-in and visible. * `MemoryConfig.mode: MemoryMode = MemoryMode.AUTO_TAIL` propagates into `search_and_format_context`, which now short-circuits to `None` in `TOOL` mode. This is the single chokepoint that gates every provider — Anthropic /v1/messages, OpenAI /v1/chat/completions, OpenAI /v1/responses, and Gemini all funnel through it, so flipping a deployment to tool mode does not require auditing every handler. * New `MemoryHandler._append_to_latest_user_tail(messages, context_text, provider=..., frozen_message_count=...)` static helper provides the unified tail-append entry point and dispatches to the existing provider-specific helpers (`AnthropicHandlerMixin._append_context_to_latest_non_frozen_user_turn` for Anthropic, `append_text_to_latest_user_chat_message` for OpenAI). * Gemini handler swapped from auto-prepending memory as a system message (the old P2-24 cache-hot-zone mutation pattern) to using `_append_to_latest_user_tail(provider="openai")`. * `ProxyConfig.memory_mode: Literal["auto_tail", "tool"] = "auto_tail"` surfaces the mode for deployment configuration. Server constructs the enum via `MemoryMode(config.memory_mode)` and raises loudly on unknown values (no silent fallback). * OpenAI Chat Completions, OpenAI Responses, and Anthropic handlers were already routing to the live-zone tail via PR-A2/A3 — no code change needed beyond inheriting the `TOOL`-mode skip from the chokepoint. Tests ----- * `tests/test_memory_auto_tail.py` (6 tests): - `test_memory_appears_in_latest_user_message_tail` — Anthropic shape. - `test_memory_appears_in_latest_user_message_tail_openai_shape` — OpenAI string + list-content shapes. - `test_memory_does_not_modify_system_or_tools` — system prompt and tools list are never touched; frozen-prefix tail is a no-op. - `test_same_query_byte_identical_across_runs` — two independent runs with identical inputs produce byte-identical mutated message lists (determinism gate). - `test_default_mode_is_auto_tail` — fresh `MemoryConfig` defaults to `AUTO_TAIL`. - `test_unknown_provider_raises` — invalid provider strings raise loudly per the no-silent-fallback policy. * `tests/test_memory_tool_mode.py` (4 tests): - `test_tool_mode_skips_auto_injection` — `search_and_format_context` returns `None` and the backend is never queried. - `test_tool_mode_skip_emits_structured_log` — skip emits the `event=memory_mode_skip` log line for routing-decision auditability. - `test_auto_tail_mode_does_query_backend` — inverse contrast pinning down that AUTO_TAIL still works end-to-end while TOOL skips. - `test_tool_mode_enum_value_is_stable` — string round-trip is pinned so deployment configs do not drift on rename. Determinism ----------- Tests stub the backend with a fixed, ordered result set so the byte-identical assertion isolates the tail-injection layer from upstream search non- determinism. The vector-search layer itself (LocalBackend / HNSW) is deterministic per-process for the same inputs but has thread-scheduling variability across processes; per the realignment plan, request-time determinism is guaranteed by the formatter and the tail-append helpers (this PR's responsibility), and the backend layer's determinism stays out-of-scope for B6. Per-PR-B6 plan: REALIGNMENT/04-phase-B-live-zone.md.
2026-05-02 16:37:54 -07:00
assert result is None
skip_records = [r for r in caplog.records if "event=memory_mode_skip" in r.getMessage()]
assert skip_records, "TOOL mode skip must emit event=memory_mode_skip log line"
msg = skip_records[0].getMessage()
assert "mode=tool" in msg
assert "user_id=alpha" in msg
def test_auto_tail_mode_does_query_backend() -> None:
"""Sanity: AUTO_TAIL mode (the inverse) MUST query the backend.
Without this contrast, ``test_tool_mode_skips_auto_injection`` could be
passing because the wiring is broken in both modes. This pins down that
AUTO_TAIL still works end-to-end while TOOL skips.
"""
config = MemoryConfig(
enabled=True,
backend="local",
inject_context=True,
inject_tools=True,
top_k=5,
min_similarity=0.3,
mode=MemoryMode.AUTO_TAIL,
)
handler = MemoryHandler(config)
backend = _LoudBackend()
handler._backend = backend
handler._initialized = True
result = asyncio.run(
handler.search_and_format_context("alpha", [{"role": "user", "content": "hi"}])
)
assert result is not None
assert backend.calls == 1
def test_tool_mode_enum_value_is_stable() -> None:
"""The ``"tool"`` string is the persistent on-the-wire identifier.
Pinned to catch accidental rename the ProxyConfig.memory_mode field
accepts the string and must be able to round-trip via
``MemoryMode("tool")``.
"""
assert MemoryMode("tool") is MemoryMode.TOOL
assert MemoryMode("auto_tail") is MemoryMode.AUTO_TAIL
assert MemoryMode.TOOL.value == "tool"
assert MemoryMode.AUTO_TAIL.value == "auto_tail"