Spaces:
Sleeping
Sleeping
| import asyncio | |
| import os | |
| import time | |
| from app.services.audit import audit_service | |
| async def verify_audit(): | |
| print("Verifying Audit Service...") | |
| # 1. Log Interaction | |
| await audit_service.log_interaction( | |
| user_id="test_user_1", | |
| intent="test_intent", | |
| guardrails_triggered=[] | |
| ) | |
| print("Logged interaction.") | |
| # 2. Log Violation | |
| await audit_service.log_violation( | |
| user_id="test_user_unsafe", | |
| violation_type="Prohibited Phrase", | |
| content="This is a test violation content." | |
| ) | |
| print("Logged violation.") | |
| # 3. Check File | |
| time.sleep(1) # Ensure flush | |
| log_path = "logs/ora.log" | |
| if os.path.exists(log_path): | |
| print(f"Log file found at {log_path}") | |
| with open(log_path, "r") as f: | |
| content = f.read() | |
| print("--- Log Content ---") | |
| print(content) | |
| print("-------------------") | |
| if "test_user_1" in content and "test_user_unsafe" in content: | |
| print("SUCCESS: Both log entries found.") | |
| else: | |
| print("FAILURE: Log entries missing.") | |
| else: | |
| print(f"FAILURE: Log file not found at {log_path}") | |
| if __name__ == "__main__": | |
| asyncio.run(verify_audit()) | |