build(quality): P3 — real pre-commit gate (tsc+vitest+smoke); ceremony gate → advisory

Root-cause fix (audit §12.4.1): the only pre-commit gate was _gate_webapi,
which greps comment provenance / webapi ref-rate but NEVER runs tsc or vitest
→ 48 type errors + 20 failing tests could merge under an all-green gate (false green).

- scripts/quality-gate.sh: [1] tsc --noEmit (block) [2] vitest run tests/unit (block)
  [3] backend smoke (advisory local / mandatory CI). No ceremony (no magic-string grep).
  git rev-parse for root (no hardcoded /home/ubuntu).
- scripts/githooks/pre-commit (version-controlled): runs quality-gate (blocking),
  then _gate_webapi as advisory (never blocks).
- scripts/install-hooks.sh: git config core.hooksPath scripts/githooks
- README §232: gate now enforced, tsc rule 靠自觉 → 门强制

blindspot_guards.test.ts quarantined via --exclude (12 fails = registry drift,
PLAN §P2.5) — loudly documented, not silently hidden.

Verified: NEGATIVE test — injected a type error, gate BLOCKED the commit (exit 2);
removed → tsc 0, gate passes. Gate passes its own gate.

Co-Authored-By: Claude <[email protected]>
This commit is contained in:
sswandClaude committed 2026-07-24 09:58:07 +08:00
1 parent fc16d93114
commit 21eb5520c7
4 files changed
+94 -1

No files matched your search

+38
View File
@@ -0,0 +1,38 @@
#!/bin/sh
# dacli pre-commit hook (P3, 2026-07-24) — 版本受控, 团队共用
#
# 激活: git config core.hooksPath scripts/githooks (或跑 scripts/install-hooks.sh)
#
# 顺序:
# 1. 真质量门 scripts/quality-gate.sh (tsc+vitest+smoke) → FAIL 阻塞 commit
# 2. 仪式门 _gate_webapi (webapi 引用率报告) → 降级 advisory, 永不阻塞
#
# 病根修复 (audit 2026-07-23 §12.4): 之前唯一门是 _gate_webapi, 只查注释出处/引用率,
# 从不跑 tsc/vitest → 48 类型错误 + 20 失败单测能在"全绿"下合入 (假绿).
# 现在编译+单测是硬门, 出处报告只作参考.
ROOT="$(git rev-parse --show-toplevel)"
# 只在 dacli 仓库内跑 (在其他仓库提交时跳过)
if [ ! -f "$ROOT/scripts/quality-gate.sh" ]; then
exit 0
fi
# === 1. 真质量门 (阻塞) ===
sh "$ROOT/scripts/quality-gate.sh"
GATE_EXIT=$?
if [ $GATE_EXIT -ne 0 ]; then
echo ""
echo "❌ dacli 质量门 FAIL (exit=$GATE_EXIT), commit 阻塞"
echo " 修复 tsc/vitest 错误后重试, 或紧急绕过: DACLI_SKIP_GATE=1 git commit ..."
exit 1
fi
# === 2. 仪式门 _gate_webapi (advisory, 不阻塞) ===
if [ -f "$ROOT/src/commands/_gate_webapi.ts" ]; then
echo ""
echo "ℹ️ webapi 镜像引用率报告 (advisory, 不阻塞):"
npx tsx "$ROOT/src/commands/_gate_webapi.ts" 2>/dev/null || true
fi
exit 0