Spaces:
Sleeping
Sleeping
Download test_failure_analysis/demo_test.py from VAH6002/Test_Failure_Analysis_Agent: direct link, hf CLI and curl.
- Browser
- Download file 6.45 kB
-
https://huggingface.co/spaces/VAH6002/Test_Failure_Analysis_Agent/resolve/main/test_failure_analysis/demo_test.py
- Command line
-
hf download hf://spaces/VAH6002/Test_Failure_Analysis_Agent/test_failure_analysis/demo_test.py
-
curl -L -o demo_test.py https://huggingface.co/spaces/VAH6002/Test_Failure_Analysis_Agent/resolve/main/test_failure_analysis/demo_test.py
6.45 kB
| """ | |
| 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()) |