Spaces:
Sleeping
Sleeping
Download test_failure_analysis/simple_demo.py from VAH6002/Test_Failure_Analysis_Agent: direct link, hf CLI and curl.
- Browser
- Download file 7.54 kB
-
https://huggingface.co/spaces/VAH6002/Test_Failure_Analysis_Agent/resolve/main/test_failure_analysis/simple_demo.py
- Command line
-
hf download hf://spaces/VAH6002/Test_Failure_Analysis_Agent/test_failure_analysis/simple_demo.py
-
curl -L -o simple_demo.py https://huggingface.co/spaces/VAH6002/Test_Failure_Analysis_Agent/resolve/main/test_failure_analysis/simple_demo.py
7.54 kB
| """ | |
| Simple demo to test the Sponge MCP Server tools directly | |
| """ | |
| import asyncio | |
| import json | |
| import sys | |
| import os | |
| # Add the current directory to Python path | |
| sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) | |
| from sponge_mcp_server import ( | |
| get_flaky_index, | |
| detect_regression_window, | |
| compare_log_diffs, | |
| locate_error_root, | |
| correlate_cross_service_logs, | |
| summarize_log_anomalies, | |
| fetch_stack_trace_context, | |
| inspect_visual_state, | |
| compare_visual_baselines, | |
| analyze_concurrency_drift | |
| ) | |
| def print_section(title): | |
| """Print a formatted section header""" | |
| print("\n" + "=" * 60) | |
| print(f" {title}") | |
| print("=" * 60) | |
| def print_result(tool_name, result): | |
| """Print tool result in a formatted way""" | |
| print(f"\n--- {tool_name} ---") | |
| print(json.dumps(result, indent=2)) | |
| async def demo_all_tools(): | |
| """Demo all Sponge tools directly""" | |
| print_section("SPONGE MCP SERVER TOOLS DEMO") | |
| # Test 1: Flaky Index | |
| print_result("get_flaky_index", | |
| get_flaky_index("//service/auth:flaky_login_test", 30)) | |
| # Test 2: Regression Window | |
| print_result("detect_regression_window", | |
| detect_regression_window("//service/payment:timeout_test", 7)) | |
| # Test 3: Log Diffs | |
| print_result("compare_log_diffs", | |
| compare_log_diffs("inv_failed_12345", "inv_passed_12344", "//service/auth:test")) | |
| # Test 4: Error Root | |
| print_result("locate_error_root", | |
| locate_error_root("inv_failed_12345", "//service/auth:test")) | |
| # Test 5: Cross-Service Logs | |
| print_result("correlate_cross_service_logs", | |
| correlate_cross_service_logs("inv_cross_12345", | |
| ["//service/auth:test", "//service/payment:test"], 300)) | |
| # Test 6: Log Anomalies | |
| print_result("summarize_log_anomalies", | |
| summarize_log_anomalies("inv_anomaly_12345", "//service/auth:test", 2)) | |
| # Test 7: Stack Trace Context | |
| print_result("fetch_stack_trace_context", | |
| fetch_stack_trace_context("inv_stack_12345", "//service/auth:test", 5)) | |
| # Test 8: Visual State | |
| print_result("inspect_visual_state", | |
| inspect_visual_state("inv_visual_12345", "//ui/checkout:test", "click_submit")) | |
| # Test 9: Visual Baselines | |
| print_result("compare_visual_baselines", | |
| compare_visual_baselines("inv_visual_fail_12345", "inv_visual_pass_12344", "//ui/checkout:test")) | |
| # Test 10: Concurrency Drift | |
| print_result("analyze_concurrency_drift", | |
| analyze_concurrency_drift("//service/database:connection_test", 30)) | |
| def demo_analysis_workflow(): | |
| """Demo a complete analysis workflow""" | |
| print_section("COMPLETE ANALYSIS WORKFLOW DEMO") | |
| target_id = "//service/auth:flaky_login_test" | |
| failing_invocation = "inv_failed_auth_12345" | |
| passing_invocation = "inv_passed_auth_12344" | |
| print(f"Analyzing test failure for: {target_id}") | |
| print(f"Failing invocation: {failing_invocation}") | |
| print(f"Passing invocation: {passing_invocation}") | |
| # Step 1: Check flakiness | |
| print("\nπ Step 1: Checking for flakiness...") | |
| flaky_result = get_flaky_index(target_id, 50) | |
| print(f"Flaky ratio: {flaky_result['flaky_ratio']:.2%}") | |
| print(f"Recommendation: {flaky_result['recommendation']}") | |
| # Step 2: Look for regression | |
| print("\nπ Step 2: Detecting regression window...") | |
| regression_result = detect_regression_window(target_id, 7) | |
| print(f"Analysis: {regression_result['analysis']}") | |
| # Step 3: Compare logs | |
| print("\nπ Step 3: Comparing logs...") | |
| log_diff_result = compare_log_diffs(failing_invocation, passing_invocation, target_id) | |
| print(f"Analysis: {log_diff_result['analysis']}") | |
| print(f"New errors found: {len(log_diff_result['new_errors'])}") | |
| # Step 4: Find error root | |
| print("\nπ― Step 4: Locating error root...") | |
| error_root_result = locate_error_root(failing_invocation, target_id) | |
| print(f"Error line: {error_root_result['error_line']}") | |
| # Step 5: Analyze anomalies | |
| print("\nπ Step 5: Summarizing anomalies...") | |
| anomaly_result = summarize_log_anomalies(failing_invocation, target_id, 2) | |
| print(f"Unique error types: {anomaly_result['total_error_types']}") | |
| # Step 6: Check for drift | |
| print("\nβ±οΈ Step 6: Analyzing performance drift...") | |
| drift_result = analyze_concurrency_drift(target_id, 30) | |
| drift_pct = drift_result['duration_trend']['drift_percentage'] | |
| print(f"Duration drift: {drift_pct:.1f}%") | |
| # Generate summary | |
| print_section("ANALYSIS SUMMARY") | |
| recommendations = [] | |
| confidence_factors = [] | |
| if flaky_result['flaky_ratio'] > 0.2: | |
| recommendations.append("π¨ High flakiness detected - consider stabilizing test") | |
| confidence_factors.append(0.8) | |
| if regression_result['confidence'] == 'high': | |
| recommendations.append(f"π Regression detected - review {regression_result.get('changelist', 'recent changes')}") | |
| confidence_factors.append(0.9) | |
| if log_diff_result['new_errors']: | |
| recommendations.append("π New errors found - investigate error patterns") | |
| confidence_factors.append(0.7) | |
| if error_root_result['error_line'] != "No error found after last INFO message": | |
| recommendations.append("π― Primary error location identified") | |
| confidence_factors.append(0.8) | |
| if abs(drift_pct) > 20: | |
| recommendations.append("β‘ Significant performance drift - environment may need refresh") | |
| confidence_factors.append(0.7) | |
| overall_confidence = sum(confidence_factors) / len(confidence_factors) if confidence_factors else 0.5 | |
| print(f"Overall Confidence Score: {overall_confidence:.2f}") | |
| print("\nRecommendations:") | |
| for i, rec in enumerate(recommendations, 1): | |
| print(f"{i}. {rec}") | |
| if not recommendations: | |
| print("β No major issues detected. Test appears to be functioning normally.") | |
| print("\nNext Steps:") | |
| if flaky_result['flaky_ratio'] > 0.3: | |
| print("1. Add test to flaky test list") | |
| print("2. Investigate root cause of flakiness") | |
| elif regression_result['confidence'] == 'high': | |
| print("1. Review recent code changes") | |
| print("2. Consider reverting problematic changes") | |
| else: | |
| print("1. Monitor test for additional failures") | |
| print("2. Consider adding more detailed logging") | |
| async def main(): | |
| """Run the complete demo""" | |
| print("π Starting Sponge MCP Server Demo") | |
| print("This demo showcases all 10 analysis tools and a complete workflow") | |
| # Demo individual tools | |
| await demo_all_tools() | |
| # Demo complete workflow | |
| demo_analysis_workflow() | |
| print_section("DEMO COMPLETED SUCCESSFULLY!") | |
| print("β All 10 Sponge tools are working correctly") | |
| print("β Complete analysis workflow demonstrated") | |
| print("β System is ready for production use") | |
| print("\nπ Next steps:") | |
| print("1. Integrate with your test infrastructure") | |
| print("2. Configure MCP server in your IDE") | |
| print("3. Start analyzing real test failures!") | |
| if __name__ == "__main__": | |
| asyncio.run(main()) |