#!/usr/bin/env python3 """Parse Scenario E2E test report JSON and output formatted Markdown summary.""" import json import os import sys from datetime import datetime def parse_report(path): with open(path) as f: return json.load(f) def format_scenario_report(data): if not data: return "No scenario results found." lines = [] # Summary table total = len(data) passed = sum(1 for r in data if r.get('status') == 'PASS') failed = total - passed lines.append(f"| Scenario | Status | Steps |") lines.append(f"|----------|--------|-------|") for r in data: scenario_id = r.get('scenario_id', 'unknown') scenario_name = r.get('scenario_name', '') status = r.get('status', 'UNKNOWN') steps_passed = r.get('steps_passed', 0) steps_total = r.get('steps_total', 0) status_icon = "✅" if status == "PASS" else "❌" lines.append(f"| {scenario_id} | {status_icon} {status} | {steps_passed}/{steps_total} |") lines.append("") # Failed scenario details failed_scenarios = [r for r in data if r.get('status') != 'PASS'] if failed_scenarios: lines.append("### Failed Scenarios") lines.append("") for r in failed_scenarios: scenario_id = r.get('scenario_id', 'unknown') scenario_name = r.get('scenario_name', '') lines.append(f"#### {scenario_id}: {scenario_name}") results = r.get('results', []) for step_result in results: if step_result.get('status') != 'PASS': step = step_result.get('step', 0) name = step_result.get('name', '') error = step_result.get('error') lines.append(f"- **Step {step}**: {name}") if error: # Truncate long errors if len(str(error)) > 150: error = str(error)[:150] + '...' lines.append(f" - Error: `{error}`") lines.append("") lines.append(f"_Report generated: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}_") return '\n'.join(lines) def main(): if len(sys.argv) > 1: report_path = sys.argv[1] if os.path.exists(report_path): data = parse_report(report_path) print(format_scenario_report(data)) else: print(f"Report file not found: {report_path}") return # Find latest report candidates = [ '.', os.path.expanduser('~/github/bingwang-MetaDrivenPlatform4AI/tests/e2e-api'), ] reports = [] for d in candidates: if not os.path.isdir(d): continue found = sorted([ f for f in os.listdir(d) if f.startswith('scenario-report-') and f.endswith('.json') ]) reports.extend([(d, f) for f in found]) if not reports: print("No scenario reports found!") sys.exit(1) reports.sort(key=lambda x: x[1]) report_dir, report_file = reports[-1] latest = os.path.join(report_dir, report_file) print(f"Reading: {latest}") data = parse_report(latest) print(format_scenario_report(data)) if __name__ == '__main__': main()