Skip to content

test(ensemble-code-review): extract diff recipe to bin/pai-build-diff + bats + CI#15

Merged
kiki830621 merged 1 commit into
mainfrom
test/diff-recipe-extraction
Jun 3, 2026
Merged

test(ensemble-code-review): extract diff recipe to bin/pai-build-diff + bats + CI#15
kiki830621 merged 1 commit into
mainfrom
test/diff-recipe-extraction

Conversation

@kiki830621

Copy link
Copy Markdown
Contributor

摘要

ensemble-code-review diff 模式那段「經過 3 輪 self-dogfood 硬化」的 inline bash recipe 抽成 version-pinned shipped script + 自動化測試,從「每次改都人工 re-audit」轉成「CI 自動守住」。對應使用者需求 task 1(轉自動化測試,複利 > 人工審)。

改了什麼

新增 內容
bin/pai-build-diff diff 模式建構器(單一真相源)。5 模式 --diff/--base/--since/--commits/--pr;退出碼契約 0=有 diff/3=無變更(良性)/1=錯誤。封裝全部硬化:ref/N 驗證(防 injection + dashed-ref)、untracked symlink no-follow / FIFO no-hang / 換行檔名 C-quote、--commits N≥TOT 用 empty-tree base、git/gh exit-code 檢查。
test/pai-build-diff.bats 25 個 bats regression,把 3 輪人工 re-audit 抓到的 bug 全部固化。
test/run.sh + test/README.md 本地一鍵 shellcheck + bats。
.github/workflows/test.yml CI:每次 push / PR 自動跑 shellcheck + bats。

SKILL.md 的 inline recipe(~38 行)→ 改成呼叫 script(~14 行)+ 一段「要改邏輯就改 script + 測試,別 inline 重寫」的註記。單一真相源

extraction 過程 dogfood 抓到的 bug

抽 script 時順手 dogfood,抓到一個真 bug:未知 mode 的錯誤訊息 未知 MODE: $MODE(限... —— $MODE 緊貼全形 (UTF-8 三位元組),bash 把首位元組吞進變數名 → set -u 誤報 unbound variable。改 ${MODE} 明確界定,並加 regression 測試(case 23)。

設計取捨

  • 為何 script 用「內部 buffer + stdout」而非寫進 skill 的 DIFF_FILE:script 變成純 filter (MODE, REF/N) → stdout,bats 直接 run; assert_output 捕捉。skill 仍擁有自己的 DIFF_FILE(async reviewer agents 讀的那個 + Phase 4.5 cleanup 不受影響)—— 兩個不同檔、不同 lifecycle,所以 script 內用 trap EXIT 清理是安全的(同步、無 async reader)。
  • -C <dir> flag:讓 bats 指向 fixture repo 而不需 cd;skill 不帶則用 cwd。

驗證

$ ./test/run.sh
── shellcheck bin/pai-build-diff ──        ✓ clean
── bats test/ ──                            ok 1..25
✓ 全部通過

新 recipe 也用 fixture 端到端模擬過:--diff 無 ARG→rc=0、--base 帶 ARG→rc=0、壞 ref→rc=1 停、乾淨樹→rc=3 停。

版本

2.13.22.14.0(plugin.json + marketplace.json 同步)。CHANGELOG 已補 [2.14.0]

Scope note

這是使用者要求的兩件事中的 task 1。task 2(dogfood 另外三個 skill + 共用 harness)將另開 PR。

… + bats + CI

把 3 輪 self-dogfood 硬化的 diff 模式 inline recipe 抽成 version-pinned
shipped script,改成「單一真相源 + 自動化測試」取代人工 re-audit。

新增:
- bin/pai-build-diff — diff 模式建構器(5 模式 + 退出碼契約 0/3/1)。
  封裝 ref/N 驗證、untracked symlink/FIFO/換行檔名安全、empty-tree base、
  git/gh exit-code 檢查。SKILL.md 改成呼叫它(${CLAUDE_PLUGIN_ROOT}/bin/...)。
- test/pai-build-diff.bats — 25 個 regression(含 3 輪抓到的全部 bug)。
- test/run.sh + test/README.md — 本地一鍵 shellcheck + bats。
- .github/workflows/test.yml — CI 每次 push/PR 自動跑。

修正(extraction dogfood 抓到):
- 未知 mode 訊息 $MODE 緊貼全形( 被 set -u 誤判 unbound variable
  → 改 ${MODE}。已加 regression。

bump 2.13.2 → 2.14.0(plugin.json + marketplace.json)。
@kiki830621 kiki830621 merged commit 9421411 into main Jun 3, 2026
1 check passed
@kiki830621 kiki830621 deleted the test/diff-recipe-extraction branch June 3, 2026 02:05
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