kulono / agent-constitution
blob · tests/test_constitution.py · python
← filesrepo
tests/test_constitution.pypython
1from agent_constitution import (
2 Constitution,
3 ConstitutionEnforcer,
4 ConstitutionRule,
5 RuleType,
6 ViolationAction,
7)
8
9
10def make_constitution():
11 c = Constitution(name="test", agent_type="default")
12 c.boundaries.append(ConstitutionRule(
13 rule_id="B-001",
14 rule_type=RuleType.BOUNDARY,
15 description="Never delete production data",
16 pattern=["production", "rm -rf"],
17 action=ViolationAction.REJECT,
18 ))
19 return c
20
21
22def test_violation_rejected():
23 enforcer = ConstitutionEnforcer(make_constitution())
24 res = enforcer.check_action("rm -rf /var/data/production")
25 assert not res.allowed
26 assert len(res.matched_rules) >= 1
27
28
29def test_benign_action_allowed():
30 enforcer = ConstitutionEnforcer(make_constitution())
31 res = enforcer.check_action("ls -la /tmp")
32 assert res.allowed
33
100%