The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test: trim the switch-invalidation suite to the two invariants
kshitijk4poor5b3fbcaf71f1
diff --git a/tests/agent/test_system_prompt_switch_invalidation.py b/tests/agent/test_system_prompt_switch_invalidation.pyindex 48085dd65a2..40ab985742d 100644--- a/tests/agent/test_system_prompt_switch_invalidation.py+++ b/tests/agent/test_system_prompt_switch_invalidation.py@@ -26,12 +26,10 @@ Real ``SessionDB`` on a temp file; no mock stands in for the DB layer.from __future__ import annotations-import loggingfrom unittest.mock import MagicMockimport pytest-from agent.conversation_loop import _restore_or_build_system_promptfrom hermes_state import SessionDBSESSION_ID = "switch-session"@@ -55,32 +53,6 @@ def db(tmp_path, monkeypatch):session_db.close()-def _make_agent(db, *, model: str, provider: str, prebuilt: str) -> MagicMock:- """The minimal agent ``_restore_or_build_system_prompt`` needs; the DB is real."""- agent = MagicMock()- agent._cached_system_prompt = None- agent.session_id = SESSION_ID- agent.model = model- agent.provider = provider- agent.platform = "discord"- agent._session_db = db- agent._use_prompt_caching = False- agent._persist_disabled = True # no on_session_start hook, no tool-pin rewrite- agent.enabled_toolsets = agent.disabled_toolsets = None- agent.tools = []- agent._build_system_prompt = MagicMock(return_value=prebuilt)- return agent---def _continue_turn(db, *, model: str, provider: str, prebuilt: str, caplog):- """Run the next turn of a continuing session and return (agent, warnings)."""- agent = _make_agent(db, model=model, provider=provider, prebuilt=prebuilt)- with caplog.at_level(logging.INFO, logger="agent.conversation_loop"):- _restore_or_build_system_prompt(agent, None, [{"role": "user", "content": "hi"}])- warnings = [r for r in caplog.records if r.levelno >= logging.WARNING]- return agent, warnings--_ROUTE_COMMITS = {"model": lambda db: db.update_session_model(SESSION_ID, "anthropic/claude-opus-4.8", provider="anthropic", base_url="https://a/v1",@@ -115,64 +87,6 @@ def test_route_commits_keep_the_stored_prompt(db, commit):).fetchone()[0] == 1-class TestNextTurnAfterASwitchCommit:- def test_same_route_commit_reuses_the_stored_bytes(self, db, caplog):- """The picker re-committing the session's current route must not cost a rebuild."""- prompt = _stored_prompt("glm-5.3", "zro")- db.create_session(SESSION_ID, source="discord", model="glm-5.3")- db.update_system_prompt(SESSION_ID, prompt)-- db.update_session_model(SESSION_ID, "glm-5.3", provider="zro", base_url="https://hyper/v1")-- agent, warnings = _continue_turn(- db, model="glm-5.3", provider="zro", prebuilt="REBUILT", caplog=caplog,- )-- assert agent._cached_system_prompt == prompt- agent._build_system_prompt.assert_not_called()- assert warnings == []-- def test_route_change_rebuilds_through_the_identity_check(self, db, caplog):- """A real switch still rebuilds — on the next turn, via the stale footer, not a null row."""- db.create_session(SESSION_ID, source="discord", model="deepseek-v4.1-flash")- db.update_system_prompt(SESSION_ID, _stored_prompt("deepseek-v4.1-flash", "hyper"))-- db.update_session_model(- SESSION_ID, "glm-5.3", provider="zro", base_url="https://hyper/v1",- )-- rebuilt = _stored_prompt("glm-5.3", "zro")- agent, warnings = _continue_turn(- db, model="glm-5.3", provider="zro", prebuilt=rebuilt, caplog=caplog,- )-- agent._build_system_prompt.assert_called_once()- assert agent._cached_system_prompt == rebuilt- # The rebuilt bytes are persisted so the following turns reuse them verbatim.- assert db.get_session(SESSION_ID)["system_prompt"] == rebuilt- assert warnings == []- assert any(- r.levelno == logging.INFO and "stale runtime identity" in r.getMessage()- for r in caplog.records- )-- def test_a_genuinely_lost_prompt_still_warns(self, db, caplog):- """The WARNING keeps its real meaning: nobody switched — the row was lost."""- db.create_session(SESSION_ID, source="discord", model="glm-5.3")- db.update_system_prompt(SESSION_ID, _stored_prompt("glm-5.3", "zro"))- db.update_system_prompt(SESSION_ID, None) # a write that lost the prompt-- agent, warnings = _continue_turn(- db, model="glm-5.3", provider="zro", prebuilt="REBUILT", caplog=caplog,- )-- assert agent._cached_system_prompt == "REBUILT"- assert any(- "is null; rebuilding" in w.getMessage() and "update_system_prompt write path" in w.getMessage()- for w in warnings- )--def test_compression_tip_adoption_applies_the_identity_check(db):"""The other reader that seeds ``_cached_system_prompt`` from a stored row.