xiaozhi-esp32-server/scripts/westernization_rebase_check.sh
lapy cd83c805f5 chore(westernization): add rebase-verification tooling and docs
The October rebase silently shipped runtime-breaking merge artifacts that
neither the web build nor the test suites caught (blank models page,
ReferenceError on role open, broken provider management). Make every one
of those failure classes fail loudly and early:

- manager-web/scripts/integrity-check.js: AST pass (acorn + eslint-scope)
  for undefined identifiers (lost imports, dropped function params and
  const bindings), vue-template-compiler pass for mismatched tags, and a
  duplicate-options-key pass (double 'computed:' clobbering). Negative-
  tested against reproductions of all three shipped bugs.
- manager-web/scripts/check-i18n.js rewritten for the fork: base locale
  is en, locales discovered dynamically, plus a pass that fails when any
  $t('a.b') key referenced in src/ has no definition (upstream rebases
  kept adding views with keys never added downstream).
- scripts/westernization_rebase_check.sh: one-command gate chaining audit,
  integrity, i18n parity, snapshot/contract/unit tests and the production
  build; heavier Java/Python suites run only when toolchains exist.
- scripts/translate_han_llm.py: vendored from the one-off /tmp tool used
  for the translation sweep; repo-relative paths, endpoint/model via
  TRANSLATE_API/TRANSLATE_MODEL env, cache gitignored.
- CI: the Vue job now runs integrity-check, check:i18n, test:snapshot and
  test:contract before test:unit; new nightly Upstream Sync Check workflow
  dry-merges upstream/main into a throwaway branch and runs the same web
  gates so a breaking incoming merge alerts before a human sync.
- westernization.md: tooling table, five known merge-corruption failure
  classes with symptoms and repair strategy, translator usage, updated
  rebase order and good-outcome checklist.

acorn and eslint-scope are now explicit devDependencies.
2026-10-13 11:35:11 +01:00

73 lines
2.7 KiB
Bash
Executable file

#!/usr/bin/env bash
#
# Post-rebase verification gate for the westernized downstream branch.
#
# Run this after every upstream sync/rebase, BEFORE promoting the integration
# branch. It chains the checks that historically caught real regressions that
# `npm run build` and the unit suites do NOT catch on their own:
#
# * westernization audit (Han-script / path scan, exception zones)
# * manager-web integrity (undefined identifiers, template tag mismatches,
# duplicated Vue option keys -> the silent-blank-page class of bugs)
# * manager-web i18n parity + referenced-key coverage
# * manager-web snapshot/contract + unit tests
# * manager-web production build
#
# Subsystem suites that need heavier toolchains (Java, Python) are listed at
# the end but only run when their toolchain is present, so this script is safe
# to run in a web-only environment.
set -uo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$ROOT"
fail=0
run() {
local name="$1"; shift
echo
echo "==> $name"
if "$@"; then
echo "--- PASS: $name"
else
echo "--- FAIL: $name"
fail=1
fi
}
# 1. Westernization audit (Han-script, paths, generator bundle).
run "westernization audit" bash scripts/westernization_audit.sh
# 2..5 manager-web checks (need node_modules; install if missing).
if [ -d main/manager-web/node_modules ] || npm --prefix main/manager-web ci --no-audit --no-fund >/dev/null 2>&1; then
run "manager-web integrity" node main/manager-web/scripts/integrity-check.js
run "manager-web i18n parity" npm --prefix main/manager-web run --silent check:i18n
run "manager-web snapshot tests" npm --prefix main/manager-web run --silent test:snapshot
run "manager-web contract tests" npm --prefix main/manager-web run --silent test:contract
run "manager-web unit tests" npm --prefix main/manager-web run --silent test:unit
run "manager-web build" npm --prefix main/manager-web run --silent build
else
echo "!! manager-web: node/npm unavailable or install failed - SKIPPING web checks"
fail=1
fi
# 6. Optional heavier suites when toolchains exist.
if command -v mvn >/dev/null 2>&1; then
run "manager-api compile" mvn -q -f main/manager-api/pom.xml -DskipTests compile
else
echo "==> mvn not present - skipping manager-api compile"
fi
if command -v python3 >/dev/null 2>&1 && python3 -c 'import pytest' >/dev/null 2>&1; then
( cd main/xiaozhi-server && PYTHONPATH=. pytest tests/test_smoke.py -q ) \
&& echo "--- PASS: python smoke" || { echo "--- FAIL: python smoke"; fail=1; }
else
echo "==> pytest not present - skipping python smoke"
fi
echo
if [ "$fail" -eq 0 ]; then
echo "ALL REBASE CHECKS PASSED"
else
echo "REBASE CHECKS FAILED - fix the above before promoting the branch"
fi
exit "$fail"