test: add prefetch_context observer-resolution test for ai_observe_others
Verify that get_prefetch_context queries user context through the assistant observer when _ai_observe_others is enabled, matching the fix that routes _fetch_session_context through _resolve_observer_target.
This commit is contained in:
parent
9a887e7c5b
commit
b08a13cd33
|
|
@ -361,6 +361,46 @@ class TestPeerLookupHelpers:
|
|||
user_peer.context.assert_called_once_with(target=session.user_peer_id)
|
||||
ai_peer.context.assert_called_once_with(target=session.assistant_peer_id)
|
||||
|
||||
def test_get_prefetch_context_uses_assistant_observer_for_user_when_ai_observe_others(self):
|
||||
"""With ai_observe_others enabled, get_prefetch_context must query
|
||||
the user context through the assistant observer, not the user peer."""
|
||||
mgr, session = self._make_cached_manager()
|
||||
mgr._ai_observe_others = True
|
||||
|
||||
assistant_peer = MagicMock()
|
||||
|
||||
def _assistant_context(**kwargs):
|
||||
if kwargs.get("target") == session.user_peer_id:
|
||||
return SimpleNamespace(
|
||||
representation="User via assistant",
|
||||
peer_card=["Name: Robert"],
|
||||
)
|
||||
if kwargs.get("target") == session.assistant_peer_id:
|
||||
return SimpleNamespace(
|
||||
representation="AI self",
|
||||
peer_card=["Role: Assistant"],
|
||||
)
|
||||
return SimpleNamespace(representation="Unknown", peer_card=[])
|
||||
|
||||
assistant_peer.context.side_effect = _assistant_context
|
||||
mgr._get_or_create_peer = MagicMock(
|
||||
side_effect=[assistant_peer, assistant_peer],
|
||||
)
|
||||
|
||||
result = mgr.get_prefetch_context(session.key)
|
||||
|
||||
assert result == {
|
||||
"representation": "User via assistant",
|
||||
"card": "Name: Robert",
|
||||
"ai_representation": "AI self",
|
||||
"ai_card": "Role: Assistant",
|
||||
}
|
||||
assert assistant_peer.context.call_count == 2
|
||||
assistant_peer.context.assert_any_call(
|
||||
target=session.user_peer_id, search_query=None,
|
||||
)
|
||||
assistant_peer.context.assert_any_call(target=session.assistant_peer_id)
|
||||
|
||||
def test_get_ai_representation_uses_peer_api(self):
|
||||
mgr, session = self._make_cached_manager()
|
||||
ai_peer = MagicMock()
|
||||
|
|
|
|||
Loading…
Reference in New Issue