Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions tests/test_engine.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

from context_compiler import create_engine


Expand Down
38 changes: 36 additions & 2 deletions tests/test_properties.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

import re

from hypothesis import assume, given
Expand Down Expand Up @@ -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),
Expand Down
Loading