kulono / agent-constitution
blob · tests/test_constitution.py · python
tests/test_constitution.pypython
1from agent_constitution import (2 Constitution,3 ConstitutionEnforcer,4 ConstitutionRule,5 RuleType,6 ViolationAction,7)8910def 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 c202122def test_violation_rejected():23 enforcer = ConstitutionEnforcer(make_constitution())24 res = enforcer.check_action("rm -rf /var/data/production")25 assert not res.allowed26 assert len(res.matched_rules) >= 1272829def test_benign_action_allowed():30 enforcer = ConstitutionEnforcer(make_constitution())31 res = enforcer.check_action("ls -la /tmp")32 assert res.allowed33
100%