| from types import SimpleNamespace |
| from uuid import uuid4 |
|
|
| from app.agents.validation import RuleValidationAgent |
|
|
|
|
| agent = RuleValidationAgent() |
|
|
|
|
| def make_rule(name, configuration): |
| return SimpleNamespace( |
| id=uuid4(), |
| name=name, |
| description="test rule", |
| rule_type="COMPLIANCE", |
| configuration=configuration, |
| enabled=True, |
| ) |
|
|
|
|
| def make_proposal(confidence=0.90, evidence=True): |
| proposed = { |
| "confidence": confidence, |
| } |
|
|
| if evidence: |
| proposed["evidence"] = { |
| "source": "test.pdf", |
| "page": 1, |
| } |
|
|
| return SimpleNamespace( |
| id=uuid4(), |
| proposal_type="CREATE", |
| proposed_changes=proposed, |
| ) |
|
|
|
|
| |
| result = agent.validate( |
| rules=[], |
| proposals=[make_proposal()], |
| ) |
|
|
| print("\nTEST 1 - NO RULES") |
| print(result) |
|
|
|
|
| |
| result = agent.validate( |
| rules=[ |
| make_rule( |
| "Minimum confidence", |
| { |
| "operator": "min_confidence", |
| "value": 0.80, |
| }, |
| ) |
| ], |
| proposals=[ |
| make_proposal(confidence=0.90), |
| ], |
| ) |
|
|
| print("\nTEST 2 - CONFIDENCE PASS") |
| print(result) |
|
|
|
|
| |
| result = agent.validate( |
| rules=[ |
| make_rule( |
| "Minimum confidence", |
| { |
| "operator": "min_confidence", |
| "value": 0.80, |
| }, |
| ) |
| ], |
| proposals=[ |
| make_proposal(confidence=0.50), |
| ], |
| ) |
|
|
| print("\nTEST 3 - CONFIDENCE FAIL") |
| print(result) |
|
|
|
|
| |
| result = agent.validate( |
| rules=[ |
| make_rule( |
| "Required evidence", |
| { |
| "operator": "required_evidence", |
| }, |
| ) |
| ], |
| proposals=[ |
| make_proposal(evidence=True), |
| ], |
| ) |
|
|
| print("\nTEST 4 - EVIDENCE PASS") |
| print(result) |
|
|
|
|
| |
| result = agent.validate( |
| rules=[ |
| make_rule( |
| "Required evidence", |
| { |
| "operator": "required_evidence", |
| }, |
| ) |
| ], |
| proposals=[ |
| make_proposal(evidence=False), |
| ], |
| ) |
|
|
| print("\nTEST 5 - EVIDENCE FAIL") |
| print(result) |
|
|
|
|
| |
| result = agent.validate( |
| rules=[ |
| make_rule( |
| "Broken confidence rule", |
| { |
| "operator": "min_confidence", |
| "value": "not-a-number", |
| }, |
| ) |
| ], |
| proposals=[ |
| make_proposal(), |
| ], |
| ) |
|
|
| print("\nTEST 6 - MALFORMED RULE") |
| print(result) |
|
|
|
|
| |
| result = agent.validate( |
| rules=[ |
| make_rule( |
| "Unknown rule", |
| { |
| "operator": "unsupported_operator", |
| }, |
| ) |
| ], |
| proposals=[ |
| make_proposal(), |
| ], |
| ) |
|
|
| print("\nTEST 7 - UNKNOWN OPERATOR") |
| print(result) |
|
|
|
|
| print("\n===================================") |
| print("VALIDATION TEST RUN COMPLETE") |
| print("===================================") |
|
|