#!/usr/bin/env python3
"""
Test script to verify interaction filtering logic
"""
import sqlite3
import os
def test_filtering_logic():
"""Test the filtering logic used in the UI"""
print("๐ Testing Interaction Filtering Logic")
print("=" * 60)
db_path = "./data/agent_tracker.db"
if not os.path.exists(db_path):
print(f"โ Database not found: {db_path}")
return
try:
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
# Test 1: Total count
cursor.execute("SELECT COUNT(*) FROM agent_interactions")
total_count = cursor.fetchone()[0]
print(f"๐ Total interactions: {total_count}")
# Test 2: Filter by conversation types
conversation_types = ['conversation_turn', 'client_request', 'agent_response', 'user_prompt']
placeholders = ','.join(['?'] * len(conversation_types))
query = f"SELECT COUNT(*) FROM agent_interactions WHERE interaction_type IN ({placeholders})"
cursor.execute(query, conversation_types)
conversation_count = cursor.fetchone()[0]
print(f"๐ฌ Conversation types ({', '.join(conversation_types)}): {conversation_count}")
# Test 3: Filter by system types
system_types = ['health_check', 'monitoring_started', 'module_import', 'system_startup', 'system_shutdown']
placeholders = ','.join(['?'] * len(system_types))
query = f"SELECT COUNT(*) FROM agent_interactions WHERE interaction_type IN ({placeholders})"
cursor.execute(query, system_types)
system_count = cursor.fetchone()[0]
print(f"โ๏ธ System types ({', '.join(system_types)}): {system_count}")
# Test 4: Filter by tool types
tool_types = ['tool_call', 'tool_response', 'tool_error']
placeholders = ','.join(['?'] * len(tool_types))
query = f"SELECT COUNT(*) FROM agent_interactions WHERE interaction_type IN ({placeholders})"
cursor.execute(query, tool_types)
tool_count = cursor.fetchone()[0]
print(f"๐ง Tool types ({', '.join(tool_types)}): {tool_count}")
# Test 5: Verify totals
calculated_total = conversation_count + system_count + tool_count
print(f"๐งฎ Calculated total: {calculated_total}")
print(f"โ
Match: {'Yes' if calculated_total == total_count else 'No'}")
# Test 6: Show all interaction types
print(f"\n๐ All interaction types:")
cursor.execute("SELECT interaction_type, COUNT(*) FROM agent_interactions GROUP BY interaction_type ORDER BY COUNT(*) DESC")
for interaction_type, count in cursor.fetchall():
print(f" โข {interaction_type}: {count}")
conn.close()
except Exception as e:
print(f"โ Error: {e}")
def main():
"""Main test function"""
print("๐ Interaction Filtering Test")
print("=" * 60)
test_filtering_logic()
print(f"\n๐ฏ Expected Results:")
print(f"โข Total: 617 interactions")
print(f"โข Conversations: 107 interactions")
print(f"โข System: 501 interactions")
print(f"โข Tools: 16 interactions")
print(f"โข Total: 107 + 501 + 16 = 624 (should match 617)")
if __name__ == "__main__":
main()