File size: 6,453 Bytes
dce5ebb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
"""

Demo script to test the Test Failure Analysis Agent

"""
import asyncio
import logging
from test_failure_analysis_agent import TestFailureAnalysisAgent, AnalysisRequest

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

async def demo_comprehensive_analysis():
    """Demo comprehensive analysis"""
    print("=" * 60)
    print("DEMO: Comprehensive Test Failure Analysis")
    print("=" * 60)
    
    agent = TestFailureAnalysisAgent()
    
    try:
        # Create analysis request for a flaky test
        request = AnalysisRequest(
            target_id="//service/auth:flaky_login_test",
            failing_invocation_id="inv_failed_12345",
            passing_invocation_id="inv_passed_12344",
            build_target="//service/auth:test",
            analysis_type="comprehensive"
        )
        
        # Run analysis
        result = await agent.analyze(request)
        
        # Generate and display report
        report = agent.generate_report(result)
        print(report)
        
        print("\n" + "=" * 60)
        print("Analysis completed successfully!")
        print("=" * 60)
        
    except Exception as e:
        logger.error(f"Demo failed: {e}")
    finally:
        await agent.disconnect()

async def demo_quick_analysis():
    """Demo quick analysis"""
    print("=" * 60)
    print("DEMO: Quick Test Failure Analysis")
    print("=" * 60)
    
    agent = TestFailureAnalysisAgent()
    
    try:
        # Create analysis request for quick check
        request = AnalysisRequest(
            target_id="//service/payment:timeout_test",
            failing_invocation_id="inv_timeout_67890",
            analysis_type="quick"
        )
        
        # Run analysis
        result = await agent.analyze(request)
        
        # Generate and display report
        report = agent.generate_report(result)
        print(report)
        
        print("\n" + "=" * 60)
        print("Quick analysis completed!")
        print("=" * 60)
        
    except Exception as e:
        logger.error(f"Demo failed: {e}")
    finally:
        await agent.disconnect()

async def demo_visual_regression():
    """Demo visual regression analysis"""
    print("=" * 60)
    print("DEMO: Visual Regression Analysis")
    print("=" * 60)
    
    agent = TestFailureAnalysisAgent()
    
    try:
        # Create analysis request for visual regression
        request = AnalysisRequest(
            target_id="//ui/checkout:visual_test",
            failing_invocation_id="inv_ui_failed_11111",
            passing_invocation_id="inv_ui_passed_11110",
            build_target="//ui/checkout:test",
            analysis_type="visual_regression"
        )
        
        # Run analysis
        result = await agent.analyze(request)
        
        # Generate and display report
        report = agent.generate_report(result)
        print(report)
        
        print("\n" + "=" * 60)
        print("Visual regression analysis completed!")
        print("=" * 60)
        
    except Exception as e:
        logger.error(f"Demo failed: {e}")
    finally:
        await agent.disconnect()

async def demo_all_sponge_tools():
    """Demo all individual Sponge tools"""
    print("=" * 60)
    print("DEMO: All Sponge MCP Tools")
    print("=" * 60)
    
    agent = TestFailureAnalysisAgent()
    
    try:
        await agent.connect_to_sponge_server()
        
        # Test each tool individually
        tools_to_test = [
            ("get_flaky_index", {"target_id": "//test:flaky_example", "runs_count": 20}),
            ("detect_regression_window", {"target_id": "//test:regression_example", "lookback_days": 5}),
            ("compare_log_diffs", {
                "failing_invocation_id": "fail_123",
                "passing_invocation_id": "pass_123",
                "build_target": "//test:example"
            }),
            ("locate_error_root", {"invocation_id": "error_123", "build_target": "//test:example"}),
            ("correlate_cross_service_logs", {
                "invocation_id": "cross_123",
                "service_targets": ["//service/auth:test", "//service/payment:test"],
                "time_window": 300
            }),
            ("summarize_log_anomalies", {
                "invocation_id": "anomaly_123",
                "build_target": "//test:example",
                "min_occurrences": 2
            }),
            ("fetch_stack_trace_context", {
                "invocation_id": "stack_123",
                "build_target": "//test:example",
                "context_lines": 5
            }),
            ("inspect_visual_state", {
                "invocation_id": "visual_123",
                "build_target": "//ui:test",
                "action_name": "click_button"
            }),
            ("compare_visual_baselines", {
                "failing_invocation_id": "visual_fail_123",
                "baseline_invocation_id": "visual_pass_123",
                "build_target": "//ui:test"
            }),
            ("analyze_concurrency_drift", {"target_id": "//test:drift_example", "days_back": 14})
        ]
        
        for tool_name, args in tools_to_test:
            print(f"\n--- Testing {tool_name} ---")
            result = await agent.call_sponge_tool(tool_name, args)
            print(f"Result: {result}")
        
        print("\n" + "=" * 60)
        print("All tools tested successfully!")
        print("=" * 60)
        
    except Exception as e:
        logger.error(f"Tool demo failed: {e}")
    finally:
        await agent.disconnect()

async def main():
    """Run all demos"""
    print("Starting Test Failure Analysis Agent Demo")
    print("This demo will showcase the comprehensive test failure analysis system")
    
    # Run demos
    await demo_comprehensive_analysis()
    await asyncio.sleep(1)
    
    await demo_quick_analysis()
    await asyncio.sleep(1)
    
    await demo_visual_regression()
    await asyncio.sleep(1)
    
    await demo_all_sponge_tools()
    
    print("\n" + "=" * 80)
    print("ALL DEMOS COMPLETED SUCCESSFULLY!")
    print("The Test Failure Analysis Agent is ready for production use.")
    print("=" * 80)

if __name__ == "__main__":
    asyncio.run(main())