-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify_intelligence.py
More file actions
65 lines (56 loc) · 1.92 KB
/
verify_intelligence.py
File metadata and controls
65 lines (56 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import sys
import os
import json
# Add backend to path
sys.path.append(os.path.join(os.getcwd(), "backend"))
from app.detection import engine_ai
def test_engine():
print("--- SentinelGov Intelligence Engine Verification ---")
# Payload 1: High Risk (Rules + Stats)
payload_critical = {
"transaction_id": "TX_CRIT_001",
"features": {
"log_amount": 11.5,
"vendor_txn_count_30d": 20,
"unique_departments_30d": 5,
"time_distance_noon": 2.5
},
"rule_hits": ["STRUCTURING", "DUPLICATE_INVOICE"],
"stat_signals": {
"amount_z_score": 4.2
}
}
# Payload 2: ML-Only (Should be low/medium risk, ML trigger)
payload_ml_only = {
"transaction_id": "TX_ML_002",
"features": {
"log_amount": 9.8,
"vendor_txn_count_30d": 3,
"unique_departments_30d": 1,
"time_distance_noon": 1.0
},
"rule_hits": [],
"stat_signals": {
"amount_z_score": 0.5
}
}
print("\n[Test 1] Critical Risk Payload (Rules + Stats)")
res1 = engine_ai.process_forensic_payload(payload_critical)
print(json.dumps(res1, indent=2))
assert res1['risk']['risk_band'] == "CRITICAL"
assert res1['risk']['primary_trigger'] == "RULE"
assert "DUPLICATE_INVOICE" in res1['explanation']
print("\n[Test 2] ML-Only Payload")
# We need a trained model for ML score > 0
# For this test, we'll verify it doesn't crash and returns expected trigger
res2 = engine_ai.process_forensic_payload(payload_ml_only)
print(json.dumps(res2, indent=2))
# ML alone should never be CRITICAL
assert res2['risk']['risk_band'] != "CRITICAL"
print("\n--- Verification Successful ---")
if __name__ == "__main__":
try:
test_engine()
except Exception as e:
print(f"\nVerification Failed: {e}")
sys.exit(1)