Spaces:
Sleeping

TFA / simple_test.py
VAH6002's picture
Upload 61 files
1af9fb8 verified
Raw History Blame Contribute Delete
5.45 kB
"""Simple test runner for TFA functionality without full agent system."""
import os
import json
# Set dummy API key
os.environ.setdefault("GOOGLE_API_KEY", "test-key-for-mock")
def test_sponge_tools():
"""Test Sponge tools with mock data."""
print("πŸ§ͺ Testing Sponge Tools...")
from tfa_agents.tools.sponge_mock import use_mock_client
from tfa_agents.tools.sponge_tools import (
get_invocation_data,
get_failed_actions,
search_historical_failures,
)
# Configure mock client
use_mock_client("code_regression")
# Test invocation data
result = get_invocation_data("fe3e0b7f-7bb9-4524-8a79-3c62cf028243")
data = json.loads(result)
print(f"βœ… Invocation Status: {data['invocation']['status']}")
print(f"βœ… Pass Rate: {data['summary']['pass_rate']:.0%}")
# Test failed actions
result = get_failed_actions("fe3e0b7f-7bb9-4524-8a79-3c62cf028243")
actions = json.loads(result)
print(f"βœ… Failed Actions: {len(actions)}")
# Test historical failures
result = search_historical_failures("//gmail/android/copycat:mark_multiple_emails_as_read")
history = json.loads(result)
print(f"βœ… Historical Pass Rate: {history['statistics']['pass_rate']:.1%}")
def test_metrics_system():
"""Test metrics system."""
print("\nπŸ“Š Testing Metrics System...")
from tfa_agents.tools.metrics_client import get_metrics_client
from tfa_agents.shared.models import Platform
client = get_metrics_client()
# Test daily metrics
daily_metrics = client.get_daily_failure_percentage()
print("βœ… Daily Failure Percentages:")
for platform, rate in daily_metrics.items():
status = "🟒" if rate < 10 else "🟑" if rate < 20 else "πŸ”΄"
print(f" {status} {platform.value}: {rate:.1f}%")
# Test trends
trends = client.get_platform_trends("7d")
print("βœ… Platform Trends (7 days):")
for platform, trend in trends.items():
trend_emoji = {"improving": "πŸ“ˆ", "degrading": "πŸ“‰", "stable": "➑️"}.get(trend.trend_direction, "❓")
print(f" {trend_emoji} {platform.value}: {trend.average_failure_rate:.1f}% ({trend.trend_direction})")
def test_metrics_tools():
"""Test metrics tools functions."""
print("\nπŸ”§ Testing Metrics Tools...")
from tfa_agents.tools.metrics_tools import (
get_daily_failure_percentages,
get_platform_trends,
get_platform_health_score,
)
# Test daily percentages
result = get_daily_failure_percentages(platforms="Android,Web")
data = json.loads(result)
print(f"βœ… Daily Metrics: {len(data['failure_percentages'])} platforms")
print(f" Average: {data['summary']['average_failure_rate']:.1f}%")
# Test trends
result = get_platform_trends("7d", "Android")
data = json.loads(result)
android_trend = data['platform_trends']['Android']
print(f"βœ… Android Trend: {android_trend['average_failure_rate']:.1f}% ({android_trend['trend_direction']})")
# Test health score
result = get_platform_health_score("Android", "7d")
data = json.loads(result)
if 'error' not in data:
print(f"βœ… Android Health: {data['health_score']}/100 ({data['status']})")
def main():
"""Run all tests."""
print("""
╔══════════════════════════════════════════════════════════════════════╗
β•‘ TFA Simple Test Runner β•‘
β•‘ Testing core functionality without agents β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•
""")
try:
test_sponge_tools()
test_metrics_system()
test_metrics_tools()
print("""
╔══════════════════════════════════════════════════════════════════════╗
β•‘ βœ… ALL TESTS PASSED! β•‘
β•‘ β•‘
β•‘ πŸš€ Your TFA application is ready to use! β•‘
β•‘ β•‘
β•‘ Next steps: β•‘
β•‘ β€’ Run: streamlit run tfa_ui/app.py (for web interface) β•‘
β•‘ β€’ Run: python -m tfa_agents.metrics_cli daily (for CLI) β•‘
β•‘ β€’ Check the metrics dashboard in the web UI β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•
""")
except Exception as e:
print(f"\n❌ Test failed: {type(e).__name__}: {e}")
import traceback
traceback.print_exc()
if __name__ == "__main__":
main()