Deployment Ready: Fixed scam detection low confidence, added production audit report, optimized throttles
1838600 | import json | |
| import os | |
| import uuid | |
| from datetime import datetime | |
| from app.enforcement.stakeholder_exports import StakeholderExporter | |
| from app.utils.dossier_generator import dossier_generator | |
| def test_generate_dossier(): | |
| print("Starting Comprehensive Dossier & Export Test...") | |
| # 1. Simulate Scammer Data | |
| session_id = "SESSION-LIVE-TEST-002" | |
| scam_type = "banking_scam" | |
| risk_score = 0.92 | |
| intelligence = { | |
| "phone_numbers": ["+918877665544"], | |
| "upi_ids": ["fraudster@ybl"], | |
| "urls": ["http://bank-kyc-update.net"], | |
| "bank_accounts": ["987654321098"] | |
| } | |
| threat_intel = { | |
| "campaign_id": "CAMP_BANK_FRAUD_JAN_2026", | |
| "pattern": "KYC Revocation", | |
| "vector": "SMS/Phishing", | |
| "scammer_id": "SCMR-XYZ-789", | |
| "mitre_ttps": [ | |
| {"id": "T1566", "name": "Phishing", "tactic": "Initial Access"}, | |
| {"id": "T1411", "name": "Input Capture", "tactic": "Credential Access"} | |
| ] | |
| } | |
| summary = "Threat actor impersonaled bank official. Claimed KYC expired. Requested bank details." | |
| # 2. Test StakeholderExporter (JSON/Official) | |
| print("\n[+] Testing StakeholderExporter (Official JSON Outputs)...") | |
| reports = StakeholderExporter.export_all( | |
| session_id=session_id, | |
| scam_type=scam_type, | |
| intelligence=intelligence, | |
| threat_intel=threat_intel, | |
| risk_score=risk_score, | |
| conversation_summary=summary | |
| ) | |
| os.makedirs("reports", exist_ok=True) | |
| with open("reports/official_exports_bundle.json", "w", encoding="utf-8") as f: | |
| json.dump(reports, f, indent=2) | |
| print("COMPLETED: Official Exports Bundle Generated (JSON)") | |
| # 3. Test DossierGenerator (Visual/Markdown) | |
| print("\n[+] Testing DossierGenerator (Human-Readable Markdown)...") | |
| # Format data for DossierGenerator | |
| dossier_input = { | |
| "scam_type": scam_type, | |
| "risk_score": risk_score, | |
| "threat_intelligence": threat_intel, | |
| "aggregated_intelligence": intelligence, | |
| "analysis": {"scam_category": threat_intel["vector"]}, | |
| "telemetry": {"geo": "Chennai, India", "device": "iPhone 15 / Safari"}, | |
| "metadata": {"timestamp": datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")}, | |
| "honeypot_response": {"persona": "Worried Retiree"} | |
| } | |
| md_dossier = dossier_generator.generate_markdown(session_id, dossier_input) | |
| with open("reports/human_readable_dossier.md", "w", encoding="utf-8") as f: | |
| f.write(md_dossier) | |
| print("COMPLETED: Human-Readable Dossier Generated (Markdown)") | |
| print(f"\nSUCCESS! Both files tested. Results saved to 'reports/'.") | |
| if __name__ == "__main__": | |
| test_generate_dossier() | |