From fefc6d84f72cd557a7f09aa2b15461a0ab99f2be Mon Sep 17 00:00:00 2001 From: Robert Lippmann Date: Fri, 6 Mar 2026 01:50:04 -0500 Subject: [PATCH] Tighten policy persistence property test --- tests/test_engine.py | 2 -- tests/test_properties.py | 38 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/tests/test_engine.py b/tests/test_engine.py index 5e95d9e..d0c4dbf 100644 --- a/tests/test_engine.py +++ b/tests/test_engine.py @@ -1,5 +1,3 @@ -from __future__ import annotations - from context_compiler import create_engine diff --git a/tests/test_properties.py b/tests/test_properties.py index 9f2aaff..4532003 100644 --- a/tests/test_properties.py +++ b/tests/test_properties.py @@ -1,5 +1,3 @@ -from __future__ import annotations - import re from hypothesis import assume, given @@ -38,6 +36,42 @@ def test_policy_addition_is_idempotent(item: str) -> None: assert twice == once +@given( + st.text(min_size=1, max_size=30), + st.lists( + st.sampled_from( + [ + "hello there", + "what do you think?", + "thanks for the help", + "this is just context", + "can you explain that?", + "yes", + "no", + ] + ), + min_size=0, + max_size=10, + ), +) +def test_policy_persists_across_passthrough_turns(item: str, turns: list[str]) -> None: + engine = create_engine() + normalized_item = _split_items(item) + assume(len(normalized_item) == 1) + + decision = engine.step(f"avoid {item}") + expected = normalized_item[0] + assert decision["kind"] == "update" + assert engine.state["policies"]["prohibit"] == [expected] + + for turn in turns: + intervening = engine.step(turn) + assert intervening["kind"] == "passthrough" + assert engine.state["policies"]["prohibit"] == [expected] + + assert expected in engine.state["policies"]["prohibit"] + + @given( st.from_regex(r"[A-Za-z0-9][A-Za-z0-9 ]{0,20}", fullmatch=True), st.from_regex(r"[A-Za-z0-9][A-Za-z0-9 ]{0,20}", fullmatch=True),