diff --git a/scripts/test-env/verify-functional.sh b/scripts/test-env/verify-functional.sh new file mode 100755 index 00000000..fdecd37a --- /dev/null +++ b/scripts/test-env/verify-functional.sh @@ -0,0 +1,65 @@ +#!/bin/bash +# verify-functional.sh — V2 全系统功能验证 +source "$(dirname "${BASH_SOURCE[0]}")/config/env.sh" + +log_info "=== V2 Functional Verification ===" +FAILED=0 + +verify() { + local desc="$1"; shift + if "$@"; then + log_ok " $desc" + else + log_error " $desc FAILED" + ((FAILED++)) + fi +} + +# F1: 电梯 V2 探活 +log_info "[F1] Elevator V2 health" +verify "elevator-v2 /actuator/health" \ + curl -sf "http://127.0.0.1:$PORT_ELEVATOR_V2/actuator/health" + +# F2: V1 vs V2 API 对拍 +log_info "[F2] V1/V2 API parity test" +cd "$REPO_ROOT/maven-cw-elevator-application/tools/elevator_api_parity" +verify "pytest elevator_api_parity" \ + pytest tests/test_smoke_catalog.py -q --tb=short + +# F3: V2.0.7 租户策略 — UC-01 基线 +log_info "[F3] Tenant visitor policy — UC-01 baseline" +RESP=$(curl -sf -X POST "http://127.0.0.1:$PORT_ELEVATOR_V2/elevator/person/add/visitor" \ + -H "Content-Type: application/json" \ + -d '{"personId":"test-person","visitorName":"test-visitor"}' 2>/dev/null || echo '{"code":-1}') +verify "UC-01 baseline (no policy)" echo "$RESP" | python3 -c "import sys,json; d=json.load(sys.stdin); assert d.get('code')!=76260532" + +# F4: V2.0.7 — UC-02 显式传 floorIds +log_info "[F4] Tenant visitor policy — UC-02 explicit floorIds" +RESP2=$(curl -sf -X POST "http://127.0.0.1:$PORT_ELEVATOR_V2/elevator/person/add/visitor" \ + -H "Content-Type: application/json" \ + -d '{"personId":"test-person","visitorName":"test-visitor2","floorIds":["zone-001"]}' 2>/dev/null || echo '{"code":-1}') +verify "UC-02 (explicit floorIds)" echo "$RESP2" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('code'))" + +# F7: CRK 联动 +log_info "[F7] CRK integration" +verify "crk-std /actuator/health" \ + curl -sf "http://127.0.0.1:$PORT_CRK_MGMT/actuator/health" + +# F8: 报警 Kafka — Consul 注册检查 +log_info "[F8] Alarm Consul registration" +verify "alarm registered in Consul" \ + curl -sf "http://$CONSUL_HOST:$CONSUL_PORT/v1/agent/services" | python3 -c "import sys,json; services=json.load(sys.stdin); assert any('alarm' in k.lower() for k in services)" + +# F9: Nginx 前端代理 +log_info "[F9] Frontend Nginx" +verify "nginx serves cwos-portal" \ + curl -sf -o /dev/null -w "%{http_code}" "http://$CONSUL_HOST:$PORT_NGINX/" | grep -q 200 + +# I1: MySQL 连通 +log_info "[I1] MySQL connectivity" +verify "mysql SELECT 1" \ + mysql -h "$MYSQL_HOST" -P "$MYSQL_PORT" -u "$MYSQL_USER" -p"$MYSQL_PASS" -e "SELECT 1" &>/dev/null + +echo "" +log_info "=== Verification Complete: $FAILED failures ===" +[[ $FAILED -eq 0 ]] && exit 0 || exit 1