""" Context-isolation eval — pure-function tests for the cross-agent contamination guards added to agent_hub.py. Verifies that: - _clear_foreign_agent_context drops only foreign-owned keys - Unknown keys (not in any agent's registry) are preserved - Keys owned by the kept agent survive """ import pytest from app.ai.agent.agent_hub import _clear_foreign_agent_context from evals.harness import load_cases, make_state CASES = load_cases("context_isolation.yaml") @pytest.mark.parametrize("case", CASES, ids=[c["id"] for c in CASES]) def test_clear_foreign_agent_context(case): state = make_state(agent_context=dict(case["agent_context_before"])) _clear_foreign_agent_context(state, keep_agent=case["keep_agent"]) for key in case["expected_keys_present"]: assert key in state.agent_context, ( f"Case {case['id']!r}: expected {key!r} preserved " f"(agent_context now: {list(state.agent_context.keys())})" ) for key in case["expected_keys_removed"]: assert key not in state.agent_context, ( f"Case {case['id']!r}: expected {key!r} removed " f"but still present in {list(state.agent_context.keys())}" )