sentinel-scam-honeypo / tests /local_guvi_simulation.py
avinash-rai's picture
Final critical GUVI fixes: callback threshold, crash fix, zero-sleep mode
639c192
import asyncio
import httpx
import sys
import uuid
# LOCAL TARGET
TARGET_URL = "http://localhost:8000/api/guvi/analyze"
async def run_simulation():
session_id = f"LOCAL-SIM-{uuid.uuid4().hex[:6]}"
print(f"πŸš€ STARTING LOCAL GUVI SIMULATION (Session: {session_id})")
print("────────────────────────────────────────────────────────")
# 3-Turn Sequence (User -> Bot -> User -> Bot -> User -> Bot) = 6 Messages
turns = [
"Hello, who is this?",
"I received a message about my bank account locking.",
"Okay, I am ready to pay. Where do I send the money?"
]
history = []
async with httpx.AsyncClient(timeout=30.0) as client:
for i, text in enumerate(turns):
print(f"\nπŸ“€ Sending Turn {i+1}/3: '{text}'")
payload = {
"sessionId": session_id,
"message": {
"text": text,
"sender": "user"
},
"conversationHistory": history,
"metadata": {"source": "local_sim"}
}
try:
resp = await client.post(TARGET_URL, json=payload)
if resp.status_code == 200:
data = resp.json()
reply = data.get("reply", "No reply")
metrics = data.get("engagementMetrics", {})
print(f"βœ… Response {i+1}: '{reply[:50]}...'")
print(f" Metrics: {metrics.get('totalMessagesExchanged', 0)} msgs, {metrics.get('engagementDurationSeconds', 0)}s")
# Update History for next turn
history.append({"text": text, "sender": "user"})
history.append({"text": reply, "sender": "bot"})
# Check for Callback Conditions
if i == 2:
print("\nπŸ”Ž Verifying Callback Trigger (Turn 3/3)...")
if metrics.get('totalMessagesExchanged', 0) >= 6:
print("βœ… SUCCESS: Message count >= 6. Callback should fire in server logs.")
else:
print("❌ FAILURE: Message count < 6.")
else:
print(f"❌ Error {resp.status_code}: {resp.text}")
except Exception as e:
print(f"⚠️ Request Failed: {e}")
break
print("\n🏁 Simulation Complete. Check server logs for '[GUVI] Final callback sent'.")
if __name__ == "__main__":
try:
asyncio.run(run_simulation())
except KeyboardInterrupt:
pass