Spaces:
Sleeping

File size: 5,447 Bytes
1af9fb8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
"""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()