80 lines
4.1 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# ref-r1-runbook.sh — 参考件轮 1 ④评估段编排(仅 mini-desktop;主会话经 ssh bash -s 投递)
# 形状沿 run-integration.sh:不跑 -e 全局(探活/清理容错),关键门各自判退出码;长驻进程一律 systemd-run。
set -u
SHA="${1:?需要精确 commit SHA}"
SCRATCH="$HOME/t1ba-ref-r1"
RT="$SCRATCH/game-runtime"
EV="$RT/games/wanglanmei-ref/evidence/round-1"
PORT=4320
CDP_PORT=9222
U_SERVE=t1ba-ref-r1-serve
U_CHROME=t1ba-ref-r1-chrome
echo "=== [0] 环境与净场 ==="
hostname; node --version
systemctl stop "$U_SERVE" "$U_CHROME" 2>/dev/null; systemctl reset-failed "$U_SERVE" "$U_CHROME" 2>/dev/null
rm -rf "$SCRATCH"
echo "=== [1] scratch 检出精确 SHA ==="
git clone -q --depth 50 --branch dev/2.0.0 ssh://git@101.200.34.71:2222/zizi-al/games-development-ai.git "$SCRATCH" || { echo "GATE: CLONE FAIL"; exit 1; }
git -C "$SCRATCH" checkout -q "$SHA" || { echo "GATE: SHA FAIL"; exit 1; }
echo "checkout=$(git -C "$SCRATCH" rev-parse --short HEAD)"
echo "=== [2] 依赖+构建(esbuild 锁参) ==="
cd "$RT" || exit 1
npm init -y >/dev/null 2>&1
npm i --no-audit --no-fund esbuild ws >/dev/null 2>&1 || { echo "GATE: NPM FAIL"; exit 1; }
node scripts/build.mjs games/wanglanmei-ref/entry.js games/wanglanmei-ref/dist/ref-bundle.js --global-name=WanglanmeiRef || { echo "GATE: BUILD FAIL"; exit 1; }
ls -l games/wanglanmei-ref/dist/ref-bundle.js
echo "GATE: BUILD OK"
echo "=== [3] IP gate(产物+对外文本,码位构造防自触发) ==="
node -e "
const fs=require('fs');const b=String.fromCharCode(0x738b,0x84dd,0x8393);let bad=false;
for(const f of ['games/wanglanmei-ref/dist/ref-bundle.js','games/wanglanmei-ref/index.html','games/wanglanmei-ref/assets/manifest.json']){
const hit=fs.readFileSync(f,'utf8').includes(b);console.log(f, hit?'VIOLATION':'clean'); if(hit) bad=true;
}
process.exit(bad?1:0)" || { echo "GATE: IPGATE FAIL"; exit 1; }
echo "GATE: IPGATE OK"
echo "=== [4] 起 serve+chrome(systemd-run durable 单元) ==="
mkdir -p "$EV"
systemd-run --unit="$U_SERVE" --setenv=NODE_NO_WARNINGS=1 \
/usr/bin/env node "$RT/test/harness/static-serve.cjs" "$RT/games/wanglanmei-ref" "$PORT" >/dev/null 2>&1
CHROME="$(command -v google-chrome google-chrome-stable chromium chromium-browser 2>/dev/null | head -1)"
[ -n "$CHROME" ] || { echo "GATE: NO CHROME"; exit 1; }
systemd-run --unit="$U_CHROME" "$CHROME" --headless=new --no-sandbox --no-zygote \
--remote-debugging-port=$CDP_PORT --remote-allow-origins='*' --autoplay-policy=no-user-gesture-required \
about:blank >/dev/null 2>&1
echo "units: $U_SERVE / $U_CHROME ($CHROME)"
echo "=== [5] 探活门(就绪等待→serve 5×6s 持续在线 + CDP 就绪) ==="
# 就绪等待:listen 绑定有毫秒级延迟,首拍 curl 会竞速误杀(2026-06-12 run3 实翻)——先容忍 10×0.5s。
READY=0
for i in $(seq 1 10); do curl -sf "http://127.0.0.1:$PORT/" >/dev/null && { READY=1; break; }; sleep 0.5; done
[ "$READY" = 1 ] || { echo "GATE: SERVE NEVER READY(5s)"; journalctl -u "$U_SERVE" --no-pager | tail -10; systemctl stop "$U_SERVE" "$U_CHROME" 2>/dev/null; exit 1; }
ALIVE=1
for i in 1 2 3 4 5; do
curl -sf "http://127.0.0.1:$PORT/" >/dev/null || { ALIVE=0; echo "probe $i: serve DOWN"; break; }
echo "probe $i: serve OK"; [ "$i" -lt 5 ] && sleep 6
done
[ "$ALIVE" = 1 ] || { echo "GATE: SERVE FAIL"; systemctl stop "$U_SERVE" "$U_CHROME" 2>/dev/null; exit 1; }
CDPOK=0
for i in 1 2 3 4 5 6 7 8 9 10; do curl -sf "http://127.0.0.1:$CDP_PORT/json/version" >/dev/null && { CDPOK=1; break; }; sleep 2; done
[ "$CDPOK" = 1 ] || { echo "GATE: CDP FAIL"; systemctl stop "$U_SERVE" "$U_CHROME" 2>/dev/null; exit 1; }
echo "GATE: SERVE+CDP OK"
echo "=== [6] e2e driver(四件套取证) ==="
node games/wanglanmei-ref/test/e2e-input.cdp.cjs "http://127.0.0.1:$PORT" "$EV" 2>&1 | tee "$EV/driver-console.log"
RC=${PIPESTATUS[0]}
echo "driver rc=$RC"
echo "=== [7] 轮终收尾(停 unit+日志归档,不留孤儿) ==="
journalctl -u "$U_SERVE" -u "$U_CHROME" --no-pager 2>/dev/null | tail -120 > "$EV/serve-units.log"
systemctl stop "$U_SERVE" "$U_CHROME" 2>/dev/null
systemctl reset-failed "$U_SERVE" "$U_CHROME" 2>/dev/null
ls -la "$EV"
echo "=== RUNBOOK DONE rc=$RC ==="
exit "$RC"