58 lines
2.4 KiB
Python
58 lines
2.4 KiB
Python
"""Unit tests for the per-call wake_depth override in core.dispatch.
|
|
|
|
The HTTP adapter (and any caller) can request standard/deep session-start
|
|
content without flipping the global profile knob. These tests verify the
|
|
override is threaded into assemble_session_start's profile_state, that invalid
|
|
values fall back to the per-process state, and that the global _profile_state is
|
|
never mutated. assemble_session_start + build_runtime_graph are monkeypatched
|
|
so no real store/embedder is needed.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import iai_mcp.core as core
|
|
import iai_mcp.retrieve as retrieve
|
|
import iai_mcp.session as session
|
|
|
|
|
|
class _FakeStore:
|
|
def count_rows(self, table): # non-empty -> takes the assemble branch
|
|
return 5
|
|
|
|
|
|
def _patch(monkeypatch):
|
|
captured = {}
|
|
|
|
def fake_assemble(store, assignment, rc, *, session_id, profile_state):
|
|
captured["profile_state"] = profile_state
|
|
captured["session_id"] = session_id
|
|
return session.SessionStartPayload(l0="content")
|
|
|
|
monkeypatch.setattr(session, "assemble_session_start", fake_assemble)
|
|
monkeypatch.setattr(retrieve, "build_runtime_graph", lambda store: (None, {}, None))
|
|
monkeypatch.setattr(core, "_profile_state", {"wake_depth": "minimal", "literal_preservation": 0.5})
|
|
return captured
|
|
|
|
|
|
def test_wake_depth_override_threaded(monkeypatch):
|
|
captured = _patch(monkeypatch)
|
|
core.dispatch(_FakeStore(), "session_start_payload", {"session_id": "s", "wake_depth": "standard"})
|
|
ps = captured["profile_state"]
|
|
assert ps["wake_depth"] == "standard"
|
|
# other profile knobs are preserved in the override copy.
|
|
assert ps["literal_preservation"] == 0.5
|
|
# the module global must NOT be mutated by the override.
|
|
assert core._profile_state["wake_depth"] == "minimal"
|
|
|
|
|
|
def test_invalid_wake_depth_falls_back_to_profile(monkeypatch):
|
|
captured = _patch(monkeypatch)
|
|
core.dispatch(_FakeStore(), "session_start_payload", {"session_id": "s", "wake_depth": "ultra"})
|
|
# junk value ignored -> uses the per-process profile state (identity, minimal).
|
|
assert captured["profile_state"] is core._profile_state
|
|
assert captured["profile_state"]["wake_depth"] == "minimal"
|
|
|
|
|
|
def test_absent_wake_depth_uses_profile(monkeypatch):
|
|
captured = _patch(monkeypatch)
|
|
core.dispatch(_FakeStore(), "session_start_payload", {"session_id": "s"})
|
|
assert captured["profile_state"] is core._profile_state
|