#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""检查执行计划状态"""
import sys
import time
import httpx

EXEC_ID = sys.argv[1] if len(sys.argv) > 1 else ""
WAIT = int(sys.argv[2]) if len(sys.argv) > 2 else 0
BASE_URL = "http://localhost:8001"

if WAIT > 0:
    print(f"等待 {WAIT} 秒...")
    time.sleep(WAIT)

if EXEC_ID:
    with httpx.Client(timeout=30) as client:
        r = client.get(f"{BASE_URL}/api/executions/{EXEC_ID}")
        if r.status_code == 200:
            d = r.json()
            print(f"状态: {d['status']}")
            print(f"进度: {d['passed'] + d['failed']}/{d['total_cases']}")
            print(f"通过: {d['passed']}, 失败: {d['failed']}, 跳过: {d.get('skipped', 0)}")
            if d['status'] == 'completed':
                print(f"通过率: {d['pass_rate']*100:.1f}%")
