| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- #!/bin/bash
- # 全站验收:起服务 → 逐个页面真实加载 → 查正文/控制台错误/图片可达
- set -u
- PROJ=/opt/data/projects/hardware-lab
- SITE=$PROJ/site
- PORT=${PORT:-8599}
- CHROME=/tmp/pwbrowsers/chromium_headless_shell-1255/chrome-headless-shell-linux64/chrome-headless-shell
- cd "$SITE" || exit 1
- # 起服务(若未起)
- if ! curl -s -o /dev/null -m 2 "http://127.0.0.1:$PORT/index.html"; then
- (python3 -m http.server $PORT --bind 127.0.0.1 >/dev/null 2>&1 &) ; sleep 1.5
- fi
- IDS=$(ls data/products/*.json 2>/dev/null | grep -v INDEX | xargs -n1 basename | sed 's/.json//')
- ROUTES="#/ "
- for id in $IDS; do ROUTES="$ROUTES #/p/$id #/lab/$id"; done
- echo "=== 静态资源可达性 ==="
- for f in index.html app.js assets/theme.css assets/app.css \
- vendor/lit/lit/index.js vendor/babylon/babylon.js; do
- printf "%-32s " "$f"; curl -s -o /dev/null -w "%{http_code}\n" "http://127.0.0.1:$PORT/$f"
- done
- printf "%-32s " "data/products/INDEX.json"; curl -s -o /dev/null -w "%{http_code}\n" "http://127.0.0.1:$PORT/data/products/INDEX.json"
- echo
- echo "=== 主 KV 与配图 ==="
- for f in assets/kv/*.png assets/detail/*.png; do
- [ -f "$SITE/$f" ] || continue
- printf "%-46s " "$(basename $f)"; curl -s -o /dev/null -w "%{http_code}\n" "http://127.0.0.1:$PORT/$f"
- done | awk '{print} $2!=200{bad++} END{if(bad)print " ✗ 不可达 " bad " 个"}'
- echo
- echo "=== 页面渲染检查 ==="
- FAILED=0
- printf "%-26s %-8s %-8s %s\n" "ROUTE" "正文长度" "错误数" "判定"
- for r in $ROUTES; do
- OUT=/tmp/route-dom.html; ERR=/tmp/route-err.log
- timeout 45 "$CHROME" --no-sandbox --disable-gpu --disable-dev-shm-usage \
- --headless --use-gl=swiftshader --enable-unsafe-swiftshader --virtual-time-budget=12000 --enable-logging=stderr --v=0 \
- --dump-dom "http://127.0.0.1:$PORT/index.html$r" > "$OUT" 2>"$ERR"
- LEN=$(python3 -c "
- import re
- h=open('$OUT',encoding='utf-8',errors='replace').read()
- t=re.sub(r'<(script|style).*?</\1>','',h,flags=re.S)
- t=re.sub(r'<[^>]+>',' ',t); t=re.sub(r'\s+',' ',t).strip()
- print(len(t))")
- ERRS=$(grep -i -E "Uncaught|SyntaxError|TypeError|ReferenceError|Failed to (load|fetch)|404" "$ERR" \
- | grep -v -i -E "gpu|vulkan|dbus|font|sandbox|DevTools|GCM" | wc -l)
- if [ "$LEN" -lt 200 ] || [ "$ERRS" -gt 0 ]; then V="✗"; FAILED=$((FAILED+1)); else V="✓"; fi
- printf "%-26s %-8s %-8s %s\n" "$r" "$LEN" "$ERRS" "$V"
- done
- echo
- echo "=== 结论:$FAILED 个路由未通过 ==="
- exit $FAILED
|