#!/usr/bin/env bash # 完整接口测试:V1/V2 单机冒烟 + 双端对拍 + 套件总览 Markdown。 # 前置:两 JAR 已分别启动(默认 http://127.0.0.1:18080 为 V1、18081 为 V2),且配置同一数据源/Redis。 # 用法:在 maven-cw-elevator-application 目录执行 ./scripts/run_full_elevator_api_suite.sh set -euo pipefail REPO="$(cd "$(dirname "$0")/.." && pwd)" TOOL="${REPO}/tools/elevator_api_parity" MARKER="${TOOL}/.suite_run_marker" export PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 export PIP_DISABLE_PIP_VERSION_CHECK=1 export ELEVATOR_BASE_OLD="${ELEVATOR_BASE_OLD:-http://127.0.0.1:18080}" export ELEVATOR_BASE_NEW="${ELEVATOR_BASE_NEW:-http://127.0.0.1:18081}" cd "$TOOL" python3 -m pip install -q -r requirements.txt 2>/dev/null || true touch "$MARKER" # -rs 在结束时打印 skip 原因;s=skip 通常表示目标端口无服务或 /actuator/health 无 200 PTF="-q -rs --tb=line" echo "==> 单元(compare 逻辑)" python3 -m pytest tests/test_unit_compare.py -q --tb=short echo "==> 冒烟 V1 ($ELEVATOR_BASE_OLD) [需该地址可访问 /actuator/health 等健康端点]" python3 -m pytest tests/test_smoke_catalog.py -m smoke \ --smoke-base="$ELEVATOR_BASE_OLD" --smoke-label=v1_legacy $PTF || true echo "==> 冒烟 V2 ($ELEVATOR_BASE_NEW) [需该地址可访问 /actuator/health 等健康端点]" python3 -m pytest tests/test_smoke_catalog.py -m smoke \ --smoke-base="$ELEVATOR_BASE_NEW" --smoke-label=v2_build $PTF || true echo "==> 横向对拍(两实例均需通过健康探针)" python3 -m pytest tests/test_parity_endpoints.py -m live $PTF \ --base-old="$ELEVATOR_BASE_OLD" --base-new="$ELEVATOR_BASE_NEW" || true SUITE_TS="$(date +%Y%m%d-%H%M%S)" _pick_newer() { local pattern="$1" local f="" for f in $(ls -t "${TOOL}/report"/${pattern} 2>/dev/null); do if [[ -f "$f" && "$f" -nt "$MARKER" ]]; then echo "$f"; return; fi done } SMOKE_V1="$(_pick_newer 'smoke-v1_legacy-*.md')" SMOKE_V2="$(_pick_newer 'smoke-v2_build-*.md')" PARITY="$(_pick_newer 'parity-*.md')" OUT="${TOOL}/report/SUITE-${SUITE_TS}.md" python3 report/generate_suite_summary.py --out "$OUT" \ --catalog "${TOOL}/api_catalog.json" \ ${PARITY:+--parity "$PARITY"} \ ${SMOKE_V1:+--smoke-v1 "$SMOKE_V1"} \ ${SMOKE_V2:+--smoke-v2 "$SMOKE_V2"} echo "==> 套件总览: $OUT" if [[ -z "$SMOKE_V1" && -z "$SMOKE_V2" && -z "$PARITY" ]]; then echo "==> 提示: 未生成 smoke/parity 子报告(多为本机未起 JAR 或健康检查未通过)。" echo " 先起两进程: java -jar V1.jar --server.port=18080 --spring.config.location=... 与 V2 用 18081" echo " 快速探活: curl -s -o /dev/null -w '%{http_code}' $ELEVATOR_BASE_OLD/actuator/health" fi rm -f "$MARKER"