| from __future__ import annotations |
|
|
| import json |
| import sys |
| from pathlib import Path |
|
|
| ROOT = Path(__file__).resolve().parents[1] |
| if str(ROOT) not in sys.path: |
| sys.path.insert(0, str(ROOT)) |
|
|
| from decision_runtime import NormativeDecisionRuntime |
|
|
|
|
| def main() -> int: |
| registry = json.loads((ROOT / "data" / "registry" / "normative_decision_contracts.json").read_text(encoding="utf-8")) |
| runtime = NormativeDecisionRuntime(registry["contracts"], "test-build") |
|
|
| cases = [ |
| ( |
| "decided_terminate", |
| runtime.evaluate("open_education_enrollment_status", {"education_mode": "OPEN_EDUCATION", "consecutive_terms_conditions_not_met": 4}), |
| "DECIDED", |
| ), |
| ( |
| "decided_continue", |
| runtime.evaluate("open_education_enrollment_status", {"education_mode": "OPEN_EDUCATION", "consecutive_terms_conditions_not_met": 3}), |
| "DECIDED", |
| ), |
| ( |
| "missing_fact", |
| runtime.evaluate("open_education_enrollment_status", {"education_mode": "OPEN_EDUCATION"}), |
| "UNKNOWN", |
| ), |
| ( |
| "legal_judgment", |
| runtime.evaluate("remote_education_rector_assistant_limit", {"central_open_education_university": True}), |
| "REQUIRES_JUDGMENT", |
| ), |
| ("unknown_scope", runtime.evaluate("not_published", {}), "OUT_OF_SCOPE"), |
| ] |
|
|
| conflict_contract = { |
| "contract_id": "TEST_CONFLICT", |
| "decision_type": "conflict_test", |
| "source_refs": [{"document_id": "TEST", "article_id": "Madde 1"}], |
| "input_schema": {"fields": {"x": {"required": True}}}, |
| "rules": [ |
| {"rule_id": "a", "priority": 10, "when": {"all": [{"fact": "x", "operator": "eq", "value": 1}]}, "outcome": "YES"}, |
| {"rule_id": "b", "priority": 10, "when": {"all": [{"fact": "x", "operator": "eq", "value": 1}]}, "outcome": "NO"}, |
| ], |
| } |
| conflict_runtime = NormativeDecisionRuntime([conflict_contract], "test-conflict") |
| cases.append(("conflict", conflict_runtime.evaluate("conflict_test", {"x": 1}), "CONFLICT")) |
|
|
| failures = [] |
| for name, result, expected in cases: |
| if result.get("status") != expected: |
| failures.append(f"{name}: {result.get('status')} != {expected}") |
|
|
| first = runtime.evaluate("open_education_enrollment_status", {"education_mode": "OPEN_EDUCATION", "consecutive_terms_conditions_not_met": 4}) |
| second = runtime.evaluate("open_education_enrollment_status", {"consecutive_terms_conditions_not_met": 4, "education_mode": "OPEN_EDUCATION"}) |
| if first != second: |
| failures.append("determinism: identical facts produced different results") |
| if runtime.governance_report().get("warning_count", 0) < 1: |
| failures.append("governance: expected at least one legal judgment warning") |
|
|
| if failures: |
| print("FAIL") |
| print("\n".join(failures)) |
| return 1 |
| print(f"PASS decision runtime: {len(cases)} status cases + determinism + governance") |
| return 0 |
|
|
|
|
| if __name__ == "__main__": |
| raise SystemExit(main()) |
|
|