Skip to content

ci(scripts): 002 記分守門 CI 端強制——base-ref 模式驗 PR 最終態 vs merge-base - #694

Merged
s123104 merged 3 commits into
experiment/ratewise-product-2026h2from
fix/661-002-ci-guard
Jul 8, 2026
Merged

ci(scripts): 002 記分守門 CI 端強制——base-ref 模式驗 PR 最終態 vs merge-base#694
s123104 merged 3 commits into
experiment/ratewise-product-2026h2from
fix/661-002-ci-guard

Conversation

@s123104

@s123104 s123104 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

摘要

Closes #661

  • scripts/verify-002-log.mjs 增設 --base-ref <ref> 入口:以 merge-base(<ref>, HEAD) 為基準版、HEAD(PR 最終態)為待驗版,與 pre-commit staged 語意共用同一 validate002 核心(無雙實作,僅內容取得方式不同)
  • .github/workflows/ci.yml Quality Checks 於 pnpm install 前新增 PR 專屬步驟 Verify 002 log (vs merge-base)(守門腳本零 npm 依賴,可搶先紅燈),堵 --no-verify 與 GitHub 網頁端 merge/squash 繞過本地 hook 的破口
  • vitest 補 6 條臨時 git repo 整合測試(真實 git 語意下驗 CLI 進入點)
  • root 顯式宣告 @types/node ^24scripts/tsconfig.json 覆寫 types 白名單:root 測試首次使用 node 內建模組,typed lint 需要型別

CI 語意選擇(issue 規格第 4 點)

  • CI 驗的是「PR 最終態(HEAD)vs merge-base」的整體一致性,不逐 commit:本 repo 以 squash 合併,中間 commit 不進入 base 歷史,逐 commit 驗證無意義;多 commit PR 只要最終 002 檔頭與新增條目差集對帳一致即綠(有整合測試鎖定此語意)
  • base 前進後仍以 merge-base 為基準(非 base tip),他人先合併的 002 條目不造成誤紅;若 PR 與 base 同時動 002,檔頭記分行必然衝突,交由 GitHub 衝突機制擋下(衝突 PR 不產生 merge ref、CI 不跑)
  • 驗證面向與 pre-commit 完全一致:條目差集計數、N = reward − penalty、總分鏈(基準總分 + N)、ID 全檔唯一、歷史條目不可刪;base-ref 模式額外把「整檔刪除」也列為必紅
  • 002 未變更的 PR 毫秒級跳過(實測約 40ms、僅 2 個 git 指令),正常 PR 零額外負擔

紅測證據(本地以 base-ref 模式重演,CI 同款指令)

構造「新增條目但檔頭計數未同步」的壞版,以 --no-verify 提交(模擬繞過 pre-commit):

=== 壞版已以 --no-verify 提交(模擬繞過 pre-commit)===
$ node scripts/verify-002-log.mjs --base-ref origin/experiment/ratewise-product-2026h2
002 記分守門失敗:
- 檔頭計數(reward 1、penalty 0、neutral 0)與本次新增條目(reward 2、penalty 0、neutral 0)不符
- 本次分數變化應為 2(reward - penalty),檔頭為 1
exit code: 1

對照組:

=== 本 PR 分支(002 正確 +203)===
002 記分守門通過
exit code: 0

=== 002 未變更情境(base HEAD、新腳本)===
002 記分守門跳過(docs/dev/002_development_reward_penalty_log.md 相對 merge-base eac973d9d8fe 無變更)
0.03s user 0.01s system 97% cpu 0.037 total
exit code: 0

驗收對照

  • 構造計數不符的 PR 在 CI 語意下必紅(上方重演證據+vitest 整合測試「構造計數不符的 PR 最終態必紅」)
  • 正常 PR 零額外負擔(002 未觸及即跳過,約 40ms)
  • 與 pre-commit 共用同一驗證核心 validate002(無雙實作)
  • workflow YAML 解析通過(python yaml.safe_load + js-yaml 雙驗)
  • pnpm vitest run scripts/__tests__/verify-002-log.test.ts 24 passed(18 既有+6 新 base-ref 整合測試)
  • pre-commit/pre-push 全過(push 已成功,typecheck+workspace tests+build:ratewise 全綠)
  • changeset 不需:純 CI/scripts/測試變更,無使用者可見行為;版本 SSOT 守門(pre-commit Step 5)通過、未要求 changeset
  • 002 一筆 reward(累計 +202 → +203

附註

  • @types/node 先前僅由各 app 宣告,root lockfile peer 漂移至 25.0.3;root 顯式宣告 ^24(對齊 engines ^24.0.0)後收斂為 24.10.1——pnpm-lock.yaml 的大量 diff 均為此 peer 版本替換,無任何依賴新增或升版
  • 整合測試曾在 hook 環境全紅:pre-push 跑 vitest 時 husky 注入 GIT_DIRGIT_INDEX_FILE,臨時 repo 的 git 子行程繼承後被導向父 repo;GIT_ENV 已剝除 GIT_* 前綴變數,hook 注入環境與一般環境雙重驗證各 24 passed

Made with Cursor

haotool and others added 2 commits July 8, 2026 22:03
- verify-002-log.mjs 增設 --base-ref <ref> 入口:以 merge-base(<ref>, HEAD) 為基準版、
  HEAD(PR 最終態)為待驗版,與 pre-commit staged 語意共用同一 validate002 核心(無雙實作)
- 002 未變更時毫秒級跳過(正常 PR 零額外負擔);整檔刪除必紅;merge-base 無法解析時明確失敗
- Quality Checks 於 install 前新增 PR 專屬步驟(零 npm 依賴,搶先紅燈),
  堵 --no-verify 與 GitHub 網頁端 merge/squash 繞過 pre-commit 的破口
- vitest 補 6 條臨時 git repo 整合測試:計數不符必紅、正確 append 綠燈、未變更跳過、
  多 commit 只驗最終態、base 前進後仍以 merge-base 為基準、刪檔必紅
- root 補宣告 @types/node ^24(對齊 engines)並讓 scripts/tsconfig.json 覆寫 types 白名單:
  root 測試首次使用 node 內建模組,typed lint 需要型別;lockfile peer 由漂移的 25.0.3 收斂為 24.10.1

測試:pnpm vitest run scripts/__tests__/verify-002-log.test.ts 24 passed、eslint 單檔通過、YAML 解析通過

Closes #661

Co-authored-by: Cursor <cursoragent@cursor.com>
- pre-push hook 跑 vitest 時 husky 注入 GIT_DIR/GIT_INDEX_FILE,臨時 repo 的
  git 子行程繼承後操作被導向父 repo,6 條 base-ref 整合測試在 hook 環境全紅
- GIT_ENV 改為先過濾所有 GIT_ 前綴變數再注入隔離設定;runGuard 子行程同步套用

測試:GIT_DIR/GIT_INDEX_FILE 注入環境與一般環境 vitest 各 24 passed、eslint 單檔通過

Co-authored-by: Cursor <cursoragent@cursor.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

⚠️ Deprecation Warning: The deny-licenses option is deprecated for possible removal in the next major release. For more information, see issue 997.

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

  • pnpm-lock.yaml

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

✅ SEO 審計通過!所有 2026 標準驗證項目都符合要求。

  • ✅ Sitemap 2026 標準
  • ✅ Breadcrumb Schema
  • ✅ JSON-LD 結構化數據
  • ✅ 內部連結結構

- scripts/tsconfig.json 加入 node 型別後 readFileSync 回傳型別由 error 轉為 string,
  stylisticTypeChecked 的 prefer-regexp-exec 開始生效,String#match 需改為 RegExp#exec
- 行為等價(單次比對、無 g flag),測試結果不變

測試:pnpm lint exit 0、vitest run lighthouse-production 6 passed

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

✅ SEO 審計通過!所有 2026 標準驗證項目都符合要求。

  • ✅ Sitemap 2026 標準
  • ✅ Breadcrumb Schema
  • ✅ JSON-LD 結構化數據
  • ✅ 內部連結結構

@s123104
s123104 merged commit bcd52c1 into experiment/ratewise-product-2026h2 Jul 8, 2026
20 of 21 checks passed
@s123104
s123104 deleted the fix/661-002-ci-guard branch July 8, 2026 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant