#!/bin/bash # WeChat 本地闭环 — 一键测试脚本 # 在 Ubuntu proot 容器内执行 set -e SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" cd "$SCRIPT_DIR" echo "======================================================================" echo "WeChat 本地闭环 — 完整测试套件" echo "======================================================================" echo "" echo "测试环境: $(uname -a)" echo "当前目录: $SCRIPT_DIR" echo "当前用户: $(whoami)" echo "" # Color codes GREEN='\033[0;32m' RED='\033[0;31m' YELLOW='\033[1;33m' NC='\033[0m' # No Color PASS_COUNT=0 FAIL_COUNT=0 run_test() { local name="$1" local script="$2" echo "======================================================================" echo "[$name]" echo "======================================================================" if [ -f "$script" ]; then if python3 "$script"; then echo -e "${GREEN}[PASS]${NC} $name" ((PASS_COUNT++)) else echo -e "${RED}[FAIL]${NC} $name" ((FAIL_COUNT++)) fi else echo -e "${RED}[MISSING]${NC} $script not found" ((FAIL_COUNT++)) fi echo "" } # Run tests in order run_test "环境预检" "test_env.py" run_test "DB 轮询测试" "test_db_poll.py" run_test "发送消息测试" "test_send_msg.py" run_test "Termux API 测试" "test_termux_api.py" run_test "Hermes API 测试" "test_hermes_api.py" # Summary echo "======================================================================" echo "测试汇总" echo "======================================================================" echo -e "通过: ${GREEN}$PASS_COUNT${NC}" echo -e "失败: ${RED}$FAIL_COUNT${NC}" # Generate combined report echo "" echo "生成综合报告..." python3 -c " import json, os, glob reports = {} for f in sorted(glob.glob('test_report_*.json')): name = f.replace('test_report_', '').replace('.json', '') try: with open(f) as fp: reports[name] = json.load(fp) except Exception as e: reports[name] = {'error': str(e)} combined = { 'timestamp': __import__('subprocess').check_output(['date', '-Iseconds']).decode().strip(), 'hostname': __import__('socket').gethostname(), 'reports': reports, 'summary': { 'pass': $PASS_COUNT, 'fail': $FAIL_COUNT } } with open('test_report_combined.json', 'w') as f: json.dump(combined, f, indent=2, ensure_ascii=False) print('综合报告已保存: test_report_combined.json') " echo "" if [ $FAIL_COUNT -eq 0 ]; then echo -e "${GREEN}所有测试通过!可以启动守护进程:${NC}" echo " python3 hermes_wechat_daemon.py --once" echo " python3 hermes_wechat_daemon.py" exit 0 else echo -e "${YELLOW}有测试失败,请检查上述输出和 test_report_*.json 文件${NC}" exit 1 fi