2026-12-04 08:37:28 -08:00
#!/usr/bin/env bash
# 一键验证:黄金对照、旧库兼容、浏览器流程;--with-unit 追加全部单元测试。
2026-12-04 19:15:24 -08:00
# 用法:bash e2e/verify.sh [--with-unit] [--skip-browser] [--with-next]
# --with-next:追加新版界面(/next/)的新旧开单对照与浏览器检查(使用已提交的 web/dist)。
2026-12-04 08:37:28 -08:00
# 首次运行浏览器检查前:(cd e2e && PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm ci)
set -u
HERE = " $( cd " $( dirname " $0 " ) " && pwd ) " ; APP = " $( dirname " $HERE " ) " ; cd " $APP "
2026-12-04 19:15:24 -08:00
WITH_UNIT = 0; SKIP_BROWSER = 0; WITH_NEXT = 0
for arg in " $@ " ; do case " $arg " in --with-unit) WITH_UNIT = 1;; --skip-browser) SKIP_BROWSER = 1;; --with-next) WITH_NEXT = 1;; *) echo "未知参数: $arg " ; exit 2;; esac ; done
2026-12-05 09:11:55 -08:00
for flag in CONTROLS_TRACE PWDEBUG GOLDEN_SKIP GOLDEN_PROBE PARITY_SELF_TEST E2E_MUTATION_REQUIRE; do
if [ -n " ${ !flag :- } " ] ; then
echo "正式验收检测到调试环境变量 ${ flag } 。请清除该变量,或单独运行对应专项排查。" >& 2
exit 2
fi
done
if [ " $WITH_NEXT " = 1 ] && [ " $SKIP_BROWSER " = 1 ] ; then
echo "--with-next 须执行冻结的旧版浏览器对照,请移除 --skip-browser。" >& 2
exit 2
fi
declare -a NAMES RESULTS TIMES expected expected_commands
FAILED = 0; stage_index = 0
check_next_build() (
cd web && ./node_modules/.bin/vite build --logLevel error &&
git diff --quiet --exit-code -- dist && test -z " $( git ls-files --others --exclude-standard -- dist) "
)
# 独立冻结入口命令及其参数。在调用前核对,避免调试命令写入正式验收证据。
freeze_stage() {
expected +=( " $1 " ) ; shift
local signature
printf -v signature '%q ' " $@ "
expected_commands +=( " $signature " )
}
if [ " $WITH_NEXT " = 1 ] ; then
freeze_stage "黄金对照(golden) " node e2e/golden.js --check
freeze_stage "旧库兼容(legacy) " node e2e/legacy-db.js --check
freeze_stage "浏览器流程(browser) " node e2e/browser.mjs --check
freeze_stage "新版严格类型与覆盖" npm --prefix web run typecheck
freeze_stage "新版代码检查" npm --prefix web run lint
freeze_stage "新版前端测试" npm --prefix web test
freeze_stage "新版构建与提交一致(web/dist) " check_next_build
freeze_stage "新旧开单对照(parity) " node e2e/parity-create-order.mjs
freeze_stage "业务页面与旧版对照(parity-pages) " node e2e/parity-pages.mjs
freeze_stage "新版界面浏览器(browser-next) " node e2e/browser-next.mjs
freeze_stage "表单原始输入与键盘导航" node e2e/parity-controls.mjs
freeze_stage "登录与开单冷启动预算" node e2e/startup-budget.mjs
freeze_stage "历史回收和寄存本地草稿" node e2e/recovery-local-drafts.mjs
freeze_stage "回收更正与寄存确认对照" node e2e/parity-recovery-confirmations.mjs
freeze_stage "逐笔写入及路由覆盖" node e2e/parity-writes.mjs
freeze_stage "金额差错负控" node e2e/parity-writes.mjs --only settings --prove
[ " $WITH_UNIT " = 1 ] && freeze_stage "单元测试(node --test test/) " node --test test/
fi
run() {
local name = " $1 " ; shift
local signature start = $SECONDS result
printf -v signature '%q ' " $@ "
echo; echo "════ $name ════"
if [ " $WITH_NEXT " = 1 ] && {
[ " $name " != " ${ expected [ $stage_index ] :- } " ] || [ " $signature " != " ${ expected_commands [ $stage_index ] :- } " ]
} ; then
printf '正式验收第 %d 项应为「%s」 %s,拒绝执行「%s」 %s\n' " $(( stage_index + 1 )) " \
" ${ expected [ $stage_index ] :- 无此项 } " " ${ expected_commands [ $stage_index ] :- } " " $name " " $signature " >& 2
result = FAIL
elif " $@ " ; then result = PASS
else result = FAIL
fi
[ " $result " = FAIL ] && FAILED = 1
NAMES +=( " $name " ) ; RESULTS +=( " $result " ) ; TIMES +=( " $(( SECONDS-start)) s" )
stage_index = $(( stage_index + 1 ))
}
2026-12-04 08:37:28 -08:00
run "黄金对照(golden) " node e2e/golden.js --check
run "旧库兼容(legacy) " node e2e/legacy-db.js --check
if [ " $SKIP_BROWSER " = 0 ] ; then
if [ -d " $HERE /node_modules/playwright" ] ; then run "浏览器流程(browser) " node e2e/browser.mjs --check
2026-12-05 09:11:55 -08:00
else echo "缺少 e2e/node_modules/playwright,请先执行:(cd e2e && PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm ci)" ; NAMES +=( "浏览器流程(browser) " ) ; RESULTS +=( "FAIL" ) ; TIMES +=( "0s" ) ; FAILED = 1; stage_index = $(( stage_index + 1 )) ; fi
2026-12-04 08:37:28 -08:00
fi
2026-12-04 19:15:24 -08:00
if [ " $WITH_NEXT " = 1 ] ; then
2026-12-05 02:33:01 -08:00
reference_tmp = $( mktemp -d) || exit 1
trap 'rm -rf "$reference_tmp"' EXIT
LEDGER_REFERENCE_APP = $( node e2e/lib/write-reference.mjs " $reference_tmp " ) || exit 1
export LEDGER_REFERENCE_APP
2026-12-04 19:15:24 -08:00
# 已提交的 web/dist 必须与源码重新构建的结果一致(需先在 web/ 下 npm ci)。
2026-12-05 08:00:41 -08:00
run "新版严格类型与覆盖" npm --prefix web run typecheck
run "新版代码检查" npm --prefix web run lint
run "新版前端测试" npm --prefix web test
2026-12-05 09:11:55 -08:00
run "新版构建与提交一致(web/dist) " check_next_build
2026-12-04 19:15:24 -08:00
run "新旧开单对照(parity) " node e2e/parity-create-order.mjs
2026-12-04 22:43:40 -08:00
run "业务页面与旧版对照(parity-pages) " node e2e/parity-pages.mjs
2026-12-04 19:15:24 -08:00
run "新版界面浏览器(browser-next) " node e2e/browser-next.mjs
2026-12-05 08:15:19 -08:00
run "表单原始输入与键盘导航" node e2e/parity-controls.mjs
2026-12-05 08:38:39 -08:00
run "登录与开单冷启动预算" node e2e/startup-budget.mjs
2026-12-05 08:14:03 -08:00
run "历史回收和寄存本地草稿" node e2e/recovery-local-drafts.mjs
2026-12-05 09:11:55 -08:00
run "回收更正与寄存确认对照" node e2e/parity-recovery-confirmations.mjs
2026-12-05 02:33:01 -08:00
run "逐笔写入及路由覆盖" node e2e/parity-writes.mjs
run "金额差错负控" node e2e/parity-writes.mjs --only settings --prove
2026-12-04 19:15:24 -08:00
fi
2026-12-04 08:37:28 -08:00
[ " $WITH_UNIT " = 1 ] && run "单元测试(node --test test/) " node --test test/
2026-12-05 09:11:55 -08:00
if [ " $WITH_NEXT " = 1 ] && [ " $stage_index " -ne " ${# expected [@] } " ] ; then
echo "正式验收应执行 ${# expected [@] } 项,实际登记 $stage_index 项。" >& 2
FAILED = 1
fi
2026-12-04 08:37:28 -08:00
echo; echo "════ 汇总 ════"
for i in " ${ !NAMES[@] } " ; do printf '%-6s %-28s %s\n' " ${ RESULTS [ $i ] } " " ${ NAMES [ $i ] } " " ${ TIMES [ $i ] } " ; done
[ " $FAILED " = 0 ] && echo "全部通过" || echo "存在失败"
exit " $FAILED "