Compare commits
53
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b60f50f2b4 | ||
|
|
43ad2b56d2 | ||
|
|
8e18bbacc2 | ||
|
|
1f012c6cfb | ||
|
|
76617dd9dc | ||
|
|
216bc39255 | ||
|
|
75ca8cdb83 | ||
|
|
aaf2e484d5 | ||
|
|
55da29a86f | ||
|
|
d424447d15 | ||
|
|
9d05af647b | ||
|
|
941d763129 | ||
|
|
9e7f8a2a0a | ||
|
|
8b50a0d643 | ||
|
|
555611db07 | ||
|
|
24b248884f | ||
|
|
e0ae6f886f | ||
|
|
55b349da07 | ||
|
|
6a26984bee | ||
|
|
a8561b4257 | ||
|
|
5ac73f290e | ||
|
|
05153bba8e | ||
|
|
d7cecc8fa8 | ||
|
|
0c29daa014 | ||
|
|
d8dd5ce92e | ||
|
|
cc9c8afed7 | ||
|
|
0c108ab7f9 | ||
|
|
83dd56f37f | ||
|
|
d354f30c27 | ||
|
|
b5264141c4 | ||
|
|
4b779ee00b | ||
|
|
deb20bb078 | ||
|
|
c63b1a6da2 | ||
|
|
ed883f6f20 | ||
|
|
3ef8a30291 | ||
|
|
be72aa0944 | ||
|
|
b277ff2f7c | ||
|
|
20a2b57998 | ||
|
|
05178be520 | ||
|
|
9e6e8bb793 | ||
|
|
321a717f91 | ||
|
|
36bf2d8644 | ||
|
|
85235e43a4 | ||
|
|
491c170d36 | ||
|
|
afed9a3cce | ||
|
|
71b93a885a | ||
|
|
7b5c7c3e4f | ||
|
|
7823718ff4 | ||
|
|
4c2b6d4265 | ||
|
|
dcd3e931f4 | ||
|
|
0a51affa72 | ||
|
|
f341dc6e07 | ||
|
|
8349fe8b71 |
File diff suppressed because it is too large
Load Diff
@@ -8,19 +8,6 @@
|
|||||||
"model": "(工具預設)"
|
"model": "(工具預設)"
|
||||||
},
|
},
|
||||||
"findings": [
|
"findings": [
|
||||||
{
|
|
||||||
"id": "F001",
|
|
||||||
"reviewer": "Leo",
|
|
||||||
"focus": "maintainability",
|
|
||||||
"badge": "🧰",
|
|
||||||
"severity": "警告",
|
|
||||||
"file": "src/index.js",
|
|
||||||
"startLine": 210,
|
|
||||||
"endLine": 224,
|
|
||||||
"problem": "`ensureIssueCreated` 同時建立 issue、修改外層 `issue` 狀態、逐筆清空 `issueBuffer`,但整段流程沒有可重入或冪等機制。若 issue 建立成功後,寫入其中一則暫存留言時失敗,主流程會中止;重跑後又會建立另一個 issue,留下內容不完整的孤兒 issue。這種依賴閉包可變狀態的半完成狀態,半年後要加入重試、續傳或測試失敗情境都會很痛苦。",
|
|
||||||
"suggestion": "把「建立追蹤 issue 並沖刷留言」抽成獨立、可注入 Gitea client 的服務函式,明確回傳 issue 與已寫入進度;建立前以 PR 編號或隱藏識別標記查找既有追蹤 issue,讓重跑能接續而非重複建立。至少也應保留已建立的 issue 編號並在錯誤訊息中回報,避免留下無法追蹤的半成品。",
|
|
||||||
"suggestedCode": ""
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"id": "F002",
|
"id": "F002",
|
||||||
"reviewer": "Maya",
|
"reviewer": "Maya",
|
||||||
@@ -34,19 +21,6 @@
|
|||||||
"suggestion": "新增主流程測試並 mock Gitea、agent 與 git 操作,至少涵蓋:`kept=[]` 時不建立 issue 且不留言;僅嚴重問題;僅警告/建議;混合問題;建立 issue 或寫入暫存留言失敗;標籤查詢、AI 選標籤及補掛標籤失敗時仍回貼 issue 連結。除了呼叫次數,也應斷言 API 呼叫順序、目標 issue 編號及留言內容。",
|
"suggestion": "新增主流程測試並 mock Gitea、agent 與 git 操作,至少涵蓋:`kept=[]` 時不建立 issue 且不留言;僅嚴重問題;僅警告/建議;混合問題;建立 issue 或寫入暫存留言失敗;標籤查詢、AI 選標籤及補掛標籤失敗時仍回貼 issue 連結。除了呼叫次數,也應斷言 API 呼叫順序、目標 issue 編號及留言內容。",
|
||||||
"suggestedCode": ""
|
"suggestedCode": ""
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"id": "F003",
|
|
||||||
"reviewer": "Maya",
|
|
||||||
"focus": "testing",
|
|
||||||
"badge": "🧪",
|
|
||||||
"severity": "警告",
|
|
||||||
"file": "src/lib/gitea.js",
|
|
||||||
"startLine": 188,
|
|
||||||
"endLine": 191,
|
|
||||||
"problem": "新增的 `addLabelsToIssue` 沒有對應測試,尚未驗證空值捷徑與實際 API 請求格式。這個函式位於新建問題流程的收尾路徑;若 endpoint、HTTP method 或 `{ labels }` payload 不符預期,追蹤 issue 將無法取得標籤,而空陣列是否真的不發出請求也未被保護。",
|
|
||||||
"suggestion": "新增單元測試,分別傳入 `undefined`、`null`、空陣列及多個 label id;斷言前三者回傳 `null` 且完全不呼叫 API,多個 id 時以 POST 呼叫正確的 owner/repo/issue endpoint 並傳送 `{ labels: [...] }`,另驗證 API 拋錯會原樣往上傳遞。",
|
|
||||||
"suggestedCode": ""
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"id": "F004",
|
"id": "F004",
|
||||||
"reviewer": "Maya",
|
"reviewer": "Maya",
|
||||||
@@ -59,19 +33,6 @@
|
|||||||
"problem": "`resolveMergeBase` 新增多階段 fetch 與淺層 checkout 修復邏輯,但沒有看到測試驗證成功、降級與最終失敗路徑。尤其初次 merge-base 失敗後,淺層與非淺層 repository 會走不同路徑,且多個 `tryGit` 失敗會被刻意吞掉;若參數、refspec 或重試順序有誤,只會在實際 CI checkout 深度不足時才暴露。",
|
"problem": "`resolveMergeBase` 新增多階段 fetch 與淺層 checkout 修復邏輯,但沒有看到測試驗證成功、降級與最終失敗路徑。尤其初次 merge-base 失敗後,淺層與非淺層 repository 會走不同路徑,且多個 `tryGit` 失敗會被刻意吞掉;若參數、refspec 或重試順序有誤,只會在實際 CI checkout 深度不足時才暴露。",
|
||||||
"suggestion": "以 stub 的 git 執行器或暫存 repository 補齊案例:首次 merge-base 成功;淺層 repository 經 `--unshallow` 後成功;`--unshallow` 失敗但 `--deepen=1000` 後成功;非淺層首次失敗後重試成功;所有策略失敗時拋出含 `baseRef` 且保留原始 `cause` 的錯誤。並斷言 base/head fetch 的 refspec 與執行順序。",
|
"suggestion": "以 stub 的 git 執行器或暫存 repository 補齊案例:首次 merge-base 成功;淺層 repository 經 `--unshallow` 後成功;`--unshallow` 失敗但 `--deepen=1000` 後成功;非淺層首次失敗後重試成功;所有策略失敗時拋出含 `baseRef` 且保留原始 `cause` 的錯誤。並斷言 base/head fetch 的 refspec 與執行順序。",
|
||||||
"suggestedCode": ""
|
"suggestedCode": ""
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "F005",
|
|
||||||
"reviewer": "Maya",
|
|
||||||
"focus": "testing",
|
|
||||||
"badge": "🧪",
|
|
||||||
"severity": "建議",
|
|
||||||
"file": "src/lib/review.js",
|
|
||||||
"startLine": 17,
|
|
||||||
"endLine": 45,
|
|
||||||
"problem": "新增的 agent 失敗診斷涵蓋逾時、數字或字串 exit code、signal、空輸出及 500 字截斷等多個邊界,但沒有測試鎖定輸出。這些資訊只在失敗路徑出現,正常審查不會自然覆蓋;日後修改時可能悄悄遺失真正的 CLI 錯誤內容,或破壞單行與截斷約束。",
|
|
||||||
"suggestion": "將摘要邏輯匯出供測試,或透過失敗的 `runAttackers`/`runDefenders`/`fillPurposes` 測試間接斷言 log。至少覆蓋 killed、數字 exit code、字串 code、signal、stderr 與 stdout 同時存在、超過 500 字、完全無資訊,以及 `res` 為 null/undefined 的案例。",
|
|
||||||
"suggestedCode": ""
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"excluded": []
|
"excluded": []
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
{
|
||||||
|
"generatedAt": "2026/07/20 15:57:46",
|
||||||
|
"commitSha": "a6534ee0764fe2363ebbb5525586ad3868dc6720",
|
||||||
|
"prNumber": 6,
|
||||||
|
"tool": {
|
||||||
|
"name": "code-review-resolve",
|
||||||
|
"version": "0.0.8",
|
||||||
|
"model": "(工具預設)"
|
||||||
|
},
|
||||||
|
"findings": [
|
||||||
|
{
|
||||||
|
"id": "F003",
|
||||||
|
"reviewer": "Maya",
|
||||||
|
"focus": "testing",
|
||||||
|
"badge": "🧪",
|
||||||
|
"severity": "警告",
|
||||||
|
"file": "src/index.js",
|
||||||
|
"startLine": 184,
|
||||||
|
"endLine": 245,
|
||||||
|
"problem": "建問題模式新增「issue 建立前暫存留言、建立後依序沖刷」的狀態流程,但沒有對應測試。尚未驗證 createIssue 或沖刷途中拋錯、空 buffer、重複呼叫、以及一般/建問題模式留言目的地是否正確;失敗路徑可能造成 issue 已建立但內容不完整或留言誤發到 PR。",
|
||||||
|
"suggestion": "補主流程整合測試並 mock Gitea API,驗證:一般模式直接發 PR 且記錄留言 id;issue 未建立時只暫存;建立後依序沖刷並清空 buffer;createIssue 與第 N 則沖刷留言失敗時以失敗結束且不再發布後續內容。屬測試架構決策(專案目前無測試框架)。",
|
||||||
|
"suggestedCode": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "F004",
|
||||||
|
"reviewer": "Maya",
|
||||||
|
"focus": "testing",
|
||||||
|
"badge": "🧪",
|
||||||
|
"severity": "警告",
|
||||||
|
"file": "src/index.js",
|
||||||
|
"startLine": 309,
|
||||||
|
"endLine": 395,
|
||||||
|
"problem": "建問題模式核心分支被大幅改寫,但沒有測試驗證各種 findings 組合與 API 失敗行為。kept.length===0、只有嚴重、只有警告/建議、兩者皆有,以及標籤挑選/issue 建立/PR 回貼連結/相依 API 失敗等路徑尚未試煉,無法確認「無問題完全靜默」「有問題才建 issue」及相依失敗僅降級等契約成立。",
|
||||||
|
"suggestion": "以參數化測試覆蓋 findings 四種組合,斷言 API 呼叫順序/次數/issue number/統計;並分別讓 listLabels/selectLabels/createIssue/問題留言/PR 連結留言/addIssueDependency 拋錯,驗證哪些中止、哪些僅記警告續行;零 findings 時斷言所有寫入 API 皆不呼叫。屬測試架構決策。",
|
||||||
|
"suggestedCode": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "F006",
|
||||||
|
"reviewer": "Maya",
|
||||||
|
"focus": "testing",
|
||||||
|
"badge": "🧪",
|
||||||
|
"severity": "警告",
|
||||||
|
"file": "src/lib/gitrepo.js",
|
||||||
|
"startLine": 103,
|
||||||
|
"endLine": 157,
|
||||||
|
"problem": "resolveMergeBase 新增多階段 fetch/重試策略,卻沒有測試鎖定淺層與失敗路徑:首次成功提早返回、非 shallow 不 unshallow、某次 fetch 失敗後仍嘗試下一策略、補抓成功立即停止、全部失敗時診斷與 cause 是否完整;易因呼叫順序或 off-by-one 在 runner 上才暴露。",
|
||||||
|
"suggestion": "將 git 執行器注入或 stub,建立表格化案例覆蓋首次成功/unshallow 後成功/deepen base 後成功/deepen HEAD 後成功/各 fetch 個別失敗/全部失敗;逐案斷言 git 參數與順序、成功後不再額外 fetch,並檢查最終錯誤含各策略成敗摘要且保留首次錯誤為 cause。屬可測性重構+測試架構決策。",
|
||||||
|
"suggestedCode": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "F007",
|
||||||
|
"reviewer": "Maya",
|
||||||
|
"focus": "testing",
|
||||||
|
"badge": "🧪",
|
||||||
|
"severity": "警告",
|
||||||
|
"file": "src/lib/gitrepo.js",
|
||||||
|
"startLine": 249,
|
||||||
|
"endLine": 289,
|
||||||
|
"problem": "推送流程新增 pushToken 分支,但沒有測試驗證兩套認證策略:有 PAT 時略過 origin、PAT 推送失敗不退回其他 token、無 PAT 時 origin 成功不重試、origin 失敗才用一般 token;也沒有案例保護含憑證資訊不出現在錯誤或測試輸出中。(本次已將認證改經 env 傳入並遮蔽 push 錯誤,測試仍待補。)",
|
||||||
|
"suggestion": "mock git 執行器與 URL/env 組裝,補測 pushToken 有值/空、origin 成功/失敗、PAT 推送失敗及含特殊字元等案例;斷言 push 目標與呼叫次數,並確保任何拋出的錯誤、log 或快照都不含原始 token。屬測試架構決策。",
|
||||||
|
"suggestedCode": ""
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"excluded": []
|
||||||
|
}
|
||||||
@@ -0,0 +1,104 @@
|
|||||||
|
{
|
||||||
|
"generatedAt": "2026/07/20 17:37:54",
|
||||||
|
"commitSha": "3ef8a302911c60b9f71024e1f4b60e0d4578b8fd",
|
||||||
|
"prNumber": 6,
|
||||||
|
"tool": {
|
||||||
|
"name": "code-review-resolve",
|
||||||
|
"version": "0.0.8",
|
||||||
|
"model": "(工具預設)"
|
||||||
|
},
|
||||||
|
"findings": [
|
||||||
|
{
|
||||||
|
"id": "F001",
|
||||||
|
"reviewer": "Leo",
|
||||||
|
"focus": "maintainability",
|
||||||
|
"badge": "🧰",
|
||||||
|
"severity": "警告",
|
||||||
|
"file": "src/index.js",
|
||||||
|
"startLine": 121,
|
||||||
|
"endLine": 145,
|
||||||
|
"problem": "流程步驟編號硬編碼在主流程註解、日誌字串、README 與多個函式 JSDoc 中;插入一個步驟就要同步修改大量檔案,文件與實作高耦合,日後調整流程易漏改而互相矛盾。",
|
||||||
|
"suggestion": "共用函式 JSDoc 改以語意階段名稱描述、不引用易變動的數字;日誌集中定義階段名稱或由單一流程描述產生編號;README 流程圖也以語意名稱為主。屬跨檔重構+設計取捨。",
|
||||||
|
"suggestedCode": "const STAGE = Object.freeze({\n TOOL_DETECTION: '偵測工具',\n DIFF_COLLECTION: '整理差異',\n ATTACK_REVIEW: '攻擊方審查',\n DEFENSE_REVIEW: '防守方裁決',\n});\nlog(STAGE.DIFF_COLLECTION, 'INF', message);"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "F003",
|
||||||
|
"reviewer": "Leo",
|
||||||
|
"focus": "maintainability",
|
||||||
|
"badge": "🧰",
|
||||||
|
"severity": "警告",
|
||||||
|
"file": "src/lib/gitrepo.js",
|
||||||
|
"startLine": 47,
|
||||||
|
"endLine": 65,
|
||||||
|
"problem": "tryGit 將所有 git 失敗壓成布林值,resolveMergeBase 的診斷只知策略成敗、無法區分認證/refspec/網路/版本問題;CI 出錯時維護者只能重跑或自行重現,診斷成本高。",
|
||||||
|
"suggestion": "讓嘗試結果保留結構化且已清理的錯誤分類(exit code、git 子命令、安全化後短訊息),仍避免記錄遠端 URL 或憑證;最終錯誤彙整足以行動的原因,並可對各失敗類型做單元測試。屬診斷重構+需測試。",
|
||||||
|
"suggestedCode": "function tryGit(cwd, ...args) {\n try {\n git(cwd, ...args);\n return { ok: true };\n } catch (error) {\n return { ok: false, code: error.status ?? error.code ?? null, reason: sanitizeGitError(error) };\n }\n}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "F004",
|
||||||
|
"reviewer": "Maya",
|
||||||
|
"focus": "testing",
|
||||||
|
"badge": "🧪",
|
||||||
|
"severity": "警告",
|
||||||
|
"file": "src/lib/gitrepo.js",
|
||||||
|
"startLine": 270,
|
||||||
|
"endLine": 291,
|
||||||
|
"problem": "findings 推送的認證路徑沒有測試。註:原「PAT 直接推送 vs origin 失敗重試」雙路徑已於先前 commit 合併為「一律以 token 明確認證推送」,測試仍待補:空 token 邊界、推送目標正確、錯誤與輸出不含 token 原文。",
|
||||||
|
"suggestion": "補單元測試攔截 git 參數/env:斷言以 token 認證推送、推送目標 refspec 正確、呼叫次數,並確保任何拋出的錯誤、log 或快照都不含原始 token。屬測試架構決策。",
|
||||||
|
"suggestedCode": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "F005",
|
||||||
|
"reviewer": "Bard",
|
||||||
|
"focus": "style",
|
||||||
|
"badge": "🎼",
|
||||||
|
"severity": "建議",
|
||||||
|
"file": "action.yml",
|
||||||
|
"startLine": 3,
|
||||||
|
"endLine": 3,
|
||||||
|
"problem": "檔頭「更新時間」為手動維護的固定字串,與實際檔案更新時間不一致;散落各檔的手動時間戳容易走調,讀者無法判斷可信度。",
|
||||||
|
"suggestion": "屬 jsc spec-time-log 慣例(各檔頭「更新時間」由 doc-funcs 流程統一產生/同步)。是否移除改用版控紀錄、或如何統一更新,宜由 doc-funcs 流程處理,不在 resolve 逐條硬改。",
|
||||||
|
"suggestedCode": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "F006",
|
||||||
|
"reviewer": "Bard",
|
||||||
|
"focus": "style",
|
||||||
|
"badge": "🎼",
|
||||||
|
"severity": "建議",
|
||||||
|
"file": "readme.md",
|
||||||
|
"startLine": 3,
|
||||||
|
"endLine": 3,
|
||||||
|
"problem": "README 檔頭手動「更新時間」與實際更新時間不符,並與 action.yml、src/index.js 重複保存同類易過期資訊,形成多個不一致的真相來源。",
|
||||||
|
"suggestion": "同 F005:屬 jsc spec-time-log 慣例,交 doc-funcs 流程統一維護(移除或自動注入)。",
|
||||||
|
"suggestedCode": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "F007",
|
||||||
|
"reviewer": "Bard",
|
||||||
|
"focus": "style",
|
||||||
|
"badge": "🎼",
|
||||||
|
"severity": "建議",
|
||||||
|
"file": "src/index.js",
|
||||||
|
"startLine": 7,
|
||||||
|
"endLine": 7,
|
||||||
|
"problem": "啟動橫幅硬編碼的「更新時間」與程式實際更新時間不一致,每次改程式都要人工校準,製造噪音並讓執行日誌呈現失真版本資訊。",
|
||||||
|
"suggestion": "同 F005:屬 jsc spec-time-log 慣例,交 doc-funcs 流程統一維護;若日誌需辨識版本,可改顯示 CI 注入的 commit SHA/版本號(屬慣例調整)。",
|
||||||
|
"suggestedCode": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "F008",
|
||||||
|
"reviewer": "Bard",
|
||||||
|
"focus": "style",
|
||||||
|
"badge": "🎼",
|
||||||
|
"severity": "建議",
|
||||||
|
"file": "src/index.js",
|
||||||
|
"startLine": 179,
|
||||||
|
"endLine": 231,
|
||||||
|
"problem": "main() 內新增兩個帶完整 JSDoc 的閉包函式與一大段「步驟 2:延後執行」說明,使主流程在進入步驟 3 前被近六十行細節打斷,留言路由、issue 建立與流程說明混在同一層,閱讀節奏沉重。",
|
||||||
|
"suggestion": "將留言路由與 issue 建立封裝成具語義名稱的輔助物件/模組(例如 createCommentPublisher),讓 main() 只保留流程級呼叫;延後清理理由縮成貼近呼叫點的簡短註解。與 F001(語意階段名稱)同屬主流程重構,宜一併處理。",
|
||||||
|
"suggestedCode": "const comments = createCommentPublisher({ ctx, gitea });\nawait comments.post(templates.toolComment({ /* ... */ }));"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"excluded": []
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
{
|
||||||
|
"generatedAt": "2026/07/20 18:00:02",
|
||||||
|
"commitSha": "d354f30c270e99baa9dcfc6aa76510710c0193ca",
|
||||||
|
"prNumber": null,
|
||||||
|
"tool": {
|
||||||
|
"name": "code-review-resolve",
|
||||||
|
"version": "0.0.8",
|
||||||
|
"model": "(工具預設)"
|
||||||
|
},
|
||||||
|
"findings": [
|
||||||
|
{
|
||||||
|
"id": "F001",
|
||||||
|
"reviewer": "🧰 Leo",
|
||||||
|
"focus": "maintainability",
|
||||||
|
"badge": "🧰",
|
||||||
|
"severity": "警告",
|
||||||
|
"file": "src/index.js",
|
||||||
|
"startLine": 257,
|
||||||
|
"endLine": 307,
|
||||||
|
"problem": "流程步驟編號同時硬編碼在 log 字串、區段註解、JSDoc、README 與多個函式庫中。插入或調整一個步驟就必須跨大量檔案全面改號,容易讓文件與實際紀錄不一致。",
|
||||||
|
"suggestion": "程式內改用穩定的語意階段名稱(如 diff、attack、defend、publish),由單一流程定義集中決定顯示順序;JSDoc 以階段名稱互相引用,README 流程圖由同一份階段資料產生或僅在文件層維護展示編號。",
|
||||||
|
"suggestedCode": "const PHASE = Object.freeze({\n RESOLVE_OLD: '清理舊留言',\n DETECT_TOOL: '偵測工具',\n COLLECT_DIFF: '整理差異',\n ATTACK: '攻擊方審查',\n DEFEND: '防守方裁決',\n});\n\nlog(PHASE.COLLECT_DIFF, 'INF', `變更檔案 ${allFiles.length} 個…`);"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "F002",
|
||||||
|
"reviewer": "🧪 Maya",
|
||||||
|
"focus": "testing",
|
||||||
|
"badge": "🧪",
|
||||||
|
"severity": "警告",
|
||||||
|
"file": "src/lib/gitrepo.js",
|
||||||
|
"startLine": 252,
|
||||||
|
"endLine": 289,
|
||||||
|
"problem": "commitAndPushFindings 的推送行為(有無變更、認證方式、空 commit 防護、是否觸發 CI)缺少測試證明。此為本次變更的核心行為,卻沒有任何測試覆蓋。",
|
||||||
|
"suggestion": "mock git 命令,斷言:無 staged diff 時回傳 false 且不執行 commit/push;有變更時以認證方式推送到正確 refspec 與分支。注意:原 finding 描述的 pushToken 對比 origin 雙軌邏輯已於重構後移除(現行一律以 token 經 pushWithCredential 認證推送),撰寫測試前需依現行程式碼重新界定情境。",
|
||||||
|
"suggestedCode": ""
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"excluded": []
|
||||||
|
}
|
||||||
@@ -0,0 +1,209 @@
|
|||||||
|
{
|
||||||
|
"generatedAt": "2026/07/20 18:31:07",
|
||||||
|
"commitSha": "0c29daa01434d6b6fa1b20ce81c513c75b1b1c6a",
|
||||||
|
"prNumber": null,
|
||||||
|
"tool": {
|
||||||
|
"name": "code-review-resolve",
|
||||||
|
"version": "0.0.9",
|
||||||
|
"model": "(工具預設)"
|
||||||
|
},
|
||||||
|
"findings": [
|
||||||
|
{
|
||||||
|
"id": "F001",
|
||||||
|
"reviewer": "Leo",
|
||||||
|
"focus": "",
|
||||||
|
"badge": "🧰",
|
||||||
|
"severity": "警告",
|
||||||
|
"file": "src/index.js",
|
||||||
|
"startLine": 119,
|
||||||
|
"endLine": 139,
|
||||||
|
"problem": "流程步驟編號被當成跨模組識別值,散落在 `index.js`、各 library 的日誌與 JSDoc、README 流程圖及功能表。這次僅因插入並延後一步,就必須同步修改大量 `步驟2`~`步驟8` 字串,而且實際執行順序已變成 1、3~8、2、9~10;未來再調整流程時非常容易讓文件、日誌與程式碼脫節。",
|
||||||
|
"suggestion": "以穩定的語意階段名稱取代硬編碼序號,例如 `TOOL_DETECTION`、`COLLECT_DIFF`、`RESOLVE_OLD_COMMENTS`,由單一常數表集中決定顯示名稱;README 的流程順序則從同一份定義產生,或至少不要在各函式文件重複紀錄易變的數字。",
|
||||||
|
"suggestedCode": "```\nconst PHASE = Object.freeze({\n FAST_RESULT: '快速回報',\n DETECT_TOOL: '偵測 AI 工具',\n COLLECT_DIFF: '整理變更',\n RESOLVE_OLD: '處理舊留言',\n PUBLISH_FINDINGS: '發布審查結果',\n});\n\nlog(PHASE.DETECT_TOOL, 'INF', `選用工具:${tool.name}。`);\n```",
|
||||||
|
"sourceIssue": 11
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "F002",
|
||||||
|
"reviewer": "Leo",
|
||||||
|
"focus": "",
|
||||||
|
"badge": "🧰",
|
||||||
|
"severity": "警告",
|
||||||
|
"file": "readme.md",
|
||||||
|
"startLine": 59,
|
||||||
|
"endLine": 130,
|
||||||
|
"problem": "功能索引把分支名稱與原始碼行號硬編碼在數十個連結中;本次僅因程式碼增行,就必須人工把大量 `#L...` 全面更新,已直接顯示這份文件存在高同步成本。之後任一檔案前段增刪程式碼,都會讓這些連結再次漂移,而且指向會持續變動的 `develop` 分支,使舊版 README 與實際連結內容無法穩定對應。",
|
||||||
|
"suggestion": "不要手動維護原始碼行號。若只需導覽,連到檔案並由右欄既有章節錨點提供函式級定位;若必須精確指向定義,應由 AST/文件產生工具在 CI 自動建立索引,並連到固定 commit SHA 或版本 tag。至少增加連結檢查,避免半年後整張功能表悄悄失準。",
|
||||||
|
"suggestedCode": "```\n| 功能名稱 | 功能描述 |\n| --- | --- |\n| [gitrepo.resolveMergeBase](src/lib/gitrepo.js) | [解析 base 分支與 HEAD 的 merge-base](#gitreporesolvemergebase) |\n```",
|
||||||
|
"sourceIssue": 12
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "F006",
|
||||||
|
"reviewer": "Rogue",
|
||||||
|
"focus": "",
|
||||||
|
"badge": "⚡",
|
||||||
|
"severity": "警告",
|
||||||
|
"file": "src/lib/gitrepo.js",
|
||||||
|
"startLine": 134,
|
||||||
|
"endLine": 134,
|
||||||
|
"problem": "在檢查是否為淺層 repository (shallow repository) 時,呼叫了外部子行程執行 `git rev-parse --is-shallow-repository`。建立與啟動 OS 子行程是非常昂貴的操作,會白白浪費數十毫秒的 CPU 週期與系統資源。",
|
||||||
|
"suggestion": "Git 在淺層 clone 時會在 `.git` 目錄下建立一個 `shallow` 檔案。我們可以使用 Node.js 內建的 `fs.existsSync` 進行本地檔案檢查,不需啟動額外的 Git 子行程,執行速度可快上百倍。",
|
||||||
|
"suggestedCode": "```\nconst fs = require('fs');\n// ...\nif (fs.existsSync(path.join(cwd, '.git', 'shallow'))) {\n strategies.push(['unshallow', 'fetch', '--no-tags', '--unshallow', 'origin']);\n}\n```",
|
||||||
|
"sourceIssue": 14
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "F007",
|
||||||
|
"reviewer": "Leo",
|
||||||
|
"focus": "",
|
||||||
|
"badge": "🧰",
|
||||||
|
"severity": "警告",
|
||||||
|
"file": "src/lib/gitrepo.js",
|
||||||
|
"startLine": 293,
|
||||||
|
"endLine": 305,
|
||||||
|
"problem": "為了防止 Git 推送失敗時在例外訊息中回顯包含 Token 與遠端 URL 的命令列參數,pushWithCredential 的 catch 區塊直接拋出一個固定的 Error('推送審查結果 commit 失敗...')。但這樣一來,它完全吞掉了原始的錯誤(例如 non-fast-forward 非快轉、分支保護規則阻擋、或連線逾時),六個月後的維護者在 CI log 中看到此錯誤時,完全無從判斷失敗的原因。",
|
||||||
|
"suggestion": "建議在保留安全遮罩的前提下,保留原始 exception 的排錯線索。例如可以檢查並安全地過濾 err.message 或 err.stderr 中所有的敏感字串(如 Token/URL),然後將其作為新錯誤的 cause 屬性或附加訊息傳遞下去。",
|
||||||
|
"suggestedCode": "```\n} catch (err) {\n // 過濾敏感資訊後保留錯誤細節\n const safeMessage = err.message ? redactSecrets(err.message) : '未知錯誤';\n const error = new Error(`推送審查結果 commit 失敗(${safeMessage})。`);\n error.cause = err;\n throw error;\n }\n```",
|
||||||
|
"sourceIssue": 14
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "F009",
|
||||||
|
"reviewer": "Bard",
|
||||||
|
"focus": "",
|
||||||
|
"badge": "🎼",
|
||||||
|
"severity": "建議",
|
||||||
|
"file": "src/index.js",
|
||||||
|
"startLine": 308,
|
||||||
|
"endLine": 368,
|
||||||
|
"problem": "新增或修改的步驟分隔註解(如步驟 8 分組、步驟 2 延後、步驟 9、步驟 10、及建問題模式收束)其尾隨的水平分隔線(─)長度不一或僅存單一字元,破壞了專案既有程式碼中整齊劃一的長分隔線視覺排版,視覺上顯得雜亂、走調。",
|
||||||
|
"suggestion": "補足尾隨的水平線 ─,使其與鄰近步驟分隔註解的長度(約 70~80 字元寬度)與視覺風格保持一致,維持排版的美觀。",
|
||||||
|
"suggestedCode": "```\n// ── 步驟 8(分組):依嚴重等級分組(嚴重/警告+建議),組內已依檔案與行數排序 ────────────────\n```",
|
||||||
|
"sourceIssue": 14
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "F010",
|
||||||
|
"reviewer": "Rogue",
|
||||||
|
"focus": "",
|
||||||
|
"badge": "⚡",
|
||||||
|
"severity": "建議",
|
||||||
|
"file": "src/index.js",
|
||||||
|
"startLine": 366,
|
||||||
|
"endLine": 382,
|
||||||
|
"problem": "在建問題模式收束時,先 `await gitea.createIssueComment` 再 `await gitea.addIssueDependency`,這兩個 Gitea API 呼叫是獨立且無資料相依性的,卻以序列(Sequential)方式執行,白白浪費了一次網路往返(RTT)的等待時間。",
|
||||||
|
"suggestion": "使用 `Promise.all` 同時發起這兩個請求,並行處理以減少整體 execution 的等待時間。",
|
||||||
|
"suggestedCode": "```\nconst commentPromise = gitea.createIssueComment(\n ctx,\n templates.issueLinkComment({\n issueNumber: issue.number,\n issueUrl: issue.html_url,\n severeCount: severe.length,\n otherCount: others.length,\n })\n );\n const dependencyPromise = gitea.addIssueDependency(ctx, ctx.prNumber, issue.number)\n .then(() => log('建問題', 'INF', `已將 PR #${ctx.prNumber} 設為相依於 issue #${issue.number}。`))\n .catch((err) => log('建問題', 'WRN', `設定 PR 相依失敗:${err.message}。`));\n \n await Promise.all([commentPromise, dependencyPromise]);\n```",
|
||||||
|
"sourceIssue": 14
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "F012",
|
||||||
|
"reviewer": "Rogue",
|
||||||
|
"focus": "",
|
||||||
|
"badge": "⚡",
|
||||||
|
"severity": "建議",
|
||||||
|
"file": "src/lib/review.js",
|
||||||
|
"startLine": 48,
|
||||||
|
"endLine": 53,
|
||||||
|
"problem": "在 `agentFailureDetail` 之中,進行 stderr 與 stdout 的遮罩處理時,是先截斷至 2,000 字元,然後執行多次複雜的 `redactSecrets` 正規表示式替換,最後再截斷至 500 字元輸出。這會造成 1,500 字元的複雜 regex 運算結果在下一步被直接丟棄,白白浪費了 CPU 進行字串比對與取代的週期。",
|
||||||
|
"suggestion": "應在呼叫 `redactSecrets` 之前,就先將字串截斷至目標長度(500 字元),再進行遮罩,可大幅減少 regex 運算負擔。",
|
||||||
|
"suggestedCode": "```\nconst stderr = redactSecrets(String((res && res.stderr) || '').slice(0, 500));\n if (stderr) parts.push(`stderr:${stderr}`);\n const stdout = redactSecrets(String((res && res.output) || '').slice(0, 500));\n if (stdout) parts.push(`stdout:${stdout}`);\n```",
|
||||||
|
"sourceIssue": 14
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "F014",
|
||||||
|
"reviewer": "Leo",
|
||||||
|
"focus": "",
|
||||||
|
"badge": "🧰",
|
||||||
|
"severity": "建議",
|
||||||
|
"file": "readme.md",
|
||||||
|
"startLine": 56,
|
||||||
|
"endLine": 132,
|
||||||
|
"problem": "README 的功能表大量手動維護 `src/branch/develop/...#Lxx` 深連結,這次光是分支與行號就改了整排。這類文件會隨任何插入註解、重排函式、換預設分支而失準,未來維護者必須在改程式時同步更新一大段文件,維護成本偏高。",
|
||||||
|
"suggestion": "改成不依賴行號的相對連結,或用文件產生腳本從原始碼 JSDoc 自動產出這張表。若仍要指向 Gitea,建議至少移除 `#Lxx`,或集中定義分支名稱,避免每次改分支都要全表搜尋替換。",
|
||||||
|
"suggestedCode": "",
|
||||||
|
"sourceIssue": 15
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "F022",
|
||||||
|
"reviewer": "Leo",
|
||||||
|
"focus": "",
|
||||||
|
"badge": "🧰",
|
||||||
|
"severity": "警告",
|
||||||
|
"file": "readme.md",
|
||||||
|
"startLine": 76,
|
||||||
|
"endLine": 132,
|
||||||
|
"problem": "README 內大量函式清單同時硬編分支名稱與行號錨點,這次 diff 已經整批從 `master` 改成 `develop` 並同步調整行號。這類文件和原始碼結構高度重複,後續只要插入幾行程式,文件連結就會失準,維護者必須靠人工記得同步整張表。",
|
||||||
|
"suggestion": "改成不含行號的穩定檔案連結,或把這份 API/功能表改由 JSDoc/腳本產生。若一定要保留行號,建議把產生流程寫入 npm script,避免每次程式碼位移都人工批次修改 README。",
|
||||||
|
"suggestedCode": "",
|
||||||
|
"sourceIssue": 18
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "F025",
|
||||||
|
"reviewer": "Assassin",
|
||||||
|
"focus": "",
|
||||||
|
"badge": "🗡️",
|
||||||
|
"severity": "警告",
|
||||||
|
"file": "action.yml",
|
||||||
|
"startLine": 21,
|
||||||
|
"endLine": 24,
|
||||||
|
"problem": "這裡建議呼叫端傳入「能觸發 CI 的 PAT」作為 action token。攻擊者最愛這種長效、可推送、可觸發 workflow 的憑證:只要此 action 在不受信任 PR 上執行,或 PR 能影響 action/workflow 執行內容,惡意變更就可能讀取 `INPUT_TOKEN`、推送結果 commit、再藉由可觸發 CI 的身分製造後續執行鏈。自動 token 原本不觸發 CI 是一道防線,這個建議等於要求使用者把防線拆掉。",
|
||||||
|
"suggestion": "不要泛稱建議使用可觸發 CI 的 PAT。文件與介面應明確要求最小權限、repo 限定、短效或可輪替 token,並禁止在 fork/不受信任 PR context 暴露 PAT。更穩的設計是分離 API 留言 token 與 push token,且只有在明確受信任事件或受保護分支才允許 push token 存在;否則拒絕 commit/push,只做留言或 artifact。",
|
||||||
|
"suggestedCode": "",
|
||||||
|
"sourceIssue": 19
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "F026",
|
||||||
|
"reviewer": "Leo",
|
||||||
|
"focus": "",
|
||||||
|
"badge": "🧰",
|
||||||
|
"severity": "建議",
|
||||||
|
"file": "readme.md",
|
||||||
|
"startLine": 59,
|
||||||
|
"endLine": 132,
|
||||||
|
"problem": "README 的功能列表手動維護了大量 `src/branch/develop/...#Lxx` 深連結與行號。這次 PR 已經一次改動數十個 branch/line anchor,代表文件和原始碼行號高度耦合;下一次只要插入幾行程式,文件就會悄悄過期,維護者很難知道哪些連結還準。",
|
||||||
|
"suggestion": "避免在手寫 README 綁定行號,改連到函式所在檔案或穩定章節錨點;若必須保留行號,請把這段改成產生式文件,讓 CI 或腳本從原始碼/JSDoc 重新生成,減少人工同步成本。",
|
||||||
|
"suggestedCode": "",
|
||||||
|
"sourceIssue": 19
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "F031",
|
||||||
|
"reviewer": "Leo",
|
||||||
|
"focus": "",
|
||||||
|
"badge": "🧰",
|
||||||
|
"severity": "建議",
|
||||||
|
"file": "readme.md",
|
||||||
|
"startLine": 56,
|
||||||
|
"endLine": 132,
|
||||||
|
"problem": "README 的功能表大量硬編遠端分支名稱與行號,這次只是從 `master` 改成 `develop` 並同步行號,但這種文件很容易在下一次函式移動、預設分支更名或重排時再次整批失準。未來維護者會被迫反覆做低價值的連結校正,文件也可能在沒人注意時指到錯誤位置。",
|
||||||
|
"suggestion": "若 README 是 repo 內文件,優先改成相對路徑連結,並避免固定行號;若必須保留行號,建議用產生腳本統一輸出這張表,讓分支名與行號只從單一來源計算。",
|
||||||
|
"suggestedCode": "",
|
||||||
|
"sourceIssue": 21
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "F040",
|
||||||
|
"reviewer": "Assassin",
|
||||||
|
"focus": "",
|
||||||
|
"badge": "🗡️",
|
||||||
|
"severity": "警告",
|
||||||
|
"file": "action.yml",
|
||||||
|
"startLine": 19,
|
||||||
|
"endLine": 22,
|
||||||
|
"problem": "這段新增說明鼓勵呼叫端傳入「能觸發 CI 的 PAT」。攻擊者最喜歡這種長效、高權限、可觸發 workflow 的憑證:若 action 跑在不可信 PR、AI CLI 被 prompt injection 誘導讀環境變數,或同 repo PR 可改動本 action 程式碼,就可能把 PAT 外送或濫用成寫入 repo/觸發 CI 的跳板。",
|
||||||
|
"suggestion": "不要把長效 PAT 當建議預設。改用最小權限、短效的 GitHub App/Gitea App token,並明確禁止在不可信 fork PR 傳入可寫 token。若目標只是回報檢查結果,優先用 status/check API 寫結果,不要靠 PAT push 再觸發下一輪 CI。",
|
||||||
|
"suggestedCode": "```\ndescription: 'Gitea API token(PR/issue 留言與 push findings 用;請使用最小權限、短效 token,勿在不可信 PR 傳入長效 PAT)'\n```",
|
||||||
|
"sourceIssue": 23
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "F041",
|
||||||
|
"reviewer": "Leo",
|
||||||
|
"focus": "",
|
||||||
|
"badge": "🧰",
|
||||||
|
"severity": "建議",
|
||||||
|
"file": "readme.md",
|
||||||
|
"startLine": 58,
|
||||||
|
"endLine": 131,
|
||||||
|
"problem": "README 的功能表把分支名稱與行號大量硬編在外部 URL 裡,這次已經需要整批 `master` 改 `develop` 並同步多個 `#Lxx`。這類文件會隨任何程式碼插行、函式移動或預設分支變更而失準,維護成本會線性累積,最後讀者點到的文件比沒有文件更誤導。",
|
||||||
|
"suggestion": "改用 repo 相對連結、不固定行號,或把這段功能表改由腳本從 JSDoc 自動產生。若需要連到特定實作,優先連到檔案或錨點,避免每次重排程式碼都要同步更新幾十個行號。",
|
||||||
|
"suggestedCode": "```\n| log.taipeiNow | [src/lib/log.js](src/lib/log.js) | 取得台北時區 yyyy/MM/dd HH:mm:ss 時間字串 |\n| review.runAttackers | [src/lib/review.js](src/lib/review.js) | 攻擊方 sub agent 並行找問題並合併列表 |\n```",
|
||||||
|
"sourceIssue": 23
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"excluded": []
|
||||||
|
}
|
||||||
@@ -0,0 +1,184 @@
|
|||||||
|
{
|
||||||
|
"generatedAt": "2026/07/21 14:27:42",
|
||||||
|
"commitSha": "9e7f8a2a0a807c26e12e9bf0381e7decfb9e5568",
|
||||||
|
"prNumber": 6,
|
||||||
|
"tool": {
|
||||||
|
"name": "codex",
|
||||||
|
"version": "codex-cli 0.144.6",
|
||||||
|
"model": "gpt-5.5"
|
||||||
|
},
|
||||||
|
"findings": [],
|
||||||
|
"excluded": [
|
||||||
|
{
|
||||||
|
"reviewer": "Assassin",
|
||||||
|
"focus": "security",
|
||||||
|
"badge": "🗡️",
|
||||||
|
"severity": "嚴重",
|
||||||
|
"file": "src/lib/diagnostics.js",
|
||||||
|
"startLine": 23,
|
||||||
|
"endLine": 23,
|
||||||
|
"problem": "攻擊者只要讓 AI CLI 在 debug 模式下把 `Authorization: token <secret>` 或 `Authorization: Basic <base64>` 印到 stderr/stdout,這條遮罩規則只會遮掉 `token`/`Basic` 這個 scheme,後面的真正憑證仍會進 CI log。這正好打穿本檔宣稱的「安全診斷」防線,PAT 或 API token 會被長期保存並暴露給可讀 log 的人。",
|
||||||
|
"suggestion": "把整個 Authorization header value 視為機密,不要只特判 Bearer。應遮掉 scheme 與 credential 全段;若要保留 scheme,也只能保留固定白名單字樣,不能留下後面的 token。",
|
||||||
|
"suggestedCode": ".replace(/(authorization\\s*[:=]\\s*)(?:\\S+\\s+)?\\S+/gi, '$1***')",
|
||||||
|
"id": "F001",
|
||||||
|
"verdicts": {
|
||||||
|
"Paladin": {
|
||||||
|
"exclude": true,
|
||||||
|
"reason": "可排除(重複)。歷史 finding 已指出除錯診斷輸出中 Authorization 遮罩規則可能只遮到 scheme、留下後方憑證,並造成 CI log 洩漏,與本條同一問題。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"reviewer": "Leo",
|
||||||
|
"focus": "maintainability",
|
||||||
|
"badge": "🧰",
|
||||||
|
"severity": "警告",
|
||||||
|
"file": "src/index.js",
|
||||||
|
"startLine": 181,
|
||||||
|
"endLine": 239,
|
||||||
|
"problem": "`main()` 這次把「PR 留言」、「issue 暫存」、「issue 建立後 flush」三種狀態直接塞進閉包變數 `currentRunCommentIds`、`issueBuffer`、`issue` 與 `queueOrPostComment()`。未來只要再新增一種落地方式或調整留言順序,維護者必須同時理解整個主流程的時序,否則很容易出現留言漏發、舊留言誤標、或 issue 尚未建立卻被使用的狀態錯誤。這段已經不是單純編排,而是隱含一個留言發布狀態機。",
|
||||||
|
"suggestion": "把留言目的地抽成小型模組,例如 `CommentSink` / `ReviewPublisher`,讓 `main()` 只負責流程編排:`publisher.postContext()`、`publisher.flushIssue()`、`publisher.resolveOldPrComments()`。建問題模式的暫存與 flush 可獨立測試,半年後改流程時不用在 `main()` 裡追閉包狀態。",
|
||||||
|
"suggestedCode": "",
|
||||||
|
"id": "F007",
|
||||||
|
"verdicts": {
|
||||||
|
"Paladin": {
|
||||||
|
"exclude": true,
|
||||||
|
"reason": "可排除(命中已知排除事項且重複)。既有紀錄已涵蓋 main() 內留言路由、issue 狀態、緩衝佇列與發布狀態機耦合的同一問題。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"reviewer": "Leo",
|
||||||
|
"focus": "maintainability",
|
||||||
|
"badge": "🧰",
|
||||||
|
"severity": "警告",
|
||||||
|
"file": "readme.md",
|
||||||
|
"startLine": 56,
|
||||||
|
"endLine": 132,
|
||||||
|
"problem": "README 這次把大量連結從 `branch/master` 改成 `branch/develop`,同時保留許多硬編碼行號。這種文件會隨分支名稱、預設分支、或任一檔案插入幾行就整批失準;未來維護者每次調整程式都得同步修幾十個 URL,否則文件看起來精準、實際上卻導到錯誤位置。",
|
||||||
|
"suggestion": "改用 repo 相對連結並盡量避免行號,例如 `src/lib/log.js` 或 `src/lib/log.js#L20` 只保留少數真正需要精準定位的 API。若這段是產生文件,請把分支名稱與連結格式集中在產生器設定,不要把同一個 branch 字串散落在 README 表格裡。",
|
||||||
|
"suggestedCode": "",
|
||||||
|
"id": "F008",
|
||||||
|
"verdicts": {
|
||||||
|
"Paladin": {
|
||||||
|
"exclude": true,
|
||||||
|
"reason": "可排除(重複)。歷史 findings 已多次指出 README 大量硬編 branch 與行號深連結,造成文件與原始碼高同步成本;本條為同一問題。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"reviewer": "Mage",
|
||||||
|
"focus": "logic",
|
||||||
|
"badge": "🔮",
|
||||||
|
"severity": "警告",
|
||||||
|
"file": "src/index.js",
|
||||||
|
"startLine": 217,
|
||||||
|
"endLine": 225,
|
||||||
|
"problem": "建問題模式先建立 issue,再逐則 flush `issueBuffer`,但中途任一留言 API 失敗會直接拋出,沒有回滾或冪等處理。最小重現:`gitea.createIssue` 成功建立 #10,第一則 buffered comment 成功,第二則因 500/timeout 失敗 → 主流程 exit 1,PR 沒有 issue 連結、也沒有結果 commit;重跑時又建立 #11,留下半成品 issue #10。這會在暫時性 API 錯誤下造成重複追蹤 issue 與狀態不一致。",
|
||||||
|
"suggestion": "建立 issue 後立即寫入可重試識別資訊,重跑前先搜尋/復用既有本 PR 的 AI review issue;或在 flush 失敗時捕捉錯誤,將已建立 issue 補上失敗狀態與 PR 回連,再讓流程以可診斷方式收束。",
|
||||||
|
"suggestedCode": "",
|
||||||
|
"id": "F010",
|
||||||
|
"verdicts": {
|
||||||
|
"Paladin": {
|
||||||
|
"exclude": true,
|
||||||
|
"reason": "可排除(命中已知排除事項且重複)。issue 建立後 flush 暫存留言失敗、重跑又建立重複 issue,正是已知排除事項與多筆歷史 findings 已記錄的問題。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"reviewer": "Maya",
|
||||||
|
"focus": "testing",
|
||||||
|
"badge": "🧪",
|
||||||
|
"severity": "警告",
|
||||||
|
"file": "src/index.js",
|
||||||
|
"startLine": 180,
|
||||||
|
"endLine": 241,
|
||||||
|
"problem": "建問題模式新增了「先暫存留言、確定有保留問題才建立 issue、再 flush 暫存留言」的流程,但目前新增測試只驗到低階 helper,沒有驗證主流程在 create-issue=true 時的留言去向與靜默通過行為。這裡若順序錯了,可能會把原本應該留在 issue 的工具/diff/角色留言發到 PR,或在無保留問題時留下不該出現的 PR 留言。",
|
||||||
|
"suggestion": "請補主流程層級測試,stub `gitea`、`review.runAttackers`、`review.runDefenders`、`agents.detectTool`,至少驗證:\n\n| 情境 | 應斷言 |\n| --- | --- |\n| `createIssue=true` 且 `kept.length > 0` | 建 issue 前的情境留言先暫存,issue 建立後依序寫入該 issue |\n| `createIssue=true` 且 `kept.length === 0` | 不建立 issue、不對 PR 留言、不呼叫 `resolveOldComments` |\n| 一般模式 | 情境留言仍發到 PR,且 id 被加入 `currentRunCommentIds` |",
|
||||||
|
"suggestedCode": "",
|
||||||
|
"id": "F012",
|
||||||
|
"verdicts": {
|
||||||
|
"Paladin": {
|
||||||
|
"exclude": true,
|
||||||
|
"reason": "可排除(重複)。歷史 findings 已涵蓋 create-issue 模式中留言先暫存、issue 建立後依序寫入、無 finding 靜默通過與一般模式留言目的地缺少主流程測試。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"reviewer": "Maya",
|
||||||
|
"focus": "testing",
|
||||||
|
"badge": "🧪",
|
||||||
|
"severity": "警告",
|
||||||
|
"file": "src/index.js",
|
||||||
|
"startLine": 354,
|
||||||
|
"endLine": 395,
|
||||||
|
"problem": "新增的建問題模式會依嚴重度分流:嚴重問題改發到 issue、PR 回貼 issue 連結,且只有嚴重問題才呼叫 `addIssueDependency`。目前測試沒有覆蓋這個決策矩陣,等於沒有驗證「警告/建議不阻擋合併」與「嚴重問題要建立相依」這兩個關鍵行為。",
|
||||||
|
"suggestion": "請補 create-issue 模式的結果分流測試,至少涵蓋:\n\n| findings | 應斷言 |\n| --- | --- |\n| 只有警告/建議 | 建 issue、逐條留言、PR 回貼連結,但不呼叫 `addIssueDependency` |\n| 有嚴重問題 | 呼叫 `postSevereToIssue`、PR 回貼連結,並呼叫 `addIssueDependency(ctx, ctx.prNumber, issue.number)` |\n| `addIssueDependency` 拋錯 | 流程降級完成,不中斷收尾 commit |",
|
||||||
|
"suggestedCode": "",
|
||||||
|
"id": "F013",
|
||||||
|
"verdicts": {
|
||||||
|
"Paladin": {
|
||||||
|
"exclude": true,
|
||||||
|
"reason": "可排除(重複)。歷史 findings 已涵蓋建問題模式的嚴重/非嚴重分流、PR 回貼、相依 API 降級與核心分支缺少測試;本條屬同一測試缺口。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"reviewer": "Maya",
|
||||||
|
"focus": "testing",
|
||||||
|
"badge": "🧪",
|
||||||
|
"severity": "警告",
|
||||||
|
"file": "src/lib/gitrepo.js",
|
||||||
|
"startLine": 130,
|
||||||
|
"endLine": 188,
|
||||||
|
"problem": "`resolveMergeBase` 新增了多段 fetch 補歷史策略、每次補抓後重試 merge-base、以及淺層 repo 才執行 `--unshallow` 的行為,但測試只驗證不安全 baseRef 會被拒絕,沒有驗證這些成功/失敗路徑。這段是 diff 基準的核心,一旦 fallback 順序或條件壞掉,review 可能拿錯範圍或在 shallow checkout 直接失敗。",
|
||||||
|
"suggestion": "請把 git 執行層抽成可注入或以臨時 repo 測試,補齊:首次 merge-base 成功不跑 fallback、deepen base 後成功即停止、deepen PR HEAD 用目前 HEAD SHA、只有 shallow repo 才嘗試 `--unshallow`、全部策略失敗時錯誤訊息含診斷且保留 cause。",
|
||||||
|
"suggestedCode": "",
|
||||||
|
"id": "F014",
|
||||||
|
"verdicts": {
|
||||||
|
"Paladin": {
|
||||||
|
"exclude": true,
|
||||||
|
"reason": "可排除(重複)。歷史 findings 已針對 resolveMergeBase 多階段 fetch、shallow 與非 shallow 分支、停止條件、降級與最終失敗診斷缺少測試提出相同問題。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"reviewer": "Maya",
|
||||||
|
"focus": "testing",
|
||||||
|
"badge": "🧪",
|
||||||
|
"severity": "警告",
|
||||||
|
"file": "src/lib/gitrepo.js",
|
||||||
|
"startLine": 331,
|
||||||
|
"endLine": 366,
|
||||||
|
"problem": "`pushWithCredential` 是這次結果 commit 能否用 PAT 觸發下一輪 CI 的關鍵,但目前沒有測試驗證它真的清掉 checkout 的自動 token、再注入 PAT Authorization,也沒有測失敗時不外洩 remote URL/token。這條失敗路徑沒被試煉過,可能讓 `[failure]` 結果 commit 無法觸發快速回報,或在錯誤訊息裡洩漏認證資訊。",
|
||||||
|
"suggestion": "請補 `commitAndPushFindings`/`pushWithCredential` 的測試,stub `execFileSync` 驗證:`git push` 使用不含帳密的 remote URL、`GIT_CONFIG_COUNT=2`、第 0 筆 extraheader 為空值、第 1 筆為 Basic Authorization、remote origin 不符時拒絕、push 失敗時拋出的錯誤不包含 token 或 remote URL。",
|
||||||
|
"suggestedCode": "",
|
||||||
|
"id": "F015",
|
||||||
|
"verdicts": {
|
||||||
|
"Paladin": {
|
||||||
|
"exclude": true,
|
||||||
|
"reason": "可排除(重複)。歷史 findings 已涵蓋 pushWithCredential/commitAndPushFindings 的認證推送策略、token 注入、推送目標與失敗時不外洩 token 或 URL 的測試缺口。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"reviewer": "Maya",
|
||||||
|
"focus": "testing",
|
||||||
|
"badge": "🧪",
|
||||||
|
"severity": "建議",
|
||||||
|
"file": "src/lib/diagnostics.js",
|
||||||
|
"startLine": 21,
|
||||||
|
"endLine": 32,
|
||||||
|
"problem": "`redactSecrets` 新增多個遮罩規則與控制字元單行化,但測試只透過 `agentFailureDetail` 間接覆蓋 Authorization 與 token 兩種格式。URL 內嵌帳密、長 token、GitHub token 樣式、控制字元注入與 null/undefined 邊界都還沒被直接驗證。",
|
||||||
|
"suggestion": "請補 `redactSecrets` 的直接單元測試,包含:`https://user:pass@host`、`ghp_...`、40 字以上 token、含換行/tab 的假日誌注入、`null`/`undefined`。斷言重點是輸出為單行、敏感片段被 `***` 取代,且一般錯誤文字仍保留可診斷性。",
|
||||||
|
"suggestedCode": "",
|
||||||
|
"id": "F016",
|
||||||
|
"verdicts": {
|
||||||
|
"Paladin": {
|
||||||
|
"exclude": true,
|
||||||
|
"reason": "可排除(重複)。歷史 findings 已記錄失敗診斷與 redactSecrets 對 Authorization、URL 帳密、token 格式、控制字元、截斷與空值邊界缺少測試;本條為同一測試缺口。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,204 @@
|
|||||||
|
{
|
||||||
|
"generatedAt": "2026/07/21 14:42:39",
|
||||||
|
"commitSha": "d424447d1502f49538fcb3093d23b5ac7bfa16c5",
|
||||||
|
"prNumber": 6,
|
||||||
|
"tool": {
|
||||||
|
"name": "codex",
|
||||||
|
"version": "codex-cli 0.144.6",
|
||||||
|
"model": "gpt-5.5"
|
||||||
|
},
|
||||||
|
"findings": [
|
||||||
|
{
|
||||||
|
"reviewer": "Bard",
|
||||||
|
"focus": "style",
|
||||||
|
"badge": "🎼",
|
||||||
|
"severity": "建議",
|
||||||
|
"file": "src/lib/gitrepo.js",
|
||||||
|
"startLine": 139,
|
||||||
|
"endLine": 160,
|
||||||
|
"problem": "`runFetch`、`tryMergeBase`、`firstError`、`strategies` 夾在 `resolveMergeBase` 主旋律中,使這個函式同時負責驗證、fetch 策略編排、診斷文字組裝與錯誤包裝。即使邏輯可行,閱讀節奏已偏密,維護者很難一眼分辨「主要流程」與「補救策略」。",
|
||||||
|
"suggestion": "建議將 fetch 策略與診斷收集抽成小函式,例如 `fetchAndRecord`、`resolveMergeBaseWithStrategies`,讓 `resolveMergeBase` 保留高階流程:驗證 baseRef → fetch base → 嘗試 merge-base → 補抓歷史。",
|
||||||
|
"suggestedCode": "",
|
||||||
|
"id": "F003",
|
||||||
|
"verdicts": {
|
||||||
|
"Paladin": {
|
||||||
|
"exclude": false,
|
||||||
|
"reason": "保留。歷史 findings 主要涵蓋 resolveMergeBase 缺測試與診斷不足,本條指向函式內策略編排、診斷組裝與錯誤包裝混雜的可維護性問題,未被既有排除事項完整涵蓋。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"excluded": [
|
||||||
|
{
|
||||||
|
"reviewer": "Bard",
|
||||||
|
"focus": "style",
|
||||||
|
"badge": "🎼",
|
||||||
|
"severity": "建議",
|
||||||
|
"file": "src/index.js",
|
||||||
|
"startLine": 179,
|
||||||
|
"endLine": 212,
|
||||||
|
"problem": "`queueOrPostComment` 與 `createIssueAndFlushBufferedComments` 這兩個閉包名稱像兩段不同旋律:一個強調「排隊或發布」,另一個卻把「建立 issue、flush 暫存留言、設定狀態」全塞進名稱與實作。讀者要來回追 `trackingIssue`、`pendingIssueCommentBodies`,節奏偏長且語意負擔重。",
|
||||||
|
"suggestion": "建議統一命名語彙,例如把「暫存/發布」集中成 `postReviewComment`、`flushPendingIssueComments`,讓函式名稱只描述一件事;建立 issue 與 flush 留言也可拆成兩段,讀起來會更像樂句而不是長句。",
|
||||||
|
"suggestedCode": "",
|
||||||
|
"id": "F002",
|
||||||
|
"verdicts": {
|
||||||
|
"Paladin": {
|
||||||
|
"exclude": true,
|
||||||
|
"reason": "可排除(重複)。歷史 finding 已指出 main() 內新增閉包與 issue/comment 路由細節讓主流程閱讀負擔加重;本條只是改以目前函式名稱描述同一維護性問題。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"reviewer": "Leo",
|
||||||
|
"focus": "maintainability",
|
||||||
|
"badge": "🧰",
|
||||||
|
"severity": "警告",
|
||||||
|
"file": "src/index.js",
|
||||||
|
"startLine": 165,
|
||||||
|
"endLine": 213,
|
||||||
|
"problem": "`main()` 這次把「留言目的地切換、issue 建立、暫存留言 flush、標籤挑選前置狀態」都塞進閉包與可變狀態(`pendingIssueCommentBodies`、`trackingIssue`、`currentRunCommentIds`)。半年後要改建問題模式時,維護者得同時追蹤主流程步驟、閉包副作用與留言落點,任何新增留言點都可能忘記處理 queue/flush 或 PR 排除清單,長期會讓流程編排變得很脆弱。",
|
||||||
|
"suggestion": "把留言目的地抽成明確的小型物件或模組,例如 `ReviewCommentSink` / `IssueCommentSink`,由它負責 `post()`、`flush()`、`currentRunCommentIds`。`main()` 只保留流程順序,不直接管理留言暫存與 issue 狀態。",
|
||||||
|
"suggestedCode": "",
|
||||||
|
"id": "F006",
|
||||||
|
"verdicts": {
|
||||||
|
"Paladin": {
|
||||||
|
"exclude": true,
|
||||||
|
"reason": "可排除(命中已知排除事項且重複)。已知與歷史 findings 已涵蓋 main() 內留言目的地、issue 狀態、緩衝佇列與可變閉包耦合,及應抽出發布器/sink 的方向。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"reviewer": "Leo",
|
||||||
|
"focus": "maintainability",
|
||||||
|
"badge": "🧰",
|
||||||
|
"severity": "警告",
|
||||||
|
"file": "src/index.js",
|
||||||
|
"startLine": 302,
|
||||||
|
"endLine": 353,
|
||||||
|
"problem": "建問題模式的收束邏輯把「挑標籤、建立 issue、發 finding、回貼 PR、設定 issue dependency、決定是否阻擋合併」全部展開在 `main()`。這段和前面的 `createIssueAndFlushBufferedComments` 共同組成一條隱性的 issue workflow,但邊界沒有被封裝;未來要新增 issue 模板、改排序、改阻擋條件或重試策略時,會在主流程裡到處補條件,維護成本會快速上升。",
|
||||||
|
"suggestion": "把建問題模式整理成單一高階函式,例如 `review.publishIssueModeResults({ ctx, gitea, tool, model, cwd, kept, severe, others, bufferedComments })`,主流程只接收 `trackingIssue` / `filesToCommit` 等結果。這樣 PR 模式與 issue 模式的責任邊界會清楚很多。",
|
||||||
|
"suggestedCode": "",
|
||||||
|
"id": "F007",
|
||||||
|
"verdicts": {
|
||||||
|
"Paladin": {
|
||||||
|
"exclude": true,
|
||||||
|
"reason": "可排除(重複)。此條與 F006 及歷史 findings 同樣指向建問題模式在 main() 中承擔 issue workflow、發布分流與狀態管理,屬同一維護性問題的延伸描述。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"reviewer": "Leo",
|
||||||
|
"focus": "maintainability",
|
||||||
|
"badge": "🧰",
|
||||||
|
"severity": "建議",
|
||||||
|
"file": "readme.md",
|
||||||
|
"startLine": 56,
|
||||||
|
"endLine": 132,
|
||||||
|
"problem": "README 內大量維護到原始碼行號的連結,這次 diff 只是分支與行號位移就需要同步改一整片表格。這種文件和程式碼行號的硬耦合很容易在後續修改時過期,讀者點到錯誤位置,維護者也要花時間做機械式同步。",
|
||||||
|
"suggestion": "若這份表格是 API 索引,建議改成自動產生,或至少移除 `#Lxx` 行號錨點,改連到檔案或穩定章節錨點。讓文件描述 API,而不是跟著每次程式碼行號漂移。",
|
||||||
|
"suggestedCode": "",
|
||||||
|
"id": "F008",
|
||||||
|
"verdicts": {
|
||||||
|
"Paladin": {
|
||||||
|
"exclude": true,
|
||||||
|
"reason": "可排除(重複)。歷史 findings 已多次指出 README 功能表硬編分支與行號連結,導致文件與原始碼高度耦合且容易失準。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"reviewer": "Mage",
|
||||||
|
"focus": "logic",
|
||||||
|
"badge": "🔮",
|
||||||
|
"severity": "警告",
|
||||||
|
"file": "src/index.js",
|
||||||
|
"startLine": 251,
|
||||||
|
"endLine": 253,
|
||||||
|
"problem": "無可審查變更的分支在一般模式下會先把舊留言標為過時,之後才保存 findings 與 commit/push 結果。最小重現:`files.length === 0`、`nothingToReviewComment` 成功、`resolveOldComments` 成功,但接著 `saveFindings` 因檔案系統錯誤或 `commitFindings` 因 push 失敗拋例外。此時舊審查結果已被標過時,但沒有成功落地本回合的 success 結果 commit,狀態會停在半更新。",
|
||||||
|
"suggestion": "把 `review.resolveOldComments` 延後到 `saveFindings` 與必要的 `commitFindings` 成功之後;或至少在空變更路徑也遵守同一個交易順序:先產生並提交本回合結果,再清理舊留言。",
|
||||||
|
"suggestedCode": "",
|
||||||
|
"id": "F010",
|
||||||
|
"verdicts": {
|
||||||
|
"Paladin": {
|
||||||
|
"exclude": true,
|
||||||
|
"reason": "可排除(命中已知排除事項)。維護者已裁示舊留言應刻意在本回合結果發布前標為過時;本條要求延後清理,落在同一已排除範圍。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"reviewer": "Maya",
|
||||||
|
"focus": "testing",
|
||||||
|
"badge": "🧪",
|
||||||
|
"severity": "警告",
|
||||||
|
"file": "src/index.js",
|
||||||
|
"startLine": 160,
|
||||||
|
"endLine": 353,
|
||||||
|
"problem": "建問題模式的主流程被大幅改寫,但目前測試只驗證了少數 helper,沒有驗證「留言先暫存、確定有 kept finding 才建 issue、無保留問題時靜默通過、嚴重問題才加 issue dependency、最後回貼 PR 連結」這些新增流程。這些行為一旦順序或條件寫錯,測試不會擋下來。",
|
||||||
|
"suggestion": "請補 `main()` 層級的流程測試,stub `agents`、`review`、`gitea`、`gitrepo`,至少覆蓋:`createIssue=true && kept=[]` 不建立 issue/不貼 PR 留言;`kept` 只有警告/建議時建立 issue、flush 暫存留言、回貼 PR 連結但不呼叫 `addIssueDependency`;`kept` 含嚴重時呼叫 `addIssueDependency`,且 dependency 失敗時流程仍完成並 commit failure findings。",
|
||||||
|
"suggestedCode": "",
|
||||||
|
"id": "F011",
|
||||||
|
"verdicts": {
|
||||||
|
"Paladin": {
|
||||||
|
"exclude": true,
|
||||||
|
"reason": "可排除(重複)。歷史 findings 已涵蓋建問題模式 main() 層級流程缺測試,包括暫存留言、有 finding 才建 issue、無 finding 靜默、PR 回貼、嚴重與非嚴重分流及 dependency 失敗降級。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"reviewer": "Maya",
|
||||||
|
"focus": "testing",
|
||||||
|
"badge": "🧪",
|
||||||
|
"severity": "警告",
|
||||||
|
"file": "src/lib/gitrepo.js",
|
||||||
|
"startLine": 307,
|
||||||
|
"endLine": 361,
|
||||||
|
"problem": "`pushWithCredential` 新增了關鍵認證行為,但沒有測試驗證它真的用 `GIT_CONFIG_*` 清掉 checkout 的 extraheader、再注入 PAT Authorization,也沒有測試遠端 URL 不符與 push 失敗時不洩漏 URL/token 的失敗路徑。這段是結果 commit 能否觸發下一輪 CI 的核心,沒有測試等於這個新契約還沒通過試煉。",
|
||||||
|
"suggestion": "請補推送行為測試。可用可注入的 exec wrapper 或子程序測試方式驗證:`git push` argv 不含 token、env 包含兩筆同 scope extraheader、`GIT_CONFIG_VALUE_0` 為空值、`GIT_CONFIG_VALUE_1` 為 Basic header;再補 `remote.origin !== server.origin` 與 exec 失敗時錯誤訊息不含 token/remoteUrl 的案例。",
|
||||||
|
"suggestedCode": "",
|
||||||
|
"id": "F012",
|
||||||
|
"verdicts": {
|
||||||
|
"Paladin": {
|
||||||
|
"exclude": true,
|
||||||
|
"reason": "可排除(重複)。歷史 findings 已記錄 pushWithCredential/pushToken 認證推送路徑缺少測試,包含 token 不進 argv、認證遮蔽、推送目標與失敗訊息不洩漏敏感資訊。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"reviewer": "Maya",
|
||||||
|
"focus": "testing",
|
||||||
|
"badge": "🧪",
|
||||||
|
"severity": "警告",
|
||||||
|
"file": "src/lib/gitrepo.js",
|
||||||
|
"startLine": 130,
|
||||||
|
"endLine": 192,
|
||||||
|
"problem": "`resolveMergeBase` 新增多段 fetch fallback:先抓 base、再 deepen base、deepen PR HEAD、最後 shallow repo 才 unshallow,但現有測試只驗證不安全 baseRef 會被拒絕,沒有驗證淺層歷史補抓順序、每次 fetch 後會重試 merge-base、成功後會短路,也沒有覆蓋所有策略失敗時的診斷錯誤。",
|
||||||
|
"suggestion": "請補針對 `resolveMergeBase` 的失敗與邊界測試。建議把 git 執行函式抽成可替換依賴,或用臨時 git repo 模擬 shallow 狀態,斷言:首次 merge-base 成功不走 fallback;deepen base 成功後立即回傳;deepen PR HEAD 使用目前 HEAD SHA 而不是遠端 `HEAD`;非 shallow repo 不呼叫 `--unshallow`;全部失敗時錯誤包含策略診斷。",
|
||||||
|
"suggestedCode": "",
|
||||||
|
"id": "F013",
|
||||||
|
"verdicts": {
|
||||||
|
"Paladin": {
|
||||||
|
"exclude": true,
|
||||||
|
"reason": "可排除(重複)。歷史 findings 已針對 resolveMergeBase 多階段 fetch、淺層與非淺層分支、成功短路、降級順序與最終失敗診斷缺測試提出相同問題。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"reviewer": "Maya",
|
||||||
|
"focus": "testing",
|
||||||
|
"badge": "🧪",
|
||||||
|
"severity": "建議",
|
||||||
|
"file": "src/lib/diagnostics.js",
|
||||||
|
"startLine": 18,
|
||||||
|
"endLine": 69,
|
||||||
|
"problem": "`redactSecrets` 與 `agentFailureDetail` 是新加入的安全診斷防線,但測試只覆蓋 Authorization/token 的基本遮罩。控制字元單行化、URL 內嵌帳密、長 token/hex、輸入與輸出長度截斷、以及沒有 error code 時的 fallback 訊息都還沒被驗證。",
|
||||||
|
"suggestion": "請補診斷邊界測試,至少包含:含換行與 tab 的輸出不會產生多行 log;`https://user:pass@host` 會被遮罩;40 字元以上 token 會被遮罩;debug 模式下 stderr/stdout 只輸出到限制長度;沒有 `error.code`、`signal`、`stderr/stdout` 時仍回傳安全的 fallback 訊息。",
|
||||||
|
"suggestedCode": "",
|
||||||
|
"id": "F014",
|
||||||
|
"verdicts": {
|
||||||
|
"Paladin": {
|
||||||
|
"exclude": true,
|
||||||
|
"reason": "可排除(重複)。歷史 findings 已涵蓋 redactSecrets/agentFailureDetail 對控制字元、URL 帳密、token 格式、截斷與 fallback 診斷等邊界缺少測試。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,184 @@
|
|||||||
|
{
|
||||||
|
"generatedAt": "2026/07/21 16:00:33",
|
||||||
|
"commitSha": "216bc39255ec176a0f66f2b257beea5929ef4eb8",
|
||||||
|
"prNumber": 6,
|
||||||
|
"tool": {
|
||||||
|
"name": "codex",
|
||||||
|
"version": "codex-cli 0.144.6",
|
||||||
|
"model": "gpt-5.5"
|
||||||
|
},
|
||||||
|
"findings": [],
|
||||||
|
"excluded": [
|
||||||
|
{
|
||||||
|
"reviewer": "Bard",
|
||||||
|
"focus": "style",
|
||||||
|
"badge": "🎼",
|
||||||
|
"severity": "警告",
|
||||||
|
"file": "src/index.js",
|
||||||
|
"startLine": 166,
|
||||||
|
"endLine": 223,
|
||||||
|
"problem": "`main()` 這段新添的建問題模式狀態、暫存佇列、三個閉包輔助函式,全塞在主流程開頭,讓主旋律還沒開始就先進入一大段插曲。`issueModeActive`、`trackingIssue`、`pendingIssueCommentBodies` 彼此共享可變狀態,讀者必須在腦中追蹤閉包副作用,主流程的步驟節奏因此變得沉重。",
|
||||||
|
"suggestion": "把留言去向抽成小型 helper(例如 `createCommentSink`),讓 `main()` 只看見 `commentSink.post()`、`commentSink.flushToIssue()`、`commentSink.fallbackToPr()` 這類語意清楚的介面。主流程保留編排,狀態管理移到專責函式,樂句會乾淨許多。",
|
||||||
|
"suggestedCode": "",
|
||||||
|
"id": "F002",
|
||||||
|
"verdicts": {
|
||||||
|
"Paladin": {
|
||||||
|
"exclude": true,
|
||||||
|
"reason": "可排除(重複)。此條指涉 main() 內 issue 模式狀態、暫存佇列與閉包職責混雜,已由既有排除事項與歷史 findings 多次涵蓋。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"reviewer": "Bard",
|
||||||
|
"focus": "style",
|
||||||
|
"badge": "🎼",
|
||||||
|
"severity": "建議",
|
||||||
|
"file": "src/index.js",
|
||||||
|
"startLine": 230,
|
||||||
|
"endLine": 239,
|
||||||
|
"problem": "註解標成「步驟 2:延後執行」,但實際位置夾在快速檢查與步驟 3 之前,後面又在步驟 8 後再次出現「步驟 2(延後執行)」。同一個步驟號在不同位置反覆變奏,雖然註解有解釋,閱讀節拍仍容易打結。",
|
||||||
|
"suggestion": "將流程步驟編號與執行順序拆開命名,例如稱為「舊留言清理(延後)」或「收斂前清理舊留言」,避免用 `步驟 2` 這種線性編號描述一個實際延後執行的階段。",
|
||||||
|
"suggestedCode": "",
|
||||||
|
"id": "F003",
|
||||||
|
"verdicts": {
|
||||||
|
"Paladin": {
|
||||||
|
"exclude": true,
|
||||||
|
"reason": "可排除(重複)。歷史 findings 已指出流程步驟編號散落且實際順序變成 1、3~8、2、9~10,與本條「步驟 2 延後但仍用線性編號」相同。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"reviewer": "Leo",
|
||||||
|
"focus": "maintainability",
|
||||||
|
"badge": "🧰",
|
||||||
|
"severity": "警告",
|
||||||
|
"file": "src/index.js",
|
||||||
|
"startLine": 166,
|
||||||
|
"endLine": 235,
|
||||||
|
"problem": "`main()` 現在同時負責流程編排、PR 留言、issue 模式暫存、issue 建立、fallback 狀態切換與留言 flush。這段靠 `issueModeActive`、`trackingIssue`、`pendingIssueCommentBodies`、`currentRunCommentIds` 多個閉包變數互相配合,半年後要改「留言要發去哪裡」或「建 issue 失敗怎麼降級」時,很容易漏掉某個狀態轉換,尤其後面收尾 commit、resolve 舊留言、嚴重/其他問題發布都還會讀這些狀態。",
|
||||||
|
"suggestion": "把發布目的地抽成一個小型 publisher 模組或類別,讓 `main()` 只呼叫 `publisher.comment()`、`publisher.ensureIssue()`、`publisher.fallbackToPr()`、`publisher.resolveOldComments()` 這類語意方法。狀態留在 publisher 內部,並補單元測試覆蓋「一般模式、issue 模式有 finding、issue 模式無 finding、建立 issue 失敗降級」四條路徑。",
|
||||||
|
"suggestedCode": "",
|
||||||
|
"id": "F006",
|
||||||
|
"verdicts": {
|
||||||
|
"Paladin": {
|
||||||
|
"exclude": true,
|
||||||
|
"reason": "可排除(命中已知排除事項且重複)。main() 同時承擔留言路由、issue 狀態、fallback 與 flush 的發布狀態管理,已由既有排除事項與歷史 findings 涵蓋。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"reviewer": "Leo",
|
||||||
|
"focus": "maintainability",
|
||||||
|
"badge": "🧰",
|
||||||
|
"severity": "建議",
|
||||||
|
"file": "src/index.js",
|
||||||
|
"startLine": 222,
|
||||||
|
"endLine": 230,
|
||||||
|
"problem": "註解與 log 名稱把「標記舊留言過時」稱為「步驟 2」,但實際執行點被延後到流程後段。這種非時間順序的步驟編號會讓維護者追 log 或對照 README 流程圖時產生認知落差:看到「步驟 2」不再代表第二個發生的動作,而是某個被延後的歷史步驟。",
|
||||||
|
"suggestion": "改用穩定的階段名稱取代數字,例如 `清理舊留言`、`工具偵測`、`diff 摘要`,或重新編號成實際執行順序。若一定要保留舊編號,建議只放在 README 遷移說明,不要散落在程式碼註解與 log label 中。",
|
||||||
|
"suggestedCode": "",
|
||||||
|
"id": "F007",
|
||||||
|
"verdicts": {
|
||||||
|
"Paladin": {
|
||||||
|
"exclude": true,
|
||||||
|
"reason": "可排除(重複)。與 F003 及歷史 findings 指涉同一個延後執行的「步驟 2」仍以線性步驟編號呈現所造成的認知落差。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"reviewer": "Leo",
|
||||||
|
"focus": "maintainability",
|
||||||
|
"badge": "🧰",
|
||||||
|
"severity": "警告",
|
||||||
|
"file": "readme.md",
|
||||||
|
"startLine": 76,
|
||||||
|
"endLine": 131,
|
||||||
|
"problem": "README 內大量手動維護到 `src/branch/develop/...#Lxx` 的精確行號連結。這次變更已經因程式碼位移而更新一整片連結,未來每次插入函式或註解都會造成文件 churn;更糟的是漏改時文件會指到錯誤行,讀者以為文件可信,實際上卻被帶到過期位置。",
|
||||||
|
"suggestion": "避免在手寫 README 維護精確行號。可改連到檔案或章節錨點,或把 API 列表改由文件產生器輸出。若需要固定定位,優先使用語意穩定的錨點或函式章節,而不是會隨程式碼行數漂移的 `#Lxx`。",
|
||||||
|
"suggestedCode": "",
|
||||||
|
"id": "F008",
|
||||||
|
"verdicts": {
|
||||||
|
"Paladin": {
|
||||||
|
"exclude": true,
|
||||||
|
"reason": "可排除(重複)。README 大量手動維護 develop 分支與 #Lxx 行號連結,歷史 findings 已多次記錄相同維護成本與連結漂移風險。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"reviewer": "Mage",
|
||||||
|
"focus": "logic",
|
||||||
|
"badge": "🔮",
|
||||||
|
"severity": "嚴重",
|
||||||
|
"file": "src/index.js",
|
||||||
|
"startLine": 117,
|
||||||
|
"endLine": 120,
|
||||||
|
"problem": "當 PR 審查出嚴重問題,但結果 commit/push 失敗時,`commitFindings` 只回傳 `false`。新版主流程又改成「本輪審查不因嚴重問題直接 exit 1,而是依賴下一輪讀到 `[failure]` commit 才失敗」。最小情境:`severe.length > 0`、token 權限不足或 push 競態導致 `commitAndPushFindings` 丟錯;此時沒有 `[failure]` commit、也不會有下一輪快速回報,但本輪仍可能以 0 結束,PR 檢查會在存在嚴重問題時通過。",
|
||||||
|
"suggestion": "嚴重問題存在時,若 failure 結果 commit 沒有成功產生,必須讓本輪直接回傳 1。可保留「成功 push failure commit 時本輪回傳 0、下一輪失敗」的設計,但 push 失敗不可靜默通過。",
|
||||||
|
"suggestedCode": "const result = severe.length === 0 ? 'success' : 'failure';\nconst committed = commitFindings({ cwd, ctx, files: filesToCommit, result });\nif (result === 'failure' && !committed) {\n log('收尾', 'ERR', '有嚴重問題但無法推送 failure 結果 commit,本輪直接失敗。');\n return 1;\n}\nreturn 0;",
|
||||||
|
"id": "F010",
|
||||||
|
"verdicts": {
|
||||||
|
"Paladin": {
|
||||||
|
"exclude": true,
|
||||||
|
"reason": "可排除(重複)。此條與 F001 指涉同一風險:嚴重 finding 存在時 failure 結果 commit/push 失敗,可能使本輪檢查仍以成功結束。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"reviewer": "Maya",
|
||||||
|
"focus": "testing",
|
||||||
|
"badge": "🧪",
|
||||||
|
"severity": "警告",
|
||||||
|
"file": "src/index.js",
|
||||||
|
"startLine": 163,
|
||||||
|
"endLine": 437,
|
||||||
|
"problem": "建問題模式被大幅改寫:情境留言先暫存、只有 kept finding 才建 issue、建立失敗會 fallback 回 PR、嚴重/非嚴重 finding 會改發到 issue、最後還要回貼追蹤 issue 連結與設定相依關係。但目前新增測試只覆蓋了少數 helper,沒有驗證 `main()` 在這些分支下的實際副作用。這些行為沒經過試煉,等於還不知道留言會不會發錯地方、fallback 後會不會漏清舊留言、或無 finding 時是否真的靜默通過。",
|
||||||
|
"suggestion": "請補 `src/index.js` 的流程層級測試,mock `gitea`、`review`、`agents`、`gitrepo` 等依賴,至少覆蓋:\n\n| 情境 | 應驗證 |\n| --- | --- |\n| `createIssue=true` 且 `kept.length===0` | 不建 issue、不發 PR 留言、暫存情境留言不外洩 |\n| `createIssue=true` 且有 finding | 先建 issue,再依序 flush 工具/diff/角色留言,finding 發到 issue,PR 只留下追蹤 issue 連結 |\n| 建 issue 或寫入 issue 失敗 | fallback 後情境留言改發 PR,後續使用一般模式留言與舊留言清理 |\n| 嚴重 finding | 結果 commit 標記為 failure,但本輪 `main()` 回傳 0,下一輪才由 bot commit 回報 1 |",
|
||||||
|
"suggestedCode": "",
|
||||||
|
"id": "F011",
|
||||||
|
"verdicts": {
|
||||||
|
"Paladin": {
|
||||||
|
"exclude": true,
|
||||||
|
"reason": "可排除(重複)。歷史 findings 已涵蓋建問題模式的暫存留言、只在有 finding 時建 issue、fallback、嚴重/非嚴重分流、PR 回貼與靜默通過等核心分支缺少流程測試。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"reviewer": "Maya",
|
||||||
|
"focus": "testing",
|
||||||
|
"badge": "🧪",
|
||||||
|
"severity": "警告",
|
||||||
|
"file": "src/lib/gitrepo.js",
|
||||||
|
"startLine": 298,
|
||||||
|
"endLine": 355,
|
||||||
|
"problem": "`commitAndPushFindings` 的推送行為改成一律走 `pushWithCredential`,並宣稱 token 不進 argv、會清掉 checkout 的 extraheader、只接受同一 Gitea origin 的 `.git` URL。這是安全與 CI 觸發都很關鍵的失敗路徑,但目前 `test/gitrepo.test.js` 只測了分支名稱檢查,沒有驗證推送時的 argv/env,也沒有驗證遠端 URL 不符時會停止。這段若改壞,測試不會提醒我們 token 可能出現在命令列或推送根本沒用 PAT 身分。",
|
||||||
|
"suggestion": "請補針對 `commitAndPushFindings`/`pushWithCredential` 的測試。建議用可替換的 `execFileSync` seam 或測試專用注入方式,斷言:\n\n| 情境 | 斷言方向 |\n| --- | --- |\n| 正常推送 | `git push` argv 只含不帶帳密的 `remoteUrl` 與 refspec |\n| 正常推送 | env 含 `GIT_CONFIG_COUNT=2`,先清空 `http.<origin>/.extraheader`,再注入 `Authorization: Basic ...` |\n| `remoteUrl` origin 不符或非 `.git` | 拋出固定錯誤且不執行 push |\n| push 失敗 | 對外錯誤訊息不含 token、remote URL 或 argv |",
|
||||||
|
"suggestedCode": "",
|
||||||
|
"id": "F012",
|
||||||
|
"verdicts": {
|
||||||
|
"Paladin": {
|
||||||
|
"exclude": true,
|
||||||
|
"reason": "可排除(重複)。歷史 findings 已記錄 commitAndPushFindings/pushWithCredential 的認證推送路徑、argv/env、遠端目標檢查與失敗訊息遮蔽缺少測試。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"reviewer": "Maya",
|
||||||
|
"focus": "testing",
|
||||||
|
"badge": "🧪",
|
||||||
|
"severity": "警告",
|
||||||
|
"file": "src/lib/gitrepo.js",
|
||||||
|
"startLine": 130,
|
||||||
|
"endLine": 188,
|
||||||
|
"problem": "`resolveMergeBase` 新增了多階段 fetch 補歷史流程:先 fetch base、首次 merge-base、再 deepen base、deepen PR HEAD、必要時 unshallow,且每個策略成功後要立即重試並短路返回。現有測試只驗證不安全 `baseRef` 會在 fetch 前被拒絕,沒有測到淺層 checkout、首次失敗後補抓成功、策略失敗繼續下一個、全部失敗時診斷訊息等邊界。這正是容易 off-by-one 或順序錯的流程,現在還沒有測試保護。",
|
||||||
|
"suggestion": "請補資料驅動的 `resolveMergeBase` 測試,mock git 執行結果來驗證:首次 merge-base 成功時不跑 deepen;deepen base 後成功會立刻回傳;deepen PR HEAD 使用目前 `HEAD` SHA 而不是遠端符號 `HEAD`;非 shallow repo 不呼叫 `--unshallow`;全部策略失敗時錯誤包含各策略診斷且保留 cause。",
|
||||||
|
"suggestedCode": "",
|
||||||
|
"id": "F013",
|
||||||
|
"verdicts": {
|
||||||
|
"Paladin": {
|
||||||
|
"exclude": true,
|
||||||
|
"reason": "可排除(重複)。resolveMergeBase 多階段 fetch、淺層與非淺層路徑、策略停止條件、全部失敗診斷與 cause 缺少測試,已由歷史 findings 涵蓋。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,280 @@
|
|||||||
|
{
|
||||||
|
"generatedAt": "2026/07/21 16:30:12",
|
||||||
|
"commitSha": "43ad2b56d27429aa3c812522dc1d4fedce4a9b76",
|
||||||
|
"prNumber": 6,
|
||||||
|
"tool": {
|
||||||
|
"name": "codex",
|
||||||
|
"version": "codex-cli 0.144.6",
|
||||||
|
"model": "gpt-5.5"
|
||||||
|
},
|
||||||
|
"findings": [
|
||||||
|
{
|
||||||
|
"reviewer": "Mage",
|
||||||
|
"focus": "logic",
|
||||||
|
"badge": "🔮",
|
||||||
|
"severity": "嚴重",
|
||||||
|
"file": "src/index.js",
|
||||||
|
"startLine": 134,
|
||||||
|
"endLine": 139,
|
||||||
|
"problem": "這裡把「本輪審查」改成即使找到嚴重 finding 也回傳 0,並依賴後續 `[ai-review-bot][failure]` 結果 commit 觸發下一輪才讓檢查失敗。最小重現情境:PR 內有 1 條嚴重問題,但 `commitFindings()` 因分支保護、token 無 push 權限、遠端競態或 PAT 無法觸發 CI 而回傳 false;本輪仍成功結束,且沒有下一輪 failure commit 可被步驟 1 讀到,嚴重問題就被靜默放行。未驗證「結果 commit 一定成功且一定觸發下一輪」這個假設時,它就是流程成敗判定的單點失效。",
|
||||||
|
"suggestion": "嚴重 finding 已確認後,若 failure 結果 commit/push 沒有成功產生,就應在本輪直接回傳 1;只有在確認 failure commit 已成功推送時,才可把失敗狀態交給下一輪快速回報。也就是:`severe.length > 0 && !resultCommitPushed` 必須阻擋。",
|
||||||
|
"suggestedCode": "const result = severe.length === 0 ? 'success' : 'failure';\nlet pushed = false;\nif (filesToCommit.length > 0) {\n pushed = commitFindings({ cwd, ctx, files: filesToCommit, result });\n}\n\nif (severe.length > 0 && !pushed) {\n log('收尾', 'ERR', '已有嚴重問題,但 failure 結果 commit 未成功產生;本輪直接以失敗收場。');\n return 1;\n}\n\nreturn 0;",
|
||||||
|
"id": "F009",
|
||||||
|
"verdicts": {
|
||||||
|
"Paladin": {
|
||||||
|
"exclude": false,
|
||||||
|
"reason": "保留。此條指控嚴重 finding 依賴結果 commit 觸發下一輪才失敗,且 commit/push 失敗時本輪可能靜默通過;既有排除事項未涵蓋此成敗判定風險。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"reviewer": "Mage",
|
||||||
|
"focus": "logic",
|
||||||
|
"badge": "🔮",
|
||||||
|
"severity": "警告",
|
||||||
|
"file": "src/index.js",
|
||||||
|
"startLine": 201,
|
||||||
|
"endLine": 209,
|
||||||
|
"problem": "`createIssueAndFlushBufferedComments()` 先建立 `trackingIssue`,再逐則寫入暫存留言;但只要其中一則留言失敗,外層 catch 會呼叫 `fallbackToPrComments()`,把整批 `pendingIssueCommentBodies` 全部改貼回 PR。最小重現情境:追蹤 issue 建立成功,第一則工具留言也成功寫入 issue,第二則 diff 留言 API 回 500;流程降級後 PR 會收到全部暫存留言,而已建立的 issue 仍殘留第一則留言、沒有後續 finding、也可能沒有 PR 連結或相依關係。這會留下部分成功、部分降級的不一致狀態。",
|
||||||
|
"suggestion": "flush 時應在每則留言成功後立刻從 pending 佇列移除,並明確處理「issue 已建立但 flush 失敗」的狀態:要嘛繼續沿用已建立 issue 並讓後續失敗冒泡,要嘛在降級前補一則 PR 診斷/連結並避免重貼已成功寫入 issue 的留言。",
|
||||||
|
"suggestedCode": "while (pendingIssueCommentBodies.length > 0) {\n const body = pendingIssueCommentBodies[0];\n await gitea.createCommentOnIssue(ctx, trackingIssue.number, body);\n pendingIssueCommentBodies.shift();\n}",
|
||||||
|
"id": "F010",
|
||||||
|
"verdicts": {
|
||||||
|
"Paladin": {
|
||||||
|
"exclude": false,
|
||||||
|
"reason": "保留。既有排除事項涵蓋 issue 建立後留言失敗導致重跑重複 issue,但本條另指出 flush 部分成功後 fallback 會把整批 pending 留言改貼 PR,造成 issue 與 PR 狀態不一致;不是單純重複。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"reviewer": "Bard",
|
||||||
|
"focus": "style",
|
||||||
|
"badge": "🎼",
|
||||||
|
"severity": "建議",
|
||||||
|
"file": "action.yml",
|
||||||
|
"startLine": 3,
|
||||||
|
"endLine": 3,
|
||||||
|
"problem": "手動維護的「更新時間」已與本次檔案標示的最後更新時間不同步;樂譜開頭的拍號一錯,讀者後面每段註解都會多一分懷疑。同樣的不協調也出現在 `readme.md` 與 `src/index.js` 的 banner/文件時間。",
|
||||||
|
"suggestion": "移除這類容易走調的手動時間戳,或改由發布流程自動產生。若一定要保留,請讓所有檔案的時間標示與本次變更一致。",
|
||||||
|
"suggestedCode": "",
|
||||||
|
"id": "F001",
|
||||||
|
"verdicts": {
|
||||||
|
"Paladin": {
|
||||||
|
"exclude": false,
|
||||||
|
"reason": "保留。已知排除事項與歷史 findings 未涵蓋手動更新時間不同步;目前也無足夠原始碼證據可判定為誤報。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"reviewer": "Bard",
|
||||||
|
"focus": "style",
|
||||||
|
"badge": "🎼",
|
||||||
|
"severity": "建議",
|
||||||
|
"file": "src/index.js",
|
||||||
|
"startLine": 199,
|
||||||
|
"endLine": 199,
|
||||||
|
"problem": "`createIssueAndFlushBufferedComments` 這個名稱把「建立 issue」與「flush 暫存留言」兩個實作細節硬串在一起,像一句過長的歌詞;呼叫點讀起來偏機械,沒有清楚表達業務意圖。",
|
||||||
|
"suggestion": "改成較語意化的命名,例如 `openTrackingIssue` 或 `createTrackingIssueWithContext`,讓讀者先理解目的,再從函式內容看見 flush 的細節。",
|
||||||
|
"suggestedCode": "",
|
||||||
|
"id": "F004",
|
||||||
|
"verdicts": {
|
||||||
|
"Paladin": {
|
||||||
|
"exclude": false,
|
||||||
|
"reason": "保留。此條針對 createIssueAndFlushBufferedComments 的命名語意與可讀性,未明確命中既有排除事項;與先前 ensureIssueCreated 暗示冪等的問題不完全相同。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"reviewer": "Maya",
|
||||||
|
"focus": "testing",
|
||||||
|
"badge": "🧪",
|
||||||
|
"severity": "建議",
|
||||||
|
"file": "src/lib/gitref.js",
|
||||||
|
"startLine": 12,
|
||||||
|
"endLine": 24,
|
||||||
|
"problem": "assertSafeBranchRef 目前只測了一個正常分支與一個 ../../ 路徑穿越案例;但這個函式承擔 refspec 安全邊界,新增的空值、前後斜線、反斜線、以及 git check-ref-format 拒絕的格式都沒有案例。邊界沒被驗證時,未來調整條件很容易放過不合法 ref。",
|
||||||
|
"suggestion": "補上表格測試,至少涵蓋空字串、純空白、/feature、feature/、feature\\\\x、feature..x、feature.lock、feature@{x},並斷言錯誤訊息能區分「不安全」與「不合法 git 分支名稱」。",
|
||||||
|
"suggestedCode": "",
|
||||||
|
"id": "F014",
|
||||||
|
"verdicts": {
|
||||||
|
"Paladin": {
|
||||||
|
"exclude": false,
|
||||||
|
"reason": "保留。此條針對 assertSafeBranchRef 的 refspec 安全邊界測試不足,未見已知排除事項或歷史 findings 明確涵蓋;證據不足以排除。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"excluded": [
|
||||||
|
{
|
||||||
|
"reviewer": "Bard",
|
||||||
|
"focus": "style",
|
||||||
|
"badge": "🎼",
|
||||||
|
"severity": "建議",
|
||||||
|
"file": "readme.md",
|
||||||
|
"startLine": 48,
|
||||||
|
"endLine": 48,
|
||||||
|
"problem": "Mermaid 節點代號從 `N8` 跳回 `N2`,雖然流程語意是「步驟 2 延後」,但原始碼讀起來像旋律突然倒帶;維護者在對照圖與步驟時容易被代號順序絆住。",
|
||||||
|
"suggestion": "節點 id 建議改用語意名稱,而把顯示文字保留步驟編號。例如 `ResolveOldComments[2 延後將舊留言標記解決...]`,讓圖的原始碼與顯示內容各自清楚。",
|
||||||
|
"suggestedCode": "",
|
||||||
|
"id": "F002",
|
||||||
|
"verdicts": {
|
||||||
|
"Paladin": {
|
||||||
|
"exclude": true,
|
||||||
|
"reason": "可排除(重複)。歷史 findings 已指出流程步驟編號與實際順序、README 流程圖及文件對照會產生認知落差;本條 Mermaid 節點代號問題屬同一類指控。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"reviewer": "Bard",
|
||||||
|
"focus": "style",
|
||||||
|
"badge": "🎼",
|
||||||
|
"severity": "警告",
|
||||||
|
"file": "src/index.js",
|
||||||
|
"startLine": 167,
|
||||||
|
"endLine": 235,
|
||||||
|
"problem": "`main()` 內新增了建 issue 模式狀態、暫存佇列與三個帶長篇 JSDoc 的閉包,讓主流程的旋律被大量伴奏蓋過。這段同時管理 `issueModeActive`、`trackingIssue`、`pendingIssueCommentBodies` 與 PR 留言 id,可讀性負擔明顯升高。",
|
||||||
|
"suggestion": "把留言路由與建 issue 暫存邏輯抽成小型 helper(例如 `createCommentRouter`),`main()` 只保留流程編排;JSDoc 也移到 helper 旁,讓主流程步驟重新一眼可讀。",
|
||||||
|
"suggestedCode": "",
|
||||||
|
"id": "F003",
|
||||||
|
"verdicts": {
|
||||||
|
"Paladin": {
|
||||||
|
"exclude": true,
|
||||||
|
"reason": "可排除(重複)。已知排除事項與歷史 findings 已涵蓋 main() 內留言路由、issue 狀態、暫存佇列與發布職責耦合造成可讀性與維護負擔。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"reviewer": "Bard",
|
||||||
|
"focus": "style",
|
||||||
|
"badge": "🎼",
|
||||||
|
"severity": "建議",
|
||||||
|
"file": "src/lib/gitrepo.js",
|
||||||
|
"startLine": 121,
|
||||||
|
"endLine": 128,
|
||||||
|
"problem": "`strategies` 以陣列位置承載語意,`[label, ...args]` 雖簡短,卻讓每個元素的第二欄之後全靠讀者猜是 git argv;這裡的可讀性像沒有小節線的樂譜。",
|
||||||
|
"suggestion": "改成物件陣列,明確標出 `label` 與 `args`,可降低後續新增 fetch 策略時的閱讀成本。",
|
||||||
|
"suggestedCode": "const strategies = [\n { label: 'deepen base', args: ['fetch', '--no-tags', '--deepen=1000', 'origin', `+refs/heads/${baseRef}:refs/remotes/${remoteBase}`] },\n { label: 'deepen PR HEAD', args: ['fetch', '--no-tags', '--deepen=1000', 'origin', headSha] },\n];",
|
||||||
|
"id": "F005",
|
||||||
|
"verdicts": {
|
||||||
|
"Paladin": {
|
||||||
|
"exclude": true,
|
||||||
|
"reason": "可排除(重複)。歷史 finding 已針對 resolveMergeBase 內 strategies 與補救策略編排使閱讀節奏偏密提出問題;本條 tuple 可讀性屬同一段策略結構的細項。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"reviewer": "Leo",
|
||||||
|
"focus": "maintainability",
|
||||||
|
"badge": "🧰",
|
||||||
|
"severity": "警告",
|
||||||
|
"file": "src/index.js",
|
||||||
|
"startLine": 163,
|
||||||
|
"endLine": 231,
|
||||||
|
"problem": "`main()` 這次把一般模式/建問題模式/降級模式的留言去向都塞進閉包狀態:`issueModeActive`、`trackingIssue`、`pendingIssueCommentBodies`、`currentRunCommentIds` 彼此耦合。半年後要新增一種落地方式或調整「何時清舊留言」時,維護者必須同時追多個可變狀態與後續多個 `if (issueModeActive)` 分支,很容易漏掉 flush、清空、登錄留言 id 或 fallback 後的收尾行為。",
|
||||||
|
"suggestion": "把留言目的地抽成小型物件,讓主流程只呼叫 `commentSink.postContext()`、`commentSink.finalizeAfterFindings()`、`commentSink.postFinding()` 這類語意方法。一般 PR、issue buffering、fallback 的狀態轉換集中在同一個模組或工廠函式內,`main()` 保持審查流程編排,不承擔留言狀態機。",
|
||||||
|
"suggestedCode": "",
|
||||||
|
"id": "F006",
|
||||||
|
"verdicts": {
|
||||||
|
"Paladin": {
|
||||||
|
"exclude": true,
|
||||||
|
"reason": "可排除(重複)。與 F003 及既有排除事項相同,均指向 main() 以可變閉包狀態承擔留言目的地、issue 生命週期與 fallback 狀態機。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"reviewer": "Leo",
|
||||||
|
"focus": "maintainability",
|
||||||
|
"badge": "🧰",
|
||||||
|
"severity": "警告",
|
||||||
|
"file": "src/index.js",
|
||||||
|
"startLine": 232,
|
||||||
|
"endLine": 241,
|
||||||
|
"problem": "流程註解把「將舊留言標記為解決」稱為「步驟 2(延後執行)」,但實際執行點在審查結果產生後、接近原本步驟 9 前。這種「編號是 2、時間點是 8 後」的設計已經擴散到多個檔案的 JSDoc 與 log 描述,未來查 CI log 或維護流程圖時會產生認知落差:看到 `步驟2` 不代表它真的發生在第二步。",
|
||||||
|
"suggestion": "不要用固定序號承載流程語意。建議改成穩定階段名稱,例如 `清理舊留言`、`工具偵測`、`diff整理`,或重新編號為實際執行順序並在文件說明「清理舊留言延後到結果產生後」。這樣 log、JSDoc、README 流程圖才不會互相背離。",
|
||||||
|
"suggestedCode": "",
|
||||||
|
"id": "F007",
|
||||||
|
"verdicts": {
|
||||||
|
"Paladin": {
|
||||||
|
"exclude": true,
|
||||||
|
"reason": "可排除(重複)。歷史 findings 已明確記錄步驟編號散落於 log、JSDoc、README 且實際順序變成 1、3 到 8、2、9 到 10 的維護風險。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"reviewer": "Leo",
|
||||||
|
"focus": "maintainability",
|
||||||
|
"badge": "🧰",
|
||||||
|
"severity": "建議",
|
||||||
|
"file": "src/lib/gitrepo.js",
|
||||||
|
"startLine": 103,
|
||||||
|
"endLine": 160,
|
||||||
|
"problem": "`resolveMergeBase()` 內同時負責驗證 base ref、fetch base、重試 merge-base、補抓淺層歷史、累積診斷與組錯誤訊息。這些都和「取得 merge-base」有關,但現在全部攤在同一個函式裡,策略陣列、診斷格式與 git 操作細節混在一起;未來要新增 fetch 策略或改診斷文字時,容易不小心改壞主流程判斷。",
|
||||||
|
"suggestion": "把補抓策略與重試邏輯拆成私有 helper,例如 `fetchBaseRef()`、`mergeBaseOrNull()`、`shallowFetchStrategies()`。主函式保留高階流程:驗證 ref → 更新 base → 嘗試 merge-base → 逐一套用策略 → 丟出診斷錯誤。",
|
||||||
|
"suggestedCode": "",
|
||||||
|
"id": "F008",
|
||||||
|
"verdicts": {
|
||||||
|
"Paladin": {
|
||||||
|
"exclude": true,
|
||||||
|
"reason": "可排除(重複)。歷史 finding 已指出 resolveMergeBase 同時負責驗證、fetch 策略編排、診斷與錯誤包裝,難以分辨主流程與補救策略。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"reviewer": "Maya",
|
||||||
|
"focus": "testing",
|
||||||
|
"badge": "🧪",
|
||||||
|
"severity": "警告",
|
||||||
|
"file": "src/index.js",
|
||||||
|
"startLine": 164,
|
||||||
|
"endLine": 232,
|
||||||
|
"problem": "建問題模式新增了「先暫存情境留言、確定有保留 finding 才建 issue、建 issue 失敗時降級回 PR 留言」這一整段流程,但目前測試只覆蓋了部分 helper,沒有驗證主流程在 create-issue=true 下的分流行為。這代表像「無保留問題時不應建 issue/不應留言」、「建立 issue 失敗時應把 pending 留言補回 PR」、「trackingIssue 建立後後續留言應改送 issue」這些行為都還沒通過試煉。",
|
||||||
|
"suggestion": "建議把 main 流程拆出可注入 gitea/review/agents/gitrepo 的 orchestrator,或至少匯出可測的流程函式,補上 create-issue=true 的案例:1. kept=[] 時不呼叫 createIssue/createIssueComment;2. kept>0 時先 flush pending issue comments 再發 finding;3. createIssue 拋錯時 fallbackToPrComments 會發回 PR 並記錄 currentRunCommentIds;4. issueModeActive 降級後會走一般 PR 留言與 resolveOldComments。",
|
||||||
|
"suggestedCode": "",
|
||||||
|
"id": "F011",
|
||||||
|
"verdicts": {
|
||||||
|
"Paladin": {
|
||||||
|
"exclude": true,
|
||||||
|
"reason": "可排除(重複)。歷史 findings 已涵蓋建問題模式核心流程、暫存留言、issue 建立條件、發布分流、外部 API 狀態切換與降級路徑缺少測試。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"reviewer": "Maya",
|
||||||
|
"focus": "testing",
|
||||||
|
"badge": "🧪",
|
||||||
|
"severity": "警告",
|
||||||
|
"file": "src/lib/gitrepo.js",
|
||||||
|
"startLine": 104,
|
||||||
|
"endLine": 150,
|
||||||
|
"problem": "resolveMergeBase 新增了多階段 fetch/deepen/unshallow fallback 與診斷錯誤,但測試只驗證不安全 baseRef 會被拒絕,沒有驗證任何成功或失敗 fallback 路徑。這段是 diff 基準的核心邏輯,若 shallow checkout 下 deepen PR HEAD 用錯 ref、策略順序跑錯,或全部失敗時診斷不正確,現有測試都抓不到。",
|
||||||
|
"suggestion": "建議用假的 git 執行層或臨時 git repo 補測:首次 merge-base 成功時不跑後續策略;首次失敗但 deepen base 後成功;deepen base 失敗會繼續 deepen PR HEAD;shallow repo 才嘗試 --unshallow;全部失敗時錯誤訊息包含各策略診斷且保留 cause。",
|
||||||
|
"suggestedCode": "",
|
||||||
|
"id": "F012",
|
||||||
|
"verdicts": {
|
||||||
|
"Paladin": {
|
||||||
|
"exclude": true,
|
||||||
|
"reason": "可排除(重複)。歷史 findings 已針對 resolveMergeBase 多階段 fetch、淺層與非淺層分支、策略停止條件、降級與最終診斷缺少測試提出相同問題。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"reviewer": "Maya",
|
||||||
|
"focus": "testing",
|
||||||
|
"badge": "🧪",
|
||||||
|
"severity": "警告",
|
||||||
|
"file": "src/lib/gitrepo.js",
|
||||||
|
"startLine": 272,
|
||||||
|
"endLine": 322,
|
||||||
|
"problem": "commitAndPushFindings 改成一律透過 pushWithCredential 用 PAT extraheader 推送,且新增 headRef 安全檢查與固定錯誤遮蔽;但目前 gitrepo 測試沒有覆蓋 commitAndPushFindings/pushWithCredential 的推送行為。這讓「token 不進 argv」、「清掉 checkout 既有 extraheader」、「遠端 URL 不符時拒絕」、「push 失敗不洩漏 URL/token」這些失敗與安全邊界都沒有被驗證。",
|
||||||
|
"suggestion": "建議以 stub child_process.execFileSync 或可注入 git runner 的方式補測:commit 後呼叫 git push 的 argv 不含 token;env 內含 GIT_CONFIG_COUNT 與 Authorization extraheader;headRef 不安全時在 git add/commit/push 前拋錯;remote origin 不符與 push 失敗時錯誤訊息不包含 token、repo URL 或 Basic header。",
|
||||||
|
"suggestedCode": "",
|
||||||
|
"id": "F013",
|
||||||
|
"verdicts": {
|
||||||
|
"Paladin": {
|
||||||
|
"exclude": true,
|
||||||
|
"reason": "可排除(重複)。歷史 findings 已涵蓋 commitAndPushFindings 與 pushWithCredential 的推送策略、認證遮蔽、失敗路徑與 token 不外洩等測試缺口。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
+12
-15
@@ -42,13 +42,12 @@ jobs:
|
|||||||
uses: ./
|
uses: ./
|
||||||
# 傳入 action inputs。
|
# 傳入 action inputs。
|
||||||
with:
|
with:
|
||||||
# Gitea Actions 自動注入的 repo 範圍 token,用於 PR 留言與 findings 寫回。
|
# PR 留言與 findings 寫回用的 token(呼叫端以 secrets 傳入)。
|
||||||
token: ${{ gitea.token }}
|
token: ${{ secrets.TOKEN }}
|
||||||
# 啟用建問題模式:審查內容改發到追蹤 issue,並在 PR 回貼 issue 連結。
|
# 啟用建問題模式:審查內容改發到追蹤 issue,並在 PR 回貼 issue 連結。
|
||||||
create-issue: 'true'
|
create-issue: 'true'
|
||||||
# 推送 findings/exclusions commit 用的 PAT:以 PAT 身分推送才會讓結果 commit 再觸發 CI,
|
# 指定 AI 模型:CI 測試固定用 Antigravity 最省模型以降低消耗。
|
||||||
# 由步驟 1 快速回報把結果蓋到新 head,避免自動 token 推送不觸發而卡合併。
|
model: gemini-3.5-flash
|
||||||
push-token: ${{ secrets.TOKEN }}
|
|
||||||
# Codex 工具環境測試 job。
|
# Codex 工具環境測試 job。
|
||||||
test-codex:
|
test-codex:
|
||||||
# Job 在 workflow UI 顯示的名稱。
|
# Job 在 workflow UI 顯示的名稱。
|
||||||
@@ -73,13 +72,12 @@ jobs:
|
|||||||
uses: ./
|
uses: ./
|
||||||
# 傳入 action inputs。
|
# 傳入 action inputs。
|
||||||
with:
|
with:
|
||||||
# Gitea Actions 自動注入的 repo 範圍 token,用於 PR 留言與 findings 寫回。
|
# PR 留言與 findings 寫回用的 token(呼叫端以 secrets 傳入)。
|
||||||
token: ${{ gitea.token }}
|
token: ${{ secrets.TOKEN }}
|
||||||
# 啟用建問題模式:審查內容改發到追蹤 issue,並在 PR 回貼 issue 連結。
|
# 啟用建問題模式:審查內容改發到追蹤 issue,並在 PR 回貼 issue 連結。
|
||||||
create-issue: 'true'
|
create-issue: 'true'
|
||||||
# 推送 findings/exclusions commit 用的 PAT:以 PAT 身分推送才會讓結果 commit 再觸發 CI,
|
# 指定 AI 模型:CI 測試固定用 Codex 最省模型以降低消耗。
|
||||||
# 由步驟 1 快速回報把結果蓋到新 head,避免自動 token 推送不觸發而卡合併。
|
model: gpt-5.5
|
||||||
push-token: ${{ secrets.TOKEN }}
|
|
||||||
# Claude 工具環境測試 job。
|
# Claude 工具環境測試 job。
|
||||||
test-claude:
|
test-claude:
|
||||||
# Job 在 workflow UI 顯示的名稱。
|
# Job 在 workflow UI 顯示的名稱。
|
||||||
@@ -104,10 +102,9 @@ jobs:
|
|||||||
uses: ./
|
uses: ./
|
||||||
# 傳入 action inputs。
|
# 傳入 action inputs。
|
||||||
with:
|
with:
|
||||||
# Gitea Actions 自動注入的 repo 範圍 token,用於 PR 留言與 findings 寫回。
|
# PR 留言與 findings 寫回用的 token(呼叫端以 secrets 傳入)。
|
||||||
token: ${{ gitea.token }}
|
token: ${{ secrets.TOKEN }}
|
||||||
# 啟用建問題模式:審查內容改發到追蹤 issue,並在 PR 回貼 issue 連結。
|
# 啟用建問題模式:審查內容改發到追蹤 issue,並在 PR 回貼 issue 連結。
|
||||||
create-issue: 'true'
|
create-issue: 'true'
|
||||||
# 推送 findings/exclusions commit 用的 PAT:以 PAT 身分推送才會讓結果 commit 再觸發 CI,
|
# 指定 AI 模型:Claude job 使用 Opus 4.8。
|
||||||
# 由步驟 1 快速回報把結果蓋到新 head,避免自動 token 推送不觸發而卡合併。
|
model: claude-opus-4-8
|
||||||
push-token: ${{ secrets.TOKEN }}
|
|
||||||
|
|||||||
+4
-15
@@ -16,11 +16,11 @@ author: 'Jeffery'
|
|||||||
# 輸入參數區塊:呼叫端 workflow 以 `with:` 傳入,
|
# 輸入參數區塊:呼叫端 workflow 以 `with:` 傳入,
|
||||||
# runner 會自動注入為 INPUT_* 環境變數(例如 INPUT_TOKEN、INPUT_MODEL、INPUT_CREATE-ISSUE)供主程式讀取。
|
# runner 會自動注入為 INPUT_* 環境變數(例如 INPUT_TOKEN、INPUT_MODEL、INPUT_CREATE-ISSUE)供主程式讀取。
|
||||||
inputs:
|
inputs:
|
||||||
# Gitea API token:用於對 PR 留言審查結果、以及 push 審查結果檔回 repo。
|
# Gitea API token:用於對 PR/issue 留言審查結果,以及 push 審查結果檔(findings/exclusions)回 repo。
|
||||||
token:
|
token:
|
||||||
# 參數用途說明:secrets/vars context 在 action 內不可用,
|
# 參數用途說明:secrets/vars context 在 action 內不可用,故由呼叫端 workflow 以 secrets 傳入。
|
||||||
# 故由呼叫端 workflow 以 secrets.GITHUB_TOKEN 傳入。
|
# 建議傳入能觸發 CI 的 PAT;自動 token 推送結果 commit 時可能不會再觸發 workflow。
|
||||||
description: 'Gitea API token(PR 留言與 push findings 用;呼叫端以 secrets.GITHUB_TOKEN 傳入)'
|
description: 'Gitea API token(PR/issue 留言與 push findings 用;建議以能觸發 CI 的 PAT 由 secrets 傳入)'
|
||||||
# 必填:缺少 token 無法呼叫 Gitea API,action 無法運作。
|
# 必填:缺少 token 無法呼叫 Gitea API,action 無法運作。
|
||||||
required: true
|
required: true
|
||||||
# 指定 AI 工具使用的模型名稱。
|
# 指定 AI 工具使用的模型名稱。
|
||||||
@@ -41,17 +41,6 @@ inputs:
|
|||||||
required: false
|
required: false
|
||||||
# 預設為字串 'false',代表不啟用建問題模式(主程式只認字串 'true' 才啟用)。
|
# 預設為字串 'false',代表不啟用建問題模式(主程式只認字串 'true' 才啟用)。
|
||||||
default: 'false'
|
default: 'false'
|
||||||
# 推送用 PAT:推送 findings/exclusions commit 時改以此 token 進行。
|
|
||||||
push-token:
|
|
||||||
# 參數用途說明:以自動 token(gitea.token / GITHUB_TOKEN)推送的 commit 不會再觸發 CI,
|
|
||||||
# 導致新 head 缺檢查而卡合併;改用 PAT 推送會讓 PR 的 synchronize 事件再觸發 CI,
|
|
||||||
# 由主程式步驟 1 快速回報([success]/[failure])廉價地把結果蓋到新 head。
|
|
||||||
# 呼叫端以 secrets 傳入(例如 secrets.TOKEN)。留空=退回以 token 走 origin 推送(不會再觸發)。
|
|
||||||
description: '推送 findings/exclusions commit 用的 PAT(讓 CI 再觸發;呼叫端以 secrets 傳入;留空=退回 token 推送、不再觸發)'
|
|
||||||
# 選填:未指定時退回以 token 推送。
|
|
||||||
required: false
|
|
||||||
# 預設為空字串,代表不使用專用推送 PAT。
|
|
||||||
default: ''
|
|
||||||
# 執行方式區塊:宣告本 action 為 node action 及其進入點。
|
# 執行方式區塊:宣告本 action 為 node action 及其進入點。
|
||||||
runs:
|
runs:
|
||||||
# 以 Node.js 24 runtime 直接在 runner 上執行(非 Docker 容器、非 composite)。
|
# 以 Node.js 24 runtime 直接在 runner 上執行(非 Docker 容器、非 composite)。
|
||||||
|
|||||||
+2
-1
@@ -4,7 +4,8 @@
|
|||||||
"description": "AI 多角色 code review:攻擊方找問題、防守方裁決誤報,結果留言到 PR 並保存 findings",
|
"description": "AI 多角色 code review:攻擊方找問題、防守方裁決誤報,結果留言到 PR 並保存 findings",
|
||||||
"main": "src/index.js",
|
"main": "src/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "ncc build src/index.js -o dist"
|
"build": "ncc build src/index.js -o dist",
|
||||||
|
"test": "node --test"
|
||||||
},
|
},
|
||||||
"author": "Jeffery",
|
"author": "Jeffery",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
|
|||||||
@@ -38,16 +38,16 @@ jobs:
|
|||||||
```mermaid
|
```mermaid
|
||||||
flowchart TD
|
flowchart TD
|
||||||
S1[1 判斷 bot commit 標記] -->|命中| E0[直接回報 success/failure]
|
S1[1 判斷 bot commit 標記] -->|命中| E0[直接回報 success/failure]
|
||||||
S1 -->|未命中| S2[2 舊留言標記解決]
|
S1 -->|未命中| N3[3 偵測 AI 工具並留言]
|
||||||
S2 --> S3[3 偵測 AI 工具並留言]
|
N3 --> N4[4 讀 .reviewignore 整理 diff 並留言]
|
||||||
S3 --> S4[4 讀 .reviewignore 整理 diff 並留言]
|
N4 --> N5[5 攻擊方登場留言]
|
||||||
S4 --> S5[5 攻擊方登場留言]
|
N5 --> N6[6 攻擊方 sub agent 並行找問題]
|
||||||
S5 --> S6[6 攻擊方 sub agent 並行找問題]
|
N6 --> N7[7 防守方登場留言]
|
||||||
S6 --> S7[7 防守方登場留言]
|
N7 --> N8[8 防守方裁決 → 保存 findings + 誤判回寫 exclusions.json]
|
||||||
S7 --> S8[8 防守方裁決 → 保存 findings + 誤判回寫 exclusions.json]
|
N8 --> N2[2 延後將舊留言標記解決(成功產生結果後才執行)]
|
||||||
S8 --> S9[9 嚴重問題逐條掛行留言]
|
N2 --> N9[9 嚴重問題逐條掛行留言]
|
||||||
S9 --> S10[10 警告+建議彙整表格留言]
|
N9 --> N10[10 警告+建議彙整表格留言]
|
||||||
S10 --> E1[收尾 commit/push + exit code]
|
N10 --> E1[收尾 commit/push + exit code]
|
||||||
```
|
```
|
||||||
|
|
||||||
## 專案列表
|
## 專案列表
|
||||||
|
|||||||
+113
-83
@@ -72,7 +72,7 @@ function saveFindings({ cwd, ctx, tool, kept, excluded }) {
|
|||||||
* 供下一回合 `main()` 步驟 1 比對辨識、直接回報結果而不重複審查。
|
* 供下一回合 `main()` 步驟 1 比對辨識、直接回報結果而不重複審查。
|
||||||
* 依 `commitAndPushFindings` 的回傳值記錄不同日誌:true=已 commit/push;
|
* 依 `commitAndPushFindings` 的回傳值記錄不同日誌:true=已 commit/push;
|
||||||
* false=檔案無實際變更(空 commit 防護),記「略過 commit/push」。
|
* false=檔案無實際變更(空 commit 防護),記「略過 commit/push」。
|
||||||
* commit/push 失敗(例如與開發者新 commit 競態)時僅記 WRN log,不拋出例外、不改變審查結果。
|
* commit/push 失敗(例如與開發者新 commit 競態)時僅記 WRN log,不拋出例外;呼叫端可依回傳值決定是否阻擋。
|
||||||
*
|
*
|
||||||
* @param {Object} params - 解構參數。
|
* @param {Object} params - 解構參數。
|
||||||
* @param {string} params.cwd - repo 根目錄(workspace)絕對路徑,git 操作在此目錄執行。
|
* @param {string} params.cwd - repo 根目錄(workspace)絕對路徑,git 操作在此目錄執行。
|
||||||
@@ -84,13 +84,14 @@ function saveFindings({ cwd, ctx, tool, kept, excluded }) {
|
|||||||
* @param {string} params.ctx.repository - `owner/repo` 形式的 repo 名稱。
|
* @param {string} params.ctx.repository - `owner/repo` 形式的 repo 名稱。
|
||||||
* @param {string[]} params.files - 要 commit 的檔案 repo 相對路徑陣列(如 findings 檔、`.gitea/ai-review/exclusions.json`);全數無變更時只記 INF 略過。
|
* @param {string[]} params.files - 要 commit 的檔案 repo 相對路徑陣列(如 findings 檔、`.gitea/ai-review/exclusions.json`);全數無變更時只記 INF 略過。
|
||||||
* @param {'success'|'failure'} params.result - 本回合審查結果:success=無嚴重問題、failure=有嚴重問題;會拼進 commit 訊息尾端。
|
* @param {'success'|'failure'} params.result - 本回合審查結果:success=無嚴重問題、failure=有嚴重問題;會拼進 commit 訊息尾端。
|
||||||
* @returns {void} 無回傳值;成敗僅反映在 log 上。
|
* @returns {boolean} true=已 commit/push;false=無變更或 commit/push 失敗。
|
||||||
* @remarks
|
* @remarks
|
||||||
* 使用情境:`main()` 於流程尾端依 `severe.length === 0 ? 'success' : 'failure'` 決定 result、
|
* 使用情境:`main()` 於流程尾端依 `severe.length === 0 ? 'success' : 'failure'` 決定 result、
|
||||||
* 依模式組出 filesToCommit(一般模式:findings 檔+有變更時的 exclusions.json;
|
* 依模式組出 filesToCommit(一般模式:findings 檔+有變更時的 exclusions.json;
|
||||||
* 建問題模式:只有 exclusions.json)後呼叫本函式;另在步驟 4 判定無可審查變更且非建問題模式時,
|
* 建問題模式:只有 exclusions.json)後呼叫本函式;另在步驟 4 判定無可審查變更且非建問題模式時,
|
||||||
* 也會以 result: 'success' 提交空 findings。
|
* 也會以 result: 'success' 提交空 findings。
|
||||||
* 推送以 `ctx.pushToken`(PAT)優先,使結果 commit 再觸發 CI、由步驟 1 快速回報;
|
* 推送一律以 `ctx.token` 的身分進行(不走 runner 的 origin 自動 token);只要 token 是能觸發 CI 的
|
||||||
|
* PAT,結果 commit 就會再觸發 CI、由步驟 1 快速回報;
|
||||||
* 注意 commit 訊息與模組常數 `BOT_COMMIT_PREFIX` 耦合,修改前綴會使步驟 1 的快速回報失效。
|
* 注意 commit 訊息與模組常數 `BOT_COMMIT_PREFIX` 耦合,修改前綴會使步驟 1 的快速回報失效。
|
||||||
*/
|
*/
|
||||||
function commitFindings({ cwd, ctx, files, result }) {
|
function commitFindings({ cwd, ctx, files, result }) {
|
||||||
@@ -101,54 +102,40 @@ function commitFindings({ cwd, ctx, files, result }) {
|
|||||||
message: `${BOT_COMMIT_PREFIX}[${result}]`,
|
message: `${BOT_COMMIT_PREFIX}[${result}]`,
|
||||||
files,
|
files,
|
||||||
token: ctx.token,
|
token: ctx.token,
|
||||||
pushToken: ctx.pushToken,
|
|
||||||
serverUrl: ctx.serverUrl,
|
serverUrl: ctx.serverUrl,
|
||||||
repository: ctx.repository,
|
repository: ctx.repository,
|
||||||
});
|
});
|
||||||
if (committed) {
|
if (committed) {
|
||||||
log('收尾', 'INF', `審查結果檔已 commit 並 push 回 ${ctx.headRef}(結果:${result})。`);
|
log('收尾', 'INF', `審查結果檔已 commit 並 push 回 ${ctx.headRef}(結果:${result})。`);
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
log('收尾', 'INF', '審查結果檔無實際變更,略過 commit/push。');
|
log('收尾', 'INF', '審查結果檔無實際變更,略過 commit/push。');
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// push 失敗(例如與開發者新 commit 競態)時只記錄,不改變審查結果。
|
// push 失敗(例如與開發者新 commit 競態)時只記錄,交由呼叫端依嚴重度決定是否阻擋。
|
||||||
log('收尾', 'WRN', `commit/push 審查結果檔失敗:${err.message}。`);
|
log('收尾', 'WRN', `commit/push 審查結果檔失敗:${err.message}。`);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AI code review 主流程:依固定 10 步驟執行多角色審查,回傳 process exit code。
|
* AI code review 主流程:編排多角色審查、發布審查結果,並回傳 process exit code。
|
||||||
*
|
*
|
||||||
* 流程概要(步驟 2~10 描述一般模式;建問題模式差異見末段):
|
* 一般模式會把審查情境、嚴重問題與警告/建議發布到 PR,並在成功產生本回合結果後才把舊留言標為過時。
|
||||||
* 1. 快速回報 — 最新 commit 若為 ai-review-bot 的結果 commit([success]/[failure]),直接回報 0/1 不重審;
|
* 建問題模式會把審查情境與每條 finding 發到追蹤 issue;沒有保留 finding 時不建立 issue、PR 也不留言。
|
||||||
* 2. 將 PR 既有舊留言標記為解決(跳過本回合留言;建問題模式不執行此步)——
|
* 嚴重 finding 會寫入 failure 結果 commit,警告與建議只建立追蹤資訊,不直接阻擋合併。
|
||||||
* 此步延後到「本回合審查已成功產生結果、即將發布問題留言前」才執行,避免工具偵測/diff/
|
|
||||||
* 攻防裁決任一失敗時舊結果先被清掉卻沒有新結果(一般模式);
|
|
||||||
* 3. 偵測 AI 工具(antigravity/codex/claude)並留言;
|
|
||||||
* 4. 讀 .reviewignore、整理 git diff 並留言(無可審查變更時:留言+保存空 findings,
|
|
||||||
* 一般模式 commit success、建問題模式略過 commit,回傳 0);
|
|
||||||
* 5–6. 攻擊方登場留言、每位攻擊方一個 sub agent 並行找問題;
|
|
||||||
* 7–8. 防守方登場留言、裁決誤報後排序並保存 findings JSON,
|
|
||||||
* 並以 appendExclusions 把誤判/重複問題回寫 .gitea/ai-review/exclusions.json;
|
|
||||||
* 9. 嚴重問題逐條掛在程式碼行上留言;
|
|
||||||
* 10. 警告+建議彙整為單一表格留言;
|
|
||||||
* 建問題模式(input: create-issue):不執行步驟 2、不觸碰 PR 既有留言;步驟 3~10 的所有留言
|
|
||||||
* 改發到追蹤 issue(工具/diff/角色留言先暫存,確定有保留問題後先挑好標籤、連同標籤一次建立 issue
|
|
||||||
* 並寫入暫存留言,嚴重問題與警告+建議再逐條發到該 issue,讓每條問題都能被個別回覆);
|
|
||||||
* 無保留問題或無可審查變更則不建 issue、PR 也完全不留言(靜默通過);
|
|
||||||
* 收束時在 PR 回貼 issue 連結形成雙向關聯,
|
|
||||||
* 並讓 PR 相依於該 issue(addIssueDependency,issue 完成/關閉前 PR 無法合併;需 repo 啟用問題相依功能);
|
|
||||||
* 收尾:組 filesToCommit —— 一般模式 commit findings 檔(+有變更的 exclusions.json)、
|
|
||||||
* 建問題模式只 commit exclusions.json、無檔案可 commit 時略過;
|
|
||||||
* commit 訊息帶結果標記(success=無嚴重問題、failure=有嚴重問題)。
|
|
||||||
*
|
*
|
||||||
* @returns {Promise<number>} process exit code:0=成功(無嚴重問題或無可審查變更、或偵測到 success 標記);
|
* @returns {Promise<number>} process exit code:本輪「審查」一律回傳 0(不因嚴重問題直接讓檢查失敗——
|
||||||
* 1=失敗(有嚴重問題、缺 PR 編號/token、找不到 AI 工具、或偵測到 failure 標記)。
|
* 失敗改由推出的 `[ai-review-bot][failure]` 結果 commit,於下一輪在步驟 1 讀 commit 訊息時回報);
|
||||||
|
* 回傳 1 僅發生於:步驟 1 偵測到 `[ai-review-bot][failure]` 結果 commit,或前置條件不足
|
||||||
|
* (缺 PR 編號/token、找不到 AI 工具)等無法進行審查的情況。
|
||||||
* @remarks
|
* @remarks
|
||||||
* 使用情境:由本檔尾端的頂層呼叫端執行 —— `main().then((code) => process.exit(code))`;
|
* 使用情境:由本檔尾端的頂層呼叫端執行 —— `main().then((code) => process.exit(code))`;
|
||||||
* 非預期例外由頂層 `catch` 記 ERR log 後以 exit code 1 收場,且刻意不 commit 結果標記,
|
* 非預期例外由頂層 `catch` 記 ERR log 後以 exit code 1 收場,且刻意不 commit 結果標記,
|
||||||
* 讓下一次 workflow 觸發時重新完整審查。警告+建議等級的問題不影響成敗,只有「嚴重」會使結果為 failure;
|
* 讓下一次 workflow 觸發時重新完整審查。警告+建議等級不影響結果標記,只有「嚴重」會使結果 commit
|
||||||
* 建問題模式只改變問題明細的落地方式(issue 留言取代 findings 進版控),不改變成敗判定。
|
* 標記為 failure;而「失敗檢查(exit 1)」只由步驟 1 讀到該 failure 結果 commit 時產生,審查本輪不直接 exit 1。
|
||||||
|
* 建問題模式只改變問題明細的落地方式(issue 留言取代 findings 進版控),不改變上述結果標記判定。
|
||||||
*/
|
*/
|
||||||
async function main() {
|
async function main() {
|
||||||
const ctx = loadContext();
|
const ctx = loadContext();
|
||||||
@@ -178,14 +165,15 @@ async function main() {
|
|||||||
|
|
||||||
// 本回合(一般模式)發出的 PR 留言 id:resolveOldComments 標註過時時要跳過這些。
|
// 本回合(一般模式)發出的 PR 留言 id:resolveOldComments 標註過時時要跳過這些。
|
||||||
const currentRunCommentIds = new Set();
|
const currentRunCommentIds = new Set();
|
||||||
// 建問題模式:issue 於「確定有保留問題」後才建立;在那之前的情境留言(工具/diff/角色)
|
// 建問題模式:追蹤 issue 於「確定有保留問題」後才建立;在那之前的情境留言(工具/diff/角色)
|
||||||
// 先暫存於 issueBuffer,建立 issue 後一次寫入。
|
// 先暫存於 pendingIssueCommentBodies,建立 issue 後一次寫入。
|
||||||
const issueBuffer = [];
|
const pendingIssueCommentBodies = [];
|
||||||
let issue = null;
|
let issueModeActive = ctx.createIssue;
|
||||||
|
let trackingIssue = null;
|
||||||
/**
|
/**
|
||||||
* 發布一則審查留言。依模式決定去向:
|
* 發布一則審查留言。依模式決定去向:
|
||||||
* - 一般模式:發到 PR,並記錄留言 id 供 `resolveOldComments` 排除。
|
* - 一般模式:發到 PR,並記錄留言 id 供 `resolveOldComments` 排除。
|
||||||
* - 建問題模式:issue 已建立時發到 issue;尚未建立時先暫存到 `issueBuffer`。
|
* - 建問題模式:追蹤 issue 已建立時發到 issue;尚未建立時先暫存到 `pendingIssueCommentBodies`。
|
||||||
*
|
*
|
||||||
* @param {string} body 要發布的 Markdown 留言內容。
|
* @param {string} body 要發布的 Markdown 留言內容。
|
||||||
* @returns {Promise<Object|null>} 一般模式、或建問題模式且 issue 已建立時回傳 Gitea 留言物件;
|
* @returns {Promise<Object|null>} 一般模式、或建問題模式且 issue 已建立時回傳 Gitea 留言物件;
|
||||||
@@ -194,10 +182,10 @@ async function main() {
|
|||||||
* 使用情境:只在 `main()` 內部使用,處理工具資訊、diff 摘要、角色登場與
|
* 使用情境:只在 `main()` 內部使用,處理工具資訊、diff 摘要、角色登場與
|
||||||
* 警告/建議彙整等留言。若 Gitea API 失敗,例外會往上拋出並由主流程頂層 catch 收斂。
|
* 警告/建議彙整等留言。若 Gitea API 失敗,例外會往上拋出並由主流程頂層 catch 收斂。
|
||||||
*/
|
*/
|
||||||
const postComment = async (body) => {
|
const queueOrPostComment = async (body) => {
|
||||||
if (ctx.createIssue) {
|
if (issueModeActive) {
|
||||||
if (issue) return gitea.createCommentOnIssue(ctx, issue.number, body);
|
if (trackingIssue) return gitea.createCommentOnIssue(ctx, trackingIssue.number, body);
|
||||||
issueBuffer.push(body);
|
pendingIssueCommentBodies.push(body);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const created = await gitea.createIssueComment(ctx, body);
|
const created = await gitea.createIssueComment(ctx, body);
|
||||||
@@ -206,24 +194,39 @@ async function main() {
|
|||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* 建問題模式:建立追蹤 issue(標題=PR 標題、本文=PR 描述+回溯 PR 的引言,連同挑好的標籤一次建立),
|
* 建問題模式:建立追蹤 issue(標題=PR 標題、本文=PR 描述+回溯 PR 的引言,連同挑好的標籤一次建立),
|
||||||
* 並把 `issueBuffer` 內暫存的情境留言依序寫入 issue;設定閉包變數 `issue` 供後續留言直接發到 issue。
|
* 並把 `pendingIssueCommentBodies` 內暫存的情境留言依流程順序寫入 issue;
|
||||||
|
* 設定閉包變數 `trackingIssue` 供後續留言直接發到 issue。
|
||||||
* 僅於「確定有保留問題」時呼叫一次。標籤於建立時一次帶入,省去「先建空標籤 issue 再補掛」的多餘 API 往返。
|
* 僅於「確定有保留問題」時呼叫一次。標籤於建立時一次帶入,省去「先建空標籤 issue 再補掛」的多餘 API 往返。
|
||||||
*
|
*
|
||||||
* @param {number[]} [labelIds] - 建立 issue 時要一併掛上的標籤 id 陣列(由 `review.selectLabels` 事先挑選);
|
* @param {number[]} [labelIds] - 建立 issue 時要一併掛上的標籤 id 陣列(由 `review.selectLabels` 事先挑選);
|
||||||
* 空陣列或省略時不掛任何標籤(`gitea.createIssue` 對空陣列不帶 labels 欄位)。
|
* 空陣列或省略時不掛任何標籤(`gitea.createIssue` 對空陣列不帶 labels 欄位)。
|
||||||
* @returns {Promise<void>} 無回傳值;結果反映在閉包變數 `issue` 與 issue 留言。
|
* @returns {Promise<void>} 無回傳值;結果反映在閉包變數 `trackingIssue` 與 issue 留言。
|
||||||
*/
|
*/
|
||||||
const ensureIssueCreated = async (labelIds = []) => {
|
const createIssueAndFlushBufferedComments = async (labelIds = []) => {
|
||||||
issue = await gitea.createIssue(ctx, {
|
trackingIssue = await gitea.createIssue(ctx, {
|
||||||
title: ctx.prTitle || `AI Code Review:PR #${ctx.prNumber}`,
|
title: ctx.prTitle || `AI Code Review:PR #${ctx.prNumber}`,
|
||||||
body: templates.issueBody({ prNumber: ctx.prNumber, prBody: ctx.prBody }),
|
body: templates.issueBody({ prNumber: ctx.prNumber, prBody: ctx.prBody }),
|
||||||
labels: labelIds,
|
labels: labelIds,
|
||||||
});
|
});
|
||||||
log('建問題', 'INF', `已建立追蹤 issue #${issue.number},寫入 ${issueBuffer.length} 則情境留言。`);
|
log('建問題', 'INF', `已建立追蹤 issue #${trackingIssue.number},寫入 ${pendingIssueCommentBodies.length} 則情境留言。`);
|
||||||
for (const body of issueBuffer) {
|
for (const body of pendingIssueCommentBodies) {
|
||||||
await gitea.createCommentOnIssue(ctx, issue.number, body);
|
await gitea.createCommentOnIssue(ctx, trackingIssue.number, body);
|
||||||
}
|
}
|
||||||
issueBuffer.length = 0;
|
pendingIssueCommentBodies.length = 0;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* 建問題模式降級:追蹤 issue 無法建立或寫入時,改把已暫存的情境留言發回 PR,後續沿用一般模式。
|
||||||
|
*
|
||||||
|
* @returns {Promise<void>} 無回傳值;會關閉建問題模式並把 PR 留言 id 登錄到 `currentRunCommentIds`。
|
||||||
|
*/
|
||||||
|
const fallbackToPrComments = async () => {
|
||||||
|
issueModeActive = false;
|
||||||
|
trackingIssue = null;
|
||||||
|
for (const body of pendingIssueCommentBodies) {
|
||||||
|
const created = await gitea.createIssueComment(ctx, body);
|
||||||
|
currentRunCommentIds.add(created.id);
|
||||||
|
}
|
||||||
|
pendingIssueCommentBodies.length = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
// ── 步驟 2:延後執行 ───────────────────────────────────────────────────
|
// ── 步驟 2:延後執行 ───────────────────────────────────────────────────
|
||||||
@@ -231,7 +234,7 @@ async function main() {
|
|||||||
// 舊結果會先被清掉卻沒有新結果。故延後到「本回合審查已成功產生結果、發布問題留言前」
|
// 舊結果會先被清掉卻沒有新結果。故延後到「本回合審查已成功產生結果、發布問題留言前」
|
||||||
// 才呼叫 review.resolveOldComments(見下方步驟 4 空變更路徑與步驟 9 前);
|
// 才呼叫 review.resolveOldComments(見下方步驟 4 空變更路徑與步驟 9 前);
|
||||||
// 屆時本回合的工具/diff/角色留言已登錄於 currentRunCommentIds,不會被誤標為過時。
|
// 屆時本回合的工具/diff/角色留言已登錄於 currentRunCommentIds,不會被誤標為過時。
|
||||||
// 建問題模式全程不觸碰 PR 既有留言(審查內容改發到 issue)。
|
// 建問題模式不清理 PR 既有審查內容,只在收束時標記舊追蹤 issue 連結。
|
||||||
|
|
||||||
// ── 步驟 3:偵測 AI agent 工具並留言 ──────────────────────────────────
|
// ── 步驟 3:偵測 AI agent 工具並留言 ──────────────────────────────────
|
||||||
const tool = agents.detectTool();
|
const tool = agents.detectTool();
|
||||||
@@ -241,7 +244,7 @@ async function main() {
|
|||||||
}
|
}
|
||||||
log('步驟3', 'INF', `選用工具:${tool.name}(${tool.version})。`);
|
log('步驟3', 'INF', `選用工具:${tool.name}(${tool.version})。`);
|
||||||
const runLink = `${ctx.serverUrl}/${ctx.repository}/actions/runs/${ctx.runId}`;
|
const runLink = `${ctx.serverUrl}/${ctx.repository}/actions/runs/${ctx.runId}`;
|
||||||
await postComment(
|
await queueOrPostComment(
|
||||||
templates.toolComment({
|
templates.toolComment({
|
||||||
toolName: tool.name,
|
toolName: tool.name,
|
||||||
version: tool.version,
|
version: tool.version,
|
||||||
@@ -263,15 +266,15 @@ async function main() {
|
|||||||
if (files.length === 0) {
|
if (files.length === 0) {
|
||||||
// 沒有可審查的變更:保存空 findings、以 success 收場。
|
// 沒有可審查的變更:保存空 findings、以 success 收場。
|
||||||
// 一般模式在 PR 留言告知;建問題模式靜默通過(不建 issue、PR 也不留言,暫存的情境留言捨棄)。
|
// 一般模式在 PR 留言告知;建問題模式靜默通過(不建 issue、PR 也不留言,暫存的情境留言捨棄)。
|
||||||
if (ctx.createIssue) {
|
if (issueModeActive) {
|
||||||
log('步驟4', 'INF', '建問題模式且無可審查變更:靜默通過(不建 issue、PR 不留言)。');
|
log('步驟4', 'INF', '建問題模式且無可審查變更:靜默通過(不建 issue、PR 不留言)。');
|
||||||
} else {
|
} else {
|
||||||
await postComment(templates.nothingToReviewComment(ignoredCount));
|
await queueOrPostComment(templates.nothingToReviewComment(ignoredCount));
|
||||||
// 已成功產生本回合結果留言(無可審查變更),此時才把舊留言標為過時(本回合留言已排除)。
|
// 已成功產生本回合結果留言(無可審查變更),此時才把舊留言標為過時(本回合留言已排除)。
|
||||||
await review.resolveOldComments({ ctx, gitea, currentRunCommentIds });
|
await review.resolveOldComments({ ctx, gitea, currentRunCommentIds });
|
||||||
}
|
}
|
||||||
const relativePath = saveFindings({ cwd, ctx, tool, kept: [], excluded: [] });
|
const relativePath = saveFindings({ cwd, ctx, tool, kept: [], excluded: [] });
|
||||||
if (ctx.createIssue) {
|
if (issueModeActive) {
|
||||||
// 建問題模式下 findings 不進版控,且 exclusions.json 無變更 → 沒東西可提交。
|
// 建問題模式下 findings 不進版控,且 exclusions.json 無變更 → 沒東西可提交。
|
||||||
log('收尾', 'INF', '建問題模式且無可審查變更,略過 commit/push。');
|
log('收尾', 'INF', '建問題模式且無可審查變更,略過 commit/push。');
|
||||||
} else {
|
} else {
|
||||||
@@ -282,23 +285,25 @@ async function main() {
|
|||||||
|
|
||||||
const diffRows = review.collectDiffRows({ cwd, files, base, gitrepo });
|
const diffRows = review.collectDiffRows({ cwd, files, base, gitrepo });
|
||||||
await review.fillPurposes({ tool, model: ctx.model, cwd, diffRows });
|
await review.fillPurposes({ tool, model: ctx.model, cwd, diffRows });
|
||||||
await postComment(templates.diffComment(diffRows, ignoredCount));
|
await queueOrPostComment(templates.diffComment(diffRows, ignoredCount));
|
||||||
|
|
||||||
// ── 步驟 5:攻擊方角色登場留言 ─────────────────────────────────────────
|
// ── 步驟 5:攻擊方角色登場留言 ─────────────────────────────────────────
|
||||||
const roles = loadRoles(path.join(ctx.actionPath, 'src', 'prompts', 'roles'));
|
const roles = loadRoles(path.join(ctx.actionPath, 'src', 'prompts', 'roles'));
|
||||||
const attackers = attackersOf(roles);
|
const attackers = attackersOf(roles);
|
||||||
const defenders = defendersOf(roles);
|
const defenders = defendersOf(roles);
|
||||||
log('步驟5', 'INF', `攻擊方 ${attackers.length} 位、防守方 ${defenders.length} 位。`);
|
log('步驟5', 'INF', `攻擊方 ${attackers.length} 位、防守方 ${defenders.length} 位。`);
|
||||||
await postComment(templates.rolesComment({ title: '⚔️ 攻擊方登場', roles: attackers }));
|
await queueOrPostComment(templates.rolesComment({ title: '⚔️ 攻擊方登場', roles: attackers }));
|
||||||
|
|
||||||
// ── 步驟 6:每個攻擊方一個 sub agent 並行分析,合併問題列表 ────────────
|
// ── 步驟 6:每個攻擊方一個 sub agent 並行分析,合併問題列表 ────────────
|
||||||
const findings = await review.runAttackers({ tool, model: ctx.model, cwd, attackers, diffRows });
|
const findings = await review.runAttackers({ tool, model: ctx.model, cwd, attackers, diffRows });
|
||||||
|
|
||||||
// ── 步驟 7:防守方角色登場留言 ─────────────────────────────────────────
|
// ── 步驟 7:防守方角色登場留言 ─────────────────────────────────────────
|
||||||
await postComment(templates.rolesComment({ title: '🛡️ 防守方登場', roles: defenders }));
|
await queueOrPostComment(templates.rolesComment({ title: '🛡️ 防守方登場', roles: defenders }));
|
||||||
|
|
||||||
// ── 步驟 8:防守方裁決 → 排除 → 排序 → 保存 findings ──────────────────
|
// ── 步驟 8:防守方裁決 → 排除 → 排序 → 保存 findings ──────────────────
|
||||||
const { kept, excluded } = await review.runDefenders({ tool, model: ctx.model, cwd, defenders, findings });
|
const { kept, excluded } = findings.length === 0
|
||||||
|
? { kept: [], excluded: [] }
|
||||||
|
: await review.runDefenders({ tool, model: ctx.model, cwd, defenders, findings });
|
||||||
review.sortFindings(kept);
|
review.sortFindings(kept);
|
||||||
const relativePath = saveFindings({ cwd, ctx, tool, kept, excluded });
|
const relativePath = saveFindings({ cwd, ctx, tool, kept, excluded });
|
||||||
|
|
||||||
@@ -312,7 +317,7 @@ async function main() {
|
|||||||
|
|
||||||
// ── 建問題模式:確定有保留問題才建立 issue,並把暫存的情境留言一次寫入;
|
// ── 建問題模式:確定有保留問題才建立 issue,並把暫存的情境留言一次寫入;
|
||||||
// 無保留問題則不建 issue、PR 也完全不留言(靜默通過,暫存的情境留言捨棄)。 ──────
|
// 無保留問題則不建 issue、PR 也完全不留言(靜默通過,暫存的情境留言捨棄)。 ──────
|
||||||
if (ctx.createIssue) {
|
if (issueModeActive) {
|
||||||
if (kept.length > 0) {
|
if (kept.length > 0) {
|
||||||
// 先依保留問題挑好標籤,於建立 issue 時一次帶入(省去「先建空標籤 issue 再補掛」的多餘 API 往返);
|
// 先依保留問題挑好標籤,於建立 issue 時一次帶入(省去「先建空標籤 issue 再補掛」的多餘 API 往返);
|
||||||
// 標籤挑選失敗一律降級為不掛標籤,不阻斷建 issue 流程。
|
// 標籤挑選失敗一律降級為不掛標籤,不阻斷建 issue 流程。
|
||||||
@@ -331,7 +336,12 @@ async function main() {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
log('建問題', 'WRN', `標籤挑選失敗(${err.message}),issue 不掛標籤。`);
|
log('建問題', 'WRN', `標籤挑選失敗(${err.message}),issue 不掛標籤。`);
|
||||||
}
|
}
|
||||||
await ensureIssueCreated(labelIds);
|
try {
|
||||||
|
await createIssueAndFlushBufferedComments(labelIds);
|
||||||
|
} catch (err) {
|
||||||
|
log('建問題', 'WRN', `建立或寫入追蹤 issue 失敗(${err.message}),改用 PR 留言與 findings 檔流程。`);
|
||||||
|
await fallbackToPrComments();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// 無保留問題 → 不建 issue、PR 也不留言(靜默通過,暫存的情境留言捨棄)。
|
// 無保留問題 → 不建 issue、PR 也不留言(靜默通過,暫存的情境留言捨棄)。
|
||||||
log('建問題', 'INF', '沒有保留的問題:靜默通過(不建 issue、PR 不留言)。');
|
log('建問題', 'INF', '沒有保留的問題:靜默通過(不建 issue、PR 不留言)。');
|
||||||
@@ -342,14 +352,14 @@ async function main() {
|
|||||||
// 延後到此可避免工具偵測/diff/攻防裁決任一失敗時舊結果先被清掉卻無新結果;
|
// 延後到此可避免工具偵測/diff/攻防裁決任一失敗時舊結果先被清掉卻無新結果;
|
||||||
// 本回合的工具/diff/角色留言已登錄於 currentRunCommentIds,不會被誤標為過時;
|
// 本回合的工具/diff/角色留言已登錄於 currentRunCommentIds,不會被誤標為過時;
|
||||||
// 嚴重/其他問題留言於本步驟之後才發布,同樣不受影響。
|
// 嚴重/其他問題留言於本步驟之後才發布,同樣不受影響。
|
||||||
if (!ctx.createIssue) {
|
if (!issueModeActive) {
|
||||||
await review.resolveOldComments({ ctx, gitea, currentRunCommentIds });
|
await review.resolveOldComments({ ctx, gitea, currentRunCommentIds });
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── 步驟 9:嚴重問題留言(一般模式掛在 PR 程式碼行上;建問題模式逐條發到 issue)─
|
// ── 步驟 9:嚴重問題留言(一般模式掛在 PR 程式碼行上;建問題模式逐條發到 issue)─
|
||||||
if (severe.length > 0) {
|
if (severe.length > 0) {
|
||||||
if (ctx.createIssue) {
|
if (issueModeActive && trackingIssue) {
|
||||||
await review.postSevereToIssue({ ctx, gitea, issueNumber: issue.number, severe });
|
await review.postSevereToIssue({ ctx, gitea, issueNumber: trackingIssue.number, severe });
|
||||||
} else {
|
} else {
|
||||||
await review.postSevereComments({ ctx, gitea, severe, cwd });
|
await review.postSevereComments({ ctx, gitea, severe, cwd });
|
||||||
}
|
}
|
||||||
@@ -358,49 +368,69 @@ async function main() {
|
|||||||
// ── 步驟 10:警告+建議——一般模式彙整為單一表格留言到 PR;
|
// ── 步驟 10:警告+建議——一般模式彙整為單一表格留言到 PR;
|
||||||
// 建問題模式逐條發到 issue,讓每條問題都能被個別回覆。 ──
|
// 建問題模式逐條發到 issue,讓每條問題都能被個別回覆。 ──
|
||||||
if (others.length > 0) {
|
if (others.length > 0) {
|
||||||
if (ctx.createIssue) {
|
if (issueModeActive && trackingIssue) {
|
||||||
await review.postOthersToIssue({ ctx, gitea, issueNumber: issue.number, others });
|
await review.postOthersToIssue({ ctx, gitea, issueNumber: trackingIssue.number, others });
|
||||||
} else {
|
} else {
|
||||||
await postComment(templates.othersComment(others));
|
await queueOrPostComment(templates.othersComment(others));
|
||||||
log('步驟10', 'INF', `警告+建議表格留言已發布(${others.length} 條)。`);
|
log('步驟10', 'INF', `警告+建議表格留言已發布(${others.length} 條)。`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── 建問題模式收束:在 PR 回貼 issue 連結(雙向關聯),並讓 PR 相依於該 issue ─
|
// ── 建問題模式收束:在 PR 回貼 issue 連結(雙向關聯);僅在有嚴重問題時才讓 PR 相依於該 issue ─
|
||||||
// 標籤已於建立 issue 時一次帶入(見上方 selectLabels → ensureIssueCreated),此處不再補掛。
|
// 標籤已於建立 issue 時一次帶入(見上方 selectLabels → createIssueAndFlushBufferedComments),此處不再補掛。
|
||||||
if (ctx.createIssue && issue) {
|
if (issueModeActive && trackingIssue) {
|
||||||
|
await review.resolveOldIssueLinkComments({ ctx, gitea });
|
||||||
await gitea.createIssueComment(
|
await gitea.createIssueComment(
|
||||||
ctx,
|
ctx,
|
||||||
templates.issueLinkComment({
|
templates.prIssueLinkComment({
|
||||||
issueNumber: issue.number,
|
issueNumber: trackingIssue.number,
|
||||||
issueUrl: issue.html_url,
|
issueUrl: trackingIssue.html_url,
|
||||||
severeCount: severe.length,
|
severeCount: severe.length,
|
||||||
otherCount: others.length,
|
otherCount: others.length,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
// 讓 PR 相依於此追蹤 issue:issue 完成/關閉前 PR 無法合併(需 repo 啟用「問題相依」功能)。
|
// 只有「嚴重」問題才讓 PR 相依於追蹤 issue(issue 關閉前無法合併,需 repo 啟用「問題相依」功能);
|
||||||
|
// 僅有警告/建議時,issue 仍建立供追蹤,但不掛相依、不阻擋 PR 合併。
|
||||||
|
if (severe.length > 0) {
|
||||||
try {
|
try {
|
||||||
await gitea.addIssueDependency(ctx, ctx.prNumber, issue.number);
|
await gitea.addIssueDependency(ctx, ctx.prNumber, trackingIssue.number);
|
||||||
log('建問題', 'INF', `已將 PR #${ctx.prNumber} 設為相依於 issue #${issue.number}:issue 關閉前無法合併。`);
|
log('建問題', 'INF', `有嚴重問題:已將 PR #${ctx.prNumber} 設為相依於 issue #${trackingIssue.number},issue 關閉前無法合併。`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
log('建問題', 'WRN', `設定 PR 相依失敗(可能未啟用「問題相依」功能):${err.message}。`);
|
log('建問題', 'WRN', `設定 PR 相依失敗(可能未啟用「問題相依」功能):${err.message}。`);
|
||||||
}
|
}
|
||||||
log('建問題', 'INF', `issue #${issue.number} 已寫入審查內容,並在 PR 回貼連結。`);
|
} else {
|
||||||
|
log('建問題', 'INF', `無嚴重問題(僅警告/建議):issue #${trackingIssue.number} 僅供追蹤,不阻擋 PR 合併。`);
|
||||||
|
}
|
||||||
|
log('建問題', 'INF', `issue #${trackingIssue.number} 已寫入審查內容,並在 PR 回貼連結。`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── 收尾:commit 並 push(success=無嚴重問題、failure=有嚴重問題)───────
|
// ── 收尾:commit 並 push(success=無嚴重問題、failure=有嚴重問題)───────
|
||||||
// 一般模式:findings+exclusions.json;建問題模式:問題明細已在 issue 留言,只 commit exclusions.json。
|
// 一般模式:findings+exclusions.json;建問題模式通常只 commit exclusions.json。
|
||||||
|
// 若有嚴重問題,仍 commit findings 檔產生 [failure] 結果 commit,避免相依 API 不支援時 fail-open。
|
||||||
const result = severe.length === 0 ? 'success' : 'failure';
|
const result = severe.length === 0 ? 'success' : 'failure';
|
||||||
const filesToCommit = ctx.createIssue ? [] : [relativePath];
|
const filesToCommit = review.resultFilesToCommit({
|
||||||
if (exclusionsChanged) {
|
createIssue: issueModeActive,
|
||||||
filesToCommit.push(path.join('.gitea', 'ai-review', 'exclusions.json'));
|
severeCount: severe.length,
|
||||||
}
|
relativePath,
|
||||||
|
exclusionsChanged,
|
||||||
|
});
|
||||||
|
let resultCommitted = false;
|
||||||
if (filesToCommit.length > 0) {
|
if (filesToCommit.length > 0) {
|
||||||
commitFindings({ cwd, ctx, files: filesToCommit, result });
|
resultCommitted = commitFindings({ cwd, ctx, files: filesToCommit, result });
|
||||||
} else {
|
} else {
|
||||||
log('收尾', 'INF', '建問題模式且 exclusions.json 無變更,略過 commit/push。');
|
log('收尾', 'INF', '建問題模式且 exclusions.json 無變更,略過 commit/push。');
|
||||||
}
|
}
|
||||||
return result === 'success' ? 0 : 1;
|
// 本輪「審查」一律以成功收場、不直接讓檢查失敗;有嚴重問題時已推出 [failure] 結果 commit,
|
||||||
|
// 由它再觸發的下一輪在步驟 1 讀 commit 訊息時才回報失敗(exit 1)。如此失敗檢查落在帶有結果
|
||||||
|
// 標記的最新 head 上,與合併判定一致。(result 僅用於上方 commit 訊息的結果標記。)
|
||||||
|
if (result === 'failure') {
|
||||||
|
if (!resultCommitted) {
|
||||||
|
log('收尾', 'ERR', '本輪有嚴重問題,但未成功產生 [failure] 結果 commit;直接回報失敗避免 fail-open。');
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
log('收尾', 'INF', '本輪有嚴重問題:已標記結果 commit 為 [failure],失敗檢查由下一輪步驟 1 讀 commit 訊息回報。');
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|||||||
+2
-6
@@ -20,7 +20,6 @@ const path = require('path');
|
|||||||
* token: string,
|
* token: string,
|
||||||
* model: string,
|
* model: string,
|
||||||
* createIssue: boolean,
|
* createIssue: boolean,
|
||||||
* pushToken: string,
|
|
||||||
* event: Object,
|
* event: Object,
|
||||||
* pr: (Object|null),
|
* pr: (Object|null),
|
||||||
* prNumber: (number|null),
|
* prNumber: (number|null),
|
||||||
@@ -38,12 +37,11 @@ const path = require('path');
|
|||||||
* - repository:`owner/repo` 全名(GITHUB_REPOSITORY)。
|
* - repository:`owner/repo` 全名(GITHUB_REPOSITORY)。
|
||||||
* - owner / repo:自 repository 拆出的擁有者與專案名,缺值時為空字串。
|
* - owner / repo:自 repository 拆出的擁有者與專案名,缺值時為空字串。
|
||||||
* - apiBase:Gitea REST API 基底網址(`<serverUrl>/api/v1`)。
|
* - apiBase:Gitea REST API 基底網址(`<serverUrl>/api/v1`)。
|
||||||
* - token:action input `token`(INPUT_TOKEN),用於 API 認證,缺值時為空字串。
|
* - token:action input `token`(INPUT_TOKEN),用於 Gitea API 認證,以及 push findings/exclusions
|
||||||
|
* commit 回 repo;建議為「能觸發 CI 的 PAT」(自動 token 推送不會再觸發 CI)。缺值時為空字串。
|
||||||
* - model:action input `model`(INPUT_MODEL,已 trim),指定 AI 模型,缺值時為空字串。
|
* - model:action input `model`(INPUT_MODEL,已 trim),指定 AI 模型,缺值時為空字串。
|
||||||
* - createIssue:action input `create-issue`(INPUT_CREATE-ISSUE),是否將問題建到
|
* - createIssue:action input `create-issue`(INPUT_CREATE-ISSUE),是否將問題建到
|
||||||
* 存取庫的問題追蹤(建問題模式);trim + 小寫後與字串 'true' 嚴格比對,預設 false。
|
* 存取庫的問題追蹤(建問題模式);trim + 小寫後與字串 'true' 嚴格比對,預設 false。
|
||||||
* - pushToken:action input `push-token`(INPUT_PUSH-TOKEN),推送 findings/exclusions commit 用的 PAT;
|
|
||||||
* 提供時以 PAT 身分推送使 CI 再觸發(配合步驟 1 快速回報);留空=退回以 token 走 origin 推送(不會再觸發)。
|
|
||||||
* - event:事件 payload 解析後的完整物件;讀取失敗時為空物件。
|
* - event:事件 payload 解析後的完整物件;讀取失敗時為空物件。
|
||||||
* - pr:payload 內的 pull_request 物件;非 PR 事件時為 null。
|
* - pr:payload 內的 pull_request 物件;非 PR 事件時為 null。
|
||||||
* - prNumber:PR 編號,優先取 payload,退而從 GITHUB_REF(refs/pull/N/...)解析;皆無時為 null。
|
* - prNumber:PR 編號,優先取 payload,退而從 GITHUB_REF(refs/pull/N/...)解析;皆無時為 null。
|
||||||
@@ -95,8 +93,6 @@ function loadContext() {
|
|||||||
model: (process.env.INPUT_MODEL || '').trim(),
|
model: (process.env.INPUT_MODEL || '').trim(),
|
||||||
// 是否將問題建到存取庫的問題追蹤(input: create-issue,字串 'true' 才啟用,預設否)。
|
// 是否將問題建到存取庫的問題追蹤(input: create-issue,字串 'true' 才啟用,預設否)。
|
||||||
createIssue: (process.env['INPUT_CREATE-ISSUE'] || '').trim().toLowerCase() === 'true',
|
createIssue: (process.env['INPUT_CREATE-ISSUE'] || '').trim().toLowerCase() === 'true',
|
||||||
// 推送 findings/exclusions commit 用的 PAT(input: push-token);提供時以 PAT 推送讓 CI 再觸發,留空=退回 token。
|
|
||||||
pushToken: (process.env['INPUT_PUSH-TOKEN'] || '').trim(),
|
|
||||||
event,
|
event,
|
||||||
pr,
|
pr,
|
||||||
prNumber,
|
prNumber,
|
||||||
|
|||||||
@@ -0,0 +1,82 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
// AI CLI 失敗診斷與機密遮罩工具:供 review 流程記錄安全、限長的一行錯誤摘要。
|
||||||
|
|
||||||
|
// 遮罩前先截去的輸入上限,避免對數 MB 失敗輸出跑整份 O(k*n) 正規掃描。
|
||||||
|
const AGENT_DIAGNOSTIC_INPUT_LIMIT = 2_000;
|
||||||
|
// 每段診斷片段(stderr/stdout)寫入日誌的字元上限。
|
||||||
|
const AGENT_DIAGNOSTIC_OUTPUT_LIMIT = 500;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 遮罩診斷文字中的機密與控制字元,避免寫進 CI log 時外洩。
|
||||||
|
*
|
||||||
|
* 處理順序:換行與控制字元一律壓成單一空白(避免注入假日誌行)→ 遮蔽
|
||||||
|
* `Authorization` 標頭、`token=`/`token:` 型憑證、URL 內嵌帳密、以及常見長金鑰/
|
||||||
|
* 長 hex/`ghp_` 等 token 樣式。屬「盡力遮罩」——無法窮舉所有機密格式,作為輸出
|
||||||
|
* CLI 診斷片段前的防線使用(見 {@link agentFailureDetail})。
|
||||||
|
*
|
||||||
|
* @param {*} text - 待遮罩的原始文字(非字串會先以 `String()` 轉型)。
|
||||||
|
* @returns {string} 已去控制字元並遮蔽常見機密樣式的單行文字。
|
||||||
|
*/
|
||||||
|
function redactSecrets(text) {
|
||||||
|
return String(text ?? '')
|
||||||
|
.replace(/[\r\n\t\v\f\x00-\x1f\x7f]+/g, ' ')
|
||||||
|
.replace(/(authorization\s*[:=]\s*)(?:bearer\s+)?\S+/gi, '$1***')
|
||||||
|
.replace(/((?:api[_-]?key|token|password|secret|bearer)\s*[:=]\s*)\S+/gi, '$1***')
|
||||||
|
.replace(/(https?:\/\/)[^\s/:@]+:[^\s/@]+@/gi, '$1***:***@')
|
||||||
|
.replace(/\bgh[pousr]_[A-Za-z0-9]{16,}\b/g, '***')
|
||||||
|
.replace(/\b[A-Za-z0-9_-]{40,}\b/g, '***')
|
||||||
|
.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 將 AI CLI 失敗輸出整理成單行、遮罩且限長的診斷片段。
|
||||||
|
*
|
||||||
|
* @param {string[]} parts - 要附加診斷片段的陣列。
|
||||||
|
* @param {string} label - 診斷欄位名稱(如 stderr/stdout)。
|
||||||
|
* @param {*} value - 原始診斷輸出。
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
function appendRedactedOutput(parts, label, value) {
|
||||||
|
const redacted = redactSecrets(String(value || '').slice(0, AGENT_DIAGNOSTIC_INPUT_LIMIT));
|
||||||
|
if (redacted) parts.push(`${label}:${redacted.slice(0, AGENT_DIAGNOSTIC_OUTPUT_LIMIT)}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 從 `runAgent` 的失敗結果組出可診斷的一行摘要:退出碼/訊號為主,原始輸出預設隱藏。
|
||||||
|
*
|
||||||
|
* 安全考量:AI CLI 失敗時可能在 stderr/stdout 回顯提示內容、環境資訊、token、PII 或
|
||||||
|
* 原始碼祕密,這些會被長期保存並供多人讀取的 CI log 收錄。因此本函式預設只輸出退出碼、
|
||||||
|
* 訊號與逾時狀態;只有 `ACTIONS_STEP_DEBUG=true` 時才附上經 {@link redactSecrets}
|
||||||
|
* 遮罩且去除控制字元的 stderr/stdout 片段。
|
||||||
|
*
|
||||||
|
* @param {{error: (Error & {code?: number|string, signal?: string, killed?: boolean})|null, stderr?: string, output?: string}} agentResult
|
||||||
|
* `runAgent` 的回傳物件。
|
||||||
|
* @returns {string} 單行診斷摘要(各段以「|」分隔);無任何資訊時回傳固定字串。
|
||||||
|
*/
|
||||||
|
function agentFailureDetail(agentResult) {
|
||||||
|
const parts = [];
|
||||||
|
const err = agentResult && agentResult.error;
|
||||||
|
if (err) {
|
||||||
|
if (err.killed) parts.push('已逾時終止');
|
||||||
|
if (typeof err.code === 'number') parts.push(`exit ${err.code}`);
|
||||||
|
else if (err.code) parts.push(`code ${err.code}`);
|
||||||
|
else if (err.signal) parts.push(`signal ${err.signal}`);
|
||||||
|
}
|
||||||
|
// 失敗輸出可能含 token 或 PII,預設不寫入長期 CI log;debug 模式才輸出遮罩後片段。
|
||||||
|
if (process.env.ACTIONS_STEP_DEBUG === 'true') {
|
||||||
|
appendRedactedOutput(parts, 'stderr', agentResult && agentResult.stderr);
|
||||||
|
appendRedactedOutput(parts, 'stdout', agentResult && agentResult.output);
|
||||||
|
}
|
||||||
|
if (parts.length === 0) {
|
||||||
|
parts.push((err && err.message && redactSecrets(err.message)) || 'AI CLI 執行失敗(無診斷輸出)');
|
||||||
|
}
|
||||||
|
return parts.join('|');
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
AGENT_DIAGNOSTIC_INPUT_LIMIT,
|
||||||
|
AGENT_DIAGNOSTIC_OUTPUT_LIMIT,
|
||||||
|
redactSecrets,
|
||||||
|
agentFailureDetail,
|
||||||
|
};
|
||||||
+9
-31
@@ -119,7 +119,7 @@ function createCommentOnIssue(ctx, issueNumber, body) {
|
|||||||
* 依 Gitea API 回應而定)。
|
* 依 Gitea API 回應而定)。
|
||||||
* @throws {Error} 請求失敗(非 2xx)由底層 `api` 丟出,錯誤附 `status`、`data`。
|
* @throws {Error} 請求失敗(非 2xx)由底層 `api` 丟出,錯誤附 `status`、`data`。
|
||||||
* @remarks 使用情境:AI review 各步驟把審查摘要、角色登場、問題彙整等內容
|
* @remarks 使用情境:AI review 各步驟把審查摘要、角色登場、問題彙整等內容
|
||||||
* 以一般留言形式張貼到本次 PR 上(`main()` 的 `postComment` 閉包即以本函式實作)。
|
* 以一般留言形式張貼到本次 PR 上(`main()` 的 `queueOrPostComment` 閉包即以本函式實作)。
|
||||||
*/
|
*/
|
||||||
function createIssueComment(ctx, body) {
|
function createIssueComment(ctx, body) {
|
||||||
return createCommentOnIssue(ctx, ctx.prNumber, body);
|
return createCommentOnIssue(ctx, ctx.prNumber, body);
|
||||||
@@ -156,7 +156,7 @@ function listLabels(ctx) {
|
|||||||
* @returns {Promise<object>} 建立成功的 issue 物件(含 `number`、`title`、
|
* @returns {Promise<object>} 建立成功的 issue 物件(含 `number`、`title`、
|
||||||
* `html_url` 等欄位,依 Gitea API 回應而定)。
|
* `html_url` 等欄位,依 Gitea API 回應而定)。
|
||||||
* @throws {Error} 請求失敗(非 2xx)由底層 `api` 丟出,錯誤附 `status`、`data`。
|
* @throws {Error} 請求失敗(非 2xx)由底層 `api` 丟出,錯誤附 `status`、`data`。
|
||||||
* @remarks 使用情境:建問題模式(input: create-issue)下,`main()` 的 `ensureIssueCreated`
|
* @remarks 使用情境:建問題模式(input: create-issue)下,`main()` 的 `createIssueAndFlushBufferedComments`
|
||||||
* 以 PR 標題/描述為 issue 標題與本文,並帶入 `review.selectLabels` 事先挑好的標籤 id
|
* 以 PR 標題/描述為 issue 標題與本文,並帶入 `review.selectLabels` 事先挑好的標籤 id
|
||||||
* 呼叫本函式一次建立追蹤問題的 issue(連同標籤),之後再把審查內容逐條留言到該 issue。
|
* 呼叫本函式一次建立追蹤問題的 issue(連同標籤),之後再把審查內容逐條留言到該 issue。
|
||||||
*/
|
*/
|
||||||
@@ -168,49 +168,28 @@ function createIssue(ctx, { title, body, labels }) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 為既有 issue 追加標籤(不影響既有標籤)。
|
|
||||||
* 對應 endpoint:`POST /repos/{owner}/{repo}/issues/{issueNumber}/labels`。
|
|
||||||
* `labels` 為空陣列時不呼叫 API、直接回傳 `null`(省一次無意義請求)。
|
|
||||||
*
|
|
||||||
* @param {object} ctx - 執行環境 context。必要欄位:`apiBase`、`token`、
|
|
||||||
* `owner`(repo 擁有者)、`repo`(repo 名稱)。
|
|
||||||
* @param {number|string} issueNumber - 目標 issue 編號。
|
|
||||||
* @param {number[]} labels - 要追加的標籤 id 陣列。
|
|
||||||
* @returns {Promise<object[]|null>} 追加後該 issue 的標籤陣列(依 Gitea API 回應而定);
|
|
||||||
* `labels` 為空時回傳 `null`(未發出請求)。
|
|
||||||
* @throws {Error} 請求失敗(非 2xx)由底層 `api` 丟出,錯誤附 `status`、`data`。
|
|
||||||
* @remarks 使用情境:為既有 issue 動態追加標籤的通用工具(不影響既有標籤)。
|
|
||||||
* 註:建問題模式主流程已改為「建立 issue 時一次帶入標籤」(見 `createIssue`),
|
|
||||||
* 不再於事後補掛;本函式保留為 Gitea 客戶端的通用能力,供需要事後追加標籤的情境使用。
|
|
||||||
*/
|
|
||||||
function addLabelsToIssue(ctx, issueNumber, labels) {
|
|
||||||
if (!labels || labels.length === 0) return Promise.resolve(null);
|
|
||||||
return api(ctx, 'POST', `/repos/${ctx.owner}/${ctx.repo}/issues/${issueNumber}/labels`, { labels });
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 建立「問題相依」關係:讓 URL 上的 issue/PR 相依於(被阻擋於)表單指定的 issue。
|
* 建立「問題相依」關係:讓 URL 上的 issue/PR 相依於(被阻擋於)表單指定的 issue。
|
||||||
* 對應 endpoint:`POST /repos/{owner}/{repo}/issues/{issueNumber}/dependencies`
|
* 對應 endpoint:`POST /repos/{owner}/{repo}/issues/{issueNumber}/dependencies`
|
||||||
* (body 為 IssueMeta:`{index, owner, repo}`)。
|
* (body 為 IssueMeta:`{index, owner, repo}`)。
|
||||||
*
|
*
|
||||||
* 語義:URL 的 issue(`issueNumber`)相依於 body 的 issue(`dependency`)——
|
* 語義:URL 的 issue(`blockedIssueNumber`)相依於 body 的 issue(`blockingIssueNumber`)——
|
||||||
* 在 `dependency` 關閉前,`issueNumber` 無法合併/關閉。本 endpoint 需 repo 啟用
|
* 在 `blockingIssueNumber` 關閉前,`blockedIssueNumber` 無法合併/關閉。本 endpoint 需 repo 啟用
|
||||||
* 「問題相依(issue dependencies)」功能,屬版本/設定相依;未啟用或不支援時 API 會回非 2xx。
|
* 「問題相依(issue dependencies)」功能,屬版本/設定相依;未啟用或不支援時 API 會回非 2xx。
|
||||||
*
|
*
|
||||||
* @param {object} ctx - 執行環境 context。必要欄位:`apiBase`、`token`、
|
* @param {object} ctx - 執行環境 context。必要欄位:`apiBase`、`token`、
|
||||||
* `owner`(repo 擁有者)、`repo`(repo 名稱)。
|
* `owner`(repo 擁有者)、`repo`(repo 名稱)。
|
||||||
* @param {number|string} issueNumber - 要被阻擋的 issue/PR 編號(相依方)。
|
* @param {number|string} blockedIssueNumber - 要被阻擋的 issue/PR 編號(相依方)。
|
||||||
* @param {number} dependency - 作為阻擋來源的 issue 編號(同一 repo)。
|
* @param {number} blockingIssueNumber - 作為阻擋來源的 issue 編號(同一 repo)。
|
||||||
* @returns {Promise<object>} 建立成功的相依關係物件(依 Gitea API 回應而定)。
|
* @returns {Promise<object>} 建立成功的相依關係物件(依 Gitea API 回應而定)。
|
||||||
* @throws {Error} 請求失敗(非 2xx,例如未啟用問題相依功能)由底層 `api` 丟出,錯誤附 `status`、`data`。
|
* @throws {Error} 請求失敗(非 2xx,例如未啟用問題相依功能)由底層 `api` 丟出,錯誤附 `status`、`data`。
|
||||||
* @remarks 使用情境:建問題模式(input: create-issue)下,`main()` 建立追蹤 issue 後,
|
* @remarks 使用情境:建問題模式(input: create-issue)下,`main()` 建立追蹤 issue 後,
|
||||||
* 以本函式把「PR(`ctx.prNumber`)相依於追蹤 issue」,讓 issue 完成/關閉前 PR 無法合併;
|
* 以本函式把「PR(`ctx.prNumber`)相依於追蹤 issue」,讓 issue 完成/關閉前 PR 無法合併;
|
||||||
* 呼叫端以 try/catch 降級(功能未啟用時記 WRN、不阻斷流程)。
|
* 呼叫端以 try/catch 降級(功能未啟用時記 WRN、不阻斷流程)。
|
||||||
*/
|
*/
|
||||||
function addIssueDependency(ctx, issueNumber, dependency) {
|
function addIssueDependency(ctx, blockedIssueNumber, blockingIssueNumber) {
|
||||||
return api(ctx, 'POST', `/repos/${ctx.owner}/${ctx.repo}/issues/${issueNumber}/dependencies`, {
|
return api(ctx, 'POST', `/repos/${ctx.owner}/${ctx.repo}/issues/${blockedIssueNumber}/dependencies`, {
|
||||||
index: dependency,
|
index: blockingIssueNumber,
|
||||||
owner: ctx.owner,
|
owner: ctx.owner,
|
||||||
repo: ctx.repo,
|
repo: ctx.repo,
|
||||||
});
|
});
|
||||||
@@ -350,7 +329,6 @@ module.exports = {
|
|||||||
createCommentOnIssue,
|
createCommentOnIssue,
|
||||||
listLabels,
|
listLabels,
|
||||||
createIssue,
|
createIssue,
|
||||||
addLabelsToIssue,
|
|
||||||
addIssueDependency,
|
addIssueDependency,
|
||||||
listIssueComments,
|
listIssueComments,
|
||||||
editIssueComment,
|
editIssueComment,
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const { execFileSync } = require('child_process');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 驗證遠端分支名稱可安全用於 refspec 與 refs/remotes/origin/*。
|
||||||
|
*
|
||||||
|
* @param {string} refName - 使用者或事件 payload 提供的分支名稱。
|
||||||
|
* @param {string} fieldName - 錯誤訊息中的欄位名稱。
|
||||||
|
* @returns {string} 原樣回傳通過驗證的分支名稱。
|
||||||
|
* @throws {Error} 分支名稱空白、含路徑穿越,或不符合 git 分支 ref 規則時拋出。
|
||||||
|
*/
|
||||||
|
function assertSafeBranchRef(refName, fieldName) {
|
||||||
|
const value = String(refName || '').trim();
|
||||||
|
if (!value) throw new Error(`${fieldName} 不可為空。`);
|
||||||
|
if (value.includes('..') || value.startsWith('/') || value.endsWith('/') || value.includes('\\')) {
|
||||||
|
throw new Error(`${fieldName} 不是安全的分支名稱:${value}`);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
execFileSync('git', ['check-ref-format', '--branch', value], {
|
||||||
|
encoding: 'utf8',
|
||||||
|
stdio: ['ignore', 'pipe', 'pipe'],
|
||||||
|
});
|
||||||
|
} catch {
|
||||||
|
throw new Error(`${fieldName} 不是合法的 git 分支名稱:${value}`);
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
assertSafeBranchRef,
|
||||||
|
};
|
||||||
+72
-37
@@ -1,6 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { execFileSync } = require('child_process');
|
const { execFileSync } = require('child_process');
|
||||||
|
const { assertSafeBranchRef } = require('./gitref');
|
||||||
|
|
||||||
// git 操作工具:一律以 execFileSync 呼叫 git(不經 shell,避免注入),輸出以 UTF-8 回傳。
|
// git 操作工具:一律以 execFileSync 呼叫 git(不經 shell,避免注入),輸出以 UTF-8 回傳。
|
||||||
|
|
||||||
@@ -102,6 +103,7 @@ function latestCommitSubject(cwd) {
|
|||||||
* 避免把 base 分支後續演進誤算進 diff。
|
* 避免把 base 分支後續演進誤算進 diff。
|
||||||
*/
|
*/
|
||||||
function resolveMergeBase(cwd, baseRef) {
|
function resolveMergeBase(cwd, baseRef) {
|
||||||
|
baseRef = assertSafeBranchRef(baseRef, 'baseRef');
|
||||||
const remoteBase = `origin/${baseRef}`;
|
const remoteBase = `origin/${baseRef}`;
|
||||||
const diagnostics = [];
|
const diagnostics = [];
|
||||||
// 執行一個 fetch 策略並記錄成敗(只記策略名與成敗,不含 git 原始輸出,避免洩漏遠端資訊)。
|
// 執行一個 fetch 策略並記錄成敗(只記策略名與成敗,不含 git 原始輸出,避免洩漏遠端資訊)。
|
||||||
@@ -130,17 +132,19 @@ function resolveMergeBase(cwd, baseRef) {
|
|||||||
diagnostics.push('merge-base(首次):失敗');
|
diagnostics.push('merge-base(首次):失敗');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 資料驅動的補抓策略:淺層才 unshallow;其後依序 deepen base 與 HEAD。
|
// 資料驅動的補抓策略:先以固定深度分批加深 base 與 HEAD(每步後重試 merge-base,成功即回傳);
|
||||||
// 每個策略成功後立即重試 merge-base,成功即回傳,避免多餘往返。
|
// 只有仍失敗且為淺層 repo 時,才把成本最高的 --unshallow(下載完整歷史)當最後手段,
|
||||||
const strategies = [];
|
// 避免大型/長壽 repo 只為找共同祖先就無謂拉全史。
|
||||||
|
// 加深 HEAD 側須以「目前 HEAD 的 commit SHA」補抓——遠端符號 `HEAD` 由伺服器解析為
|
||||||
|
// 遠端預設分支(非目前 checkout 的 PR head),只加深它並不會補到 PR head 的歷史。
|
||||||
|
const headSha = gitTrim(cwd, 'rev-parse', 'HEAD');
|
||||||
|
const strategies = [
|
||||||
|
['deepen base', 'fetch', '--no-tags', '--deepen=1000', 'origin', `+refs/heads/${baseRef}:refs/remotes/${remoteBase}`],
|
||||||
|
['deepen PR HEAD', 'fetch', '--no-tags', '--deepen=1000', 'origin', headSha],
|
||||||
|
];
|
||||||
if (gitTrim(cwd, 'rev-parse', '--is-shallow-repository') === 'true') {
|
if (gitTrim(cwd, 'rev-parse', '--is-shallow-repository') === 'true') {
|
||||||
strategies.push(['unshallow', 'fetch', '--no-tags', '--unshallow', 'origin']);
|
strategies.push(['unshallow', 'fetch', '--no-tags', '--unshallow', 'origin']);
|
||||||
}
|
}
|
||||||
strategies.push([
|
|
||||||
'deepen base',
|
|
||||||
'fetch', '--no-tags', '--deepen=1000', 'origin', `+refs/heads/${baseRef}:refs/remotes/${remoteBase}`,
|
|
||||||
]);
|
|
||||||
strategies.push(['deepen HEAD', 'fetch', '--no-tags', '--deepen=1000', 'origin', 'HEAD']);
|
|
||||||
|
|
||||||
for (const [label, ...args] of strategies) {
|
for (const [label, ...args] of strategies) {
|
||||||
if (!runFetch(label, ...args)) continue; // fetch 失敗就換下一個策略。
|
if (!runFetch(label, ...args)) continue; // fetch 失敗就換下一個策略。
|
||||||
@@ -223,9 +227,9 @@ function fileLastUpdatedIso(cwd, file) {
|
|||||||
* 若目前 HEAD 不在 PR head commit(例如 checkout 停在 merge commit),
|
* 若目前 HEAD 不在 PR head commit(例如 checkout 停在 merge commit),
|
||||||
* 會先 `git checkout --detach <headSha>` 站上 head,避免把 merge 內容推回來源分支。
|
* 會先 `git checkout --detach <headSha>` 站上 head,避免把 merge 內容推回來源分支。
|
||||||
* commit 以 `-c` 臨時覆寫 user.name / user.email,不改動 repo 的 git 設定。
|
* commit 以 `-c` 臨時覆寫 user.name / user.email,不改動 repo 的 git 設定。
|
||||||
* push 策略:提供 `pushToken`(PAT)時直接以該 token 的 URL 推送(略過 origin)——因為 origin
|
* push 策略:一律以 `token` 的身分明確認證推送({@link pushWithCredential},不走 runner 的
|
||||||
* 帶的是不會再觸發 CI 的自動 token,改以 PAT 身分推送才會讓 PR 的 synchronize 事件再觸發 CI;
|
* origin 自動 token)——origin 帶的自動 token(gitea.token / GITHUB_TOKEN)推送不會再觸發 CI,
|
||||||
* 未提供 `pushToken` 時先走 origin,失敗(遠端未帶認證)再改用帶 `token` 的 URL 重試。
|
* 改以呼叫端提供的 `token`(建議為 PAT)身分推送,才會讓 PR 的 synchronize 事件再觸發 CI。
|
||||||
*
|
*
|
||||||
* @param {string} cwd - git 工作目錄(repo 的 checkout 路徑)。
|
* @param {string} cwd - git 工作目錄(repo 的 checkout 路徑)。
|
||||||
* @param {object} options - 提交與推送設定。
|
* @param {object} options - 提交與推送設定。
|
||||||
@@ -233,8 +237,7 @@ function fileLastUpdatedIso(cwd, file) {
|
|||||||
* @param {string} [options.headSha] - PR head 的 commit SHA;有提供且與目前 HEAD 不同時會先 detach 到此 commit。可省略(falsy 時不 detach,直接於目前 HEAD 上 commit)。
|
* @param {string} [options.headSha] - PR head 的 commit SHA;有提供且與目前 HEAD 不同時會先 detach 到此 commit。可省略(falsy 時不 detach,直接於目前 HEAD 上 commit)。
|
||||||
* @param {string} options.message - commit 訊息。
|
* @param {string} options.message - commit 訊息。
|
||||||
* @param {string[]} options.files - 要加入 commit 的檔案路徑清單(相對 repo 根目錄);全數無實際變更時不 commit、回傳 false。
|
* @param {string[]} options.files - 要加入 commit 的檔案路徑清單(相對 repo 根目錄);全數無實際變更時不 commit、回傳 false。
|
||||||
* @param {string} options.token - 具該 repo push 權限的 Gitea access token;未提供 pushToken 時,於 origin push 失敗才用於組出帶認證的重試 URL。
|
* @param {string} options.token - 具該 repo push 權限的 Gitea access token(建議為能觸發 CI 的 PAT);用於 findings commit 的認證推送。
|
||||||
* @param {string} [options.pushToken] - 專用推送 token(PAT);提供時直接以此 token 的 URL 推送(略過 origin),使 push 以 PAT 身分進行以再觸發 CI;未提供時走 origin、失敗再退回 `token`。
|
|
||||||
* @param {string} options.serverUrl - Gitea 伺服器根網址(例如 https://gitea.example.com),須為合法 URL。
|
* @param {string} options.serverUrl - Gitea 伺服器根網址(例如 https://gitea.example.com),須為合法 URL。
|
||||||
* @param {string} options.repository - repo 完整名稱(owner/repo 格式),與 serverUrl 組成 clone URL。
|
* @param {string} options.repository - repo 完整名稱(owner/repo 格式),與 serverUrl 組成 clone URL。
|
||||||
* @returns {boolean} true=有變更且已 commit 並 push 到來源分支;false=暫存區與 HEAD 無差異,略過 commit/push。
|
* @returns {boolean} true=有變更且已 commit 並 push 到來源分支;false=暫存區與 HEAD 無差異,略過 commit/push。
|
||||||
@@ -244,12 +247,13 @@ function fileLastUpdatedIso(cwd, file) {
|
|||||||
* findings 檔與 `.gitea/ai-review/exclusions.json` 等結果檔提交回 PR 來源分支,
|
* findings 檔與 `.gitea/ai-review/exclusions.json` 等結果檔提交回 PR 來源分支,
|
||||||
* 並依回傳值記錄「已 commit/push」或「無實際變更、略過」的不同日誌。
|
* 並依回傳值記錄「已 commit/push」或「無實際變更、略過」的不同日誌。
|
||||||
*
|
*
|
||||||
* 安全注意:push 重試時組出的 URL 內含 token(形如
|
* 安全注意:帶認證的推送一律透過 {@link pushWithCredential} 進行——認證只以
|
||||||
* `https://ai-review-bot:<token>@host/owner/repo.git`),
|
* 環境變數(`http.<url>.extraheader` 的 base64 Basic)傳入,**不進 argv**,
|
||||||
* 絕對不得將此 URL 輸出到日誌、錯誤訊息或任何 action 輸出,以免洩漏 token;
|
* 推送目標 URL 本身不含帳密;且 push 失敗時改拋固定訊息,避免 `execFileSync`
|
||||||
* 若需記錄重試行為,只能記載「改用帶認證 URL 重試」而不得包含 URL 本身。
|
* 例外把命令列(含 token)回顯到 CI log 或程序清單。
|
||||||
*/
|
*/
|
||||||
function commitAndPushFindings(cwd, { headRef, headSha, message, files, token, pushToken, serverUrl, repository }) {
|
function commitAndPushFindings(cwd, { headRef, headSha, message, files, token, serverUrl, repository }) {
|
||||||
|
headRef = assertSafeBranchRef(headRef, 'headRef');
|
||||||
const current = gitTrim(cwd, 'rev-parse', 'HEAD');
|
const current = gitTrim(cwd, 'rev-parse', 'HEAD');
|
||||||
if (headSha && current !== headSha) {
|
if (headSha && current !== headSha) {
|
||||||
git(cwd, 'checkout', '--detach', headSha);
|
git(cwd, 'checkout', '--detach', headSha);
|
||||||
@@ -267,28 +271,59 @@ function commitAndPushFindings(cwd, { headRef, headSha, message, files, token, p
|
|||||||
'-c', 'user.email=ai-review-bot@noreply.gitea',
|
'-c', 'user.email=ai-review-bot@noreply.gitea',
|
||||||
'commit', '-m', message,
|
'commit', '-m', message,
|
||||||
);
|
);
|
||||||
if (pushToken) {
|
const refspec = `HEAD:refs/heads/${headRef}`;
|
||||||
// 有專用 PAT → 直接以帶 token 的 URL 推送(略過 origin,因 origin 帶的是不會再觸發 CI 的自動 token);
|
const remoteUrl = `${serverUrl}/${repository}.git`;
|
||||||
// 以 PAT 身分推送才會讓 PR 的 synchronize 事件再觸發 CI。不得把含 token 的 URL 輸出到日誌。
|
// 一律以 token 的身分明確認證推送,不沿用 origin 的自動 token。
|
||||||
const url = new URL(`${serverUrl}/${repository}.git`);
|
pushWithCredential(cwd, remoteUrl, token, refspec, serverUrl);
|
||||||
url.username = 'ai-review-bot';
|
|
||||||
url.password = pushToken;
|
|
||||||
git(cwd, 'push', url.toString(), `HEAD:refs/heads/${headRef}`);
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
git(cwd, 'push', 'origin', `HEAD:refs/heads/${headRef}`);
|
|
||||||
} catch {
|
|
||||||
// 遠端未帶認證(checkout 未保留 credentials)時,改用帶 token 的 URL 重試。
|
|
||||||
// 注意:不得把這個 URL 輸出到日誌,避免洩漏 token。
|
|
||||||
const url = new URL(`${serverUrl}/${repository}.git`);
|
|
||||||
url.username = 'ai-review-bot';
|
|
||||||
url.password = token;
|
|
||||||
git(cwd, 'push', url.toString(), `HEAD:refs/heads/${headRef}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 以帶認證的方式推送到指定遠端,認證資訊只經環境變數傳入、不進命令列 argv。
|
||||||
|
*
|
||||||
|
* 以 `GIT_CONFIG_*` 注入本次 HTTP Basic extraheader,避免憑證出現在 argv;
|
||||||
|
* 同時先清空 checkout 持久化的自動 token extraheader,確保本次 push 使用呼叫端 token。
|
||||||
|
* 推送失敗時改拋固定訊息,避免原始例外帶出遠端 URL 或認證資訊。
|
||||||
|
*
|
||||||
|
* @param {string} cwd - git 工作目錄(repo 的 checkout 路徑)。
|
||||||
|
* @param {string} remoteUrl - 不含帳密的遠端 URL(形如 `https://host/owner/repo.git`)。
|
||||||
|
* @param {string} token - 具 push 權限的 token/PAT(作為 Basic 認證的密碼)。
|
||||||
|
* @param {string} refspec - push 的 refspec(形如 `HEAD:refs/heads/<branch>`)。
|
||||||
|
* @param {string} serverUrl - Gitea 伺服器根網址(用於定位 checkout 持久化 extraheader 的 scope)。
|
||||||
|
* @returns {void} 成功即返回;失敗拋出不含 URL/argv/token 的固定錯誤。
|
||||||
|
* @throws {Error} 推送失敗時拋出固定訊息(已隱藏遠端 URL 與認證資訊)。
|
||||||
|
* @remarks 本函式未匯出,僅供 {@link commitAndPushFindings} 使用。
|
||||||
|
*/
|
||||||
|
function pushWithCredential(cwd, remoteUrl, token, refspec, serverUrl) {
|
||||||
|
const server = new URL(serverUrl);
|
||||||
|
const remote = new URL(remoteUrl);
|
||||||
|
if (remote.origin !== server.origin || !remote.pathname.endsWith('.git')) {
|
||||||
|
throw new Error('推送遠端 URL 與 Gitea 伺服器不相符,已停止推送。');
|
||||||
|
}
|
||||||
|
const basic = Buffer.from(`ai-review-bot:${token}`).toString('base64');
|
||||||
|
// checkout 持久化自動 token 的 scope 為 `http.<serverUrl>/.extraheader`(結尾帶斜線)。
|
||||||
|
const headerScope = `http.${server.origin}/.extraheader`;
|
||||||
|
try {
|
||||||
|
execFileSync('git', ['push', remoteUrl, refspec], {
|
||||||
|
cwd,
|
||||||
|
encoding: 'utf8',
|
||||||
|
maxBuffer: 64 * 1024 * 1024,
|
||||||
|
env: {
|
||||||
|
...process.env,
|
||||||
|
GIT_TERMINAL_PROMPT: '0',
|
||||||
|
// 先清空 checkout extraheader,再注入本次 PAT header。
|
||||||
|
GIT_CONFIG_COUNT: '2',
|
||||||
|
GIT_CONFIG_KEY_0: headerScope,
|
||||||
|
GIT_CONFIG_VALUE_0: '',
|
||||||
|
GIT_CONFIG_KEY_1: headerScope,
|
||||||
|
GIT_CONFIG_VALUE_1: `Authorization: Basic ${basic}`,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} catch {
|
||||||
|
throw new Error('推送審查結果 commit 失敗(已隱藏遠端 URL 與認證資訊)。');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
latestCommitSubject,
|
latestCommitSubject,
|
||||||
resolveMergeBase,
|
resolveMergeBase,
|
||||||
|
|||||||
+59
-65
@@ -5,6 +5,7 @@ const path = require('path');
|
|||||||
|
|
||||||
const { log, taipeiFromIso, taipeiNow } = require('./log');
|
const { log, taipeiFromIso, taipeiNow } = require('./log');
|
||||||
const { runAgent, extractJson } = require('./agents');
|
const { runAgent, extractJson } = require('./agents');
|
||||||
|
const { agentFailureDetail } = require('./diagnostics');
|
||||||
const templates = require('./templates');
|
const templates = require('./templates');
|
||||||
|
|
||||||
// 審查流程核心:.reviewignore 過濾、diff 整理、攻擊方找問題、防守方裁決、排序分組與舊留言處理。
|
// 審查流程核心:.reviewignore 過濾、diff 整理、攻擊方找問題、防守方裁決、排序分組與舊留言處理。
|
||||||
@@ -13,71 +14,6 @@ const templates = require('./templates');
|
|||||||
const PER_FILE_DIFF_LIMIT = 16_000;
|
const PER_FILE_DIFF_LIMIT = 16_000;
|
||||||
const TOTAL_DIFF_LIMIT = 160_000;
|
const TOTAL_DIFF_LIMIT = 160_000;
|
||||||
|
|
||||||
/**
|
|
||||||
* 遮罩單行診斷文字中的機密與控制字元,避免寫進 CI log 時外洩。
|
|
||||||
*
|
|
||||||
* 處理順序:換行與控制字元一律壓成單一空白(避免注入假日誌行)→ 遮蔽
|
|
||||||
* `Authorization` 標頭、`token=`/`token:` 型憑證、URL 內嵌帳密、以及常見長金鑰/
|
|
||||||
* 長 hex/`ghp_` 等 token 樣式。屬「盡力遮罩」——無法窮舉所有機密格式,故僅在
|
|
||||||
* 明確開啟除錯輸出時作為第二道防線使用(見 {@link agentFailureDetail})。
|
|
||||||
*
|
|
||||||
* @param {*} text - 待遮罩的原始文字(非字串會先以 `String()` 轉型)。
|
|
||||||
* @returns {string} 已去控制字元並遮蔽常見機密樣式的單行文字。
|
|
||||||
* @remarks 本函式未匯出,僅供模組內部使用。
|
|
||||||
*/
|
|
||||||
function redactSecrets(text) {
|
|
||||||
return String(text ?? '')
|
|
||||||
.replace(/[\r\n\t\v\f\x00-\x1f\x7f]+/g, ' ')
|
|
||||||
.replace(/(authorization\s*[:=]\s*)\S+/gi, '$1***')
|
|
||||||
.replace(/((?:api[_-]?key|token|password|secret|bearer)\s*[:=]\s*)\S+/gi, '$1***')
|
|
||||||
.replace(/(https?:\/\/)[^\s/:@]+:[^\s/@]+@/gi, '$1***:***@')
|
|
||||||
.replace(/\bgh[pousr]_[A-Za-z0-9]{16,}\b/g, '***')
|
|
||||||
.replace(/\b[A-Za-z0-9_-]{40,}\b/g, '***')
|
|
||||||
.trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 從 `runAgent` 的失敗結果組出可診斷的一行摘要:退出碼/訊號為主,原始輸出預設隱藏。
|
|
||||||
*
|
|
||||||
* 安全考量:AI CLI 失敗時可能在 stderr/stdout 回顯提示內容、環境資訊、token、PII 或
|
|
||||||
* 原始碼祕密,這些會被長期保存並供多人讀取的 CI log 收錄。故本函式**預設只輸出**
|
|
||||||
* exit code/signal/killed 等不含機密的分類資訊;**僅在明確開啟 Actions step debug**
|
|
||||||
* (環境變數 `ACTIONS_STEP_DEBUG=true`)時,才附上經 {@link redactSecrets} 遮罩且去除
|
|
||||||
* 控制字元的 stderr/stdout 片段(各截前 500 字)作為診斷第二選擇。純函式、不拋例外。
|
|
||||||
*
|
|
||||||
* @param {{error: (Error & {code?: number|string, signal?: string, killed?: boolean})|null, stderr?: string, output?: string}} res
|
|
||||||
* `runAgent` 的回傳物件。
|
|
||||||
* @returns {string} 單行診斷摘要(各段以「|」分隔);無任何資訊時回傳固定字串。
|
|
||||||
* @remarks
|
|
||||||
* 使用情境:{@link runAttackers}/{@link runDefenders}/{@link fillPurposes}/{@link selectLabels}
|
|
||||||
* 判定 `!res.ok` 時,以本函式把失敗細節寫進 WRN log,讓 CI 記錄能看出 AI CLI 為何失敗;
|
|
||||||
* 需要原始輸出診斷時,於 workflow 設定 secret `ACTIONS_STEP_DEBUG=true` 再重跑。
|
|
||||||
* 本函式未匯出,僅供模組內部使用。
|
|
||||||
*/
|
|
||||||
function agentFailureDetail(res) {
|
|
||||||
const parts = [];
|
|
||||||
const err = res && res.error;
|
|
||||||
if (err) {
|
|
||||||
if (err.killed) parts.push('已逾時終止');
|
|
||||||
if (typeof err.code === 'number') parts.push(`exit ${err.code}`);
|
|
||||||
else if (err.code) parts.push(`code ${err.code}`);
|
|
||||||
else if (err.signal) parts.push(`signal ${err.signal}`);
|
|
||||||
}
|
|
||||||
// 預設不輸出 AI CLI 原始 stderr/stdout(可能含 token、PII 或原始碼祕密);
|
|
||||||
// 僅在明確開啟 Actions step debug 時,附上「已遮罩+去控制字元」的片段作為診斷。
|
|
||||||
const verbose = String(process.env.ACTIONS_STEP_DEBUG || '').trim().toLowerCase() === 'true';
|
|
||||||
if (verbose) {
|
|
||||||
const stderr = redactSecrets((res && res.stderr) || '');
|
|
||||||
if (stderr) parts.push(`stderr:${stderr.slice(0, 500)}`);
|
|
||||||
const stdout = redactSecrets((res && res.output) || '');
|
|
||||||
if (stdout) parts.push(`stdout:${stdout.slice(0, 500)}`);
|
|
||||||
}
|
|
||||||
if (parts.length === 0) {
|
|
||||||
parts.push((err && err.message && redactSecrets(err.message)) || 'AI CLI 執行失敗(詳細輸出已隱藏)');
|
|
||||||
}
|
|
||||||
return parts.join('|');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 讀取工作目錄下的 `.reviewignore`,解析為忽略路徑前綴清單。
|
* 讀取工作目錄下的 `.reviewignore`,解析為忽略路徑前綴清單。
|
||||||
*
|
*
|
||||||
@@ -621,6 +557,28 @@ function appendExclusions({ cwd, excluded, prNumber }) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 依審查模式與結果決定收尾要提交的結果檔。
|
||||||
|
*
|
||||||
|
* 一般模式永遠提交本回合 findings 檔;建問題模式通常把問題明細留在 issue,不提交
|
||||||
|
* findings。例外是有嚴重問題時仍提交 findings 檔,讓 `[failure]` 結果 commit 一定能產生,
|
||||||
|
* 避免問題相依 API 不支援或設定失敗時 PR 缺少失敗檢查。
|
||||||
|
*
|
||||||
|
* @param {Object} params - 解構參數。
|
||||||
|
* @param {boolean} params.createIssue - 是否啟用建問題模式。
|
||||||
|
* @param {number} params.severeCount - 嚴重 finding 數量。
|
||||||
|
* @param {string} params.relativePath - 本回合保存的 findings 檔 repo 相對路徑。
|
||||||
|
* @param {boolean} params.exclusionsChanged - exclusions.json 是否有實際異動。
|
||||||
|
* @returns {string[]} 應交給 `commitFindings` 的 repo 相對路徑清單。
|
||||||
|
*/
|
||||||
|
function resultFilesToCommit({ createIssue, severeCount, relativePath, exclusionsChanged }) {
|
||||||
|
const files = createIssue ? (severeCount > 0 ? [relativePath] : []) : [relativePath];
|
||||||
|
if (exclusionsChanged) {
|
||||||
|
files.push(path.join('.gitea', 'ai-review', 'exclusions.json'));
|
||||||
|
}
|
||||||
|
return files;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 就地排序 findings:依 嚴重→警告→建議、再依檔案路徑、再依起始行遞增。
|
* 就地排序 findings:依 嚴重→警告→建議、再依檔案路徑、再依起始行遞增。
|
||||||
*
|
*
|
||||||
@@ -874,6 +832,40 @@ async function resolveOldComments({ ctx, gitea, currentRunCommentIds }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 建問題模式:只將 PR 上舊的「追蹤問題連結」留言標註為過時,不觸碰 issue 內審查內容。
|
||||||
|
*
|
||||||
|
* @param {Object} params - 解構參數。
|
||||||
|
* @param {Object} params.ctx - 執行環境 context(`loadContext()` 產出)。
|
||||||
|
* @param {Object} params.gitea - Gitea API 模組,需提供 `whoAmI`、`listIssueComments`、`editIssueComment`。
|
||||||
|
* @returns {Promise<void>} 無回傳值;失敗時只記 WRN,不阻斷主流程。
|
||||||
|
*/
|
||||||
|
async function resolveOldIssueLinkComments({ ctx, gitea }) {
|
||||||
|
let botLogin = '';
|
||||||
|
try {
|
||||||
|
botLogin = (await gitea.whoAmI(ctx)).login || '';
|
||||||
|
} catch (err) {
|
||||||
|
log('建問題', 'WRN', `無法取得 bot 身分(${err.message}),略過舊追蹤連結標註。`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const comments = await gitea.listIssueComments(ctx);
|
||||||
|
let outdatedCount = 0;
|
||||||
|
for (const comment of comments) {
|
||||||
|
const isBot = comment.user && comment.user.login === botLogin;
|
||||||
|
const body = typeof comment.body === 'string' ? comment.body : '';
|
||||||
|
const isIssueLink = body.includes(templates.MARK) && body.includes('## 🔍 AI Code Review|已建立追蹤問題');
|
||||||
|
if (!isBot || !isIssueLink || body.startsWith(templates.OUTDATED_PREFIX)) continue;
|
||||||
|
await gitea.editIssueComment(ctx, comment.id, `${templates.OUTDATED_PREFIX}${body}`);
|
||||||
|
outdatedCount += 1;
|
||||||
|
}
|
||||||
|
log('建問題', 'INF', `舊追蹤 issue 連結已標註〔已過時〕:${outdatedCount} 則。`);
|
||||||
|
} catch (err) {
|
||||||
|
log('建問題', 'WRN', `標註舊追蹤 issue 連結失敗:${err.message}。`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 步驟 9:嚴重問題逐條掛在 PR 程式碼行上留言(建立 code review);
|
* 步驟 9:嚴重問題逐條掛在 PR 程式碼行上留言(建立 code review);
|
||||||
* 建立 review 失敗時降級為一般留言逐條發布(留言內補上檔案與行號位置)。
|
* 建立 review 失敗時降級為一般留言逐條發布(留言內補上檔案與行號位置)。
|
||||||
@@ -921,9 +913,11 @@ module.exports = {
|
|||||||
runDefenders,
|
runDefenders,
|
||||||
sortFindings,
|
sortFindings,
|
||||||
appendExclusions,
|
appendExclusions,
|
||||||
|
resultFilesToCommit,
|
||||||
selectLabels,
|
selectLabels,
|
||||||
postSevereToIssue,
|
postSevereToIssue,
|
||||||
postOthersToIssue,
|
postOthersToIssue,
|
||||||
resolveOldComments,
|
resolveOldComments,
|
||||||
|
resolveOldIssueLinkComments,
|
||||||
postSevereComments,
|
postSevereComments,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -302,7 +302,7 @@ function othersComment(findings) {
|
|||||||
* @param {string} [params.prBody] - PR 描述原文;nullish 或 trim 後為空時輸出佔位文字。
|
* @param {string} [params.prBody] - PR 描述原文;nullish 或 trim 後為空時輸出佔位文字。
|
||||||
* @returns {string} 完整 issue 本文 Markdown 字串(含 MARK 隱藏標記)。
|
* @returns {string} 完整 issue 本文 Markdown 字串(含 MARK 隱藏標記)。
|
||||||
* @remarks
|
* @remarks
|
||||||
* 使用情境:建問題模式下 `main()`(src/index.js)的 `ensureIssueCreated` 建立 issue 時,
|
* 使用情境:建問題模式下 `main()`(src/index.js)的 `createIssueAndFlushBufferedComments` 建立 issue 時,
|
||||||
* 以「標題=PR 標題、本文=本函式輸出」呼叫 `gitea.createIssue`,
|
* 以「標題=PR 標題、本文=本函式輸出」呼叫 `gitea.createIssue`,
|
||||||
* 讓 issue 讀者能從本文回溯到觸發審查的 PR,再從下方留言逐條查看問題明細。
|
* 讓 issue 讀者能從本文回溯到觸發審查的 PR,再從下方留言逐條查看問題明細。
|
||||||
*/
|
*/
|
||||||
@@ -334,9 +334,9 @@ ${body || '(PR 無描述)'}
|
|||||||
* @param {string} [finding.suggestedCode] - 建議寫法程式碼;有值才輸出「建議寫法」區塊。
|
* @param {string} [finding.suggestedCode] - 建議寫法程式碼;有值才輸出「建議寫法」區塊。
|
||||||
* @returns {string} 完整留言 Markdown 字串(含 MARK 隱藏標記)。
|
* @returns {string} 完整留言 Markdown 字串(含 MARK 隱藏標記)。
|
||||||
* @remarks
|
* @remarks
|
||||||
* 使用情境:建問題模式下 `review.postSevereToIssue`(src/lib/review.js)把每條嚴重 finding
|
* 使用情境:建問題模式下 `review.postSevereToIssue` 與 `review.postOthersToIssue`
|
||||||
* 以本函式產生留言內容、經 `gitea.createCommentOnIssue` 發布到追蹤 issue 上,
|
* 把每條 finding 以本函式產生留言內容、經 `gitea.createCommentOnIssue`
|
||||||
* 作為問題明細的追蹤紀錄。
|
* 發布到追蹤 issue 上,作為問題明細的追蹤紀錄。
|
||||||
*/
|
*/
|
||||||
function issueFindingComment(finding) {
|
function issueFindingComment(finding) {
|
||||||
const emoji = SEVERITY_EMOJI[finding.severity] || '🔵';
|
const emoji = SEVERITY_EMOJI[finding.severity] || '🔵';
|
||||||
@@ -400,7 +400,7 @@ function nothingToReviewComment(ignoredCount) {
|
|||||||
* 以本函式對 PR 留一則連結留言,達成「問題關聯回 PR」;issue 內文另以
|
* 以本函式對 PR 留一則連結留言,達成「問題關聯回 PR」;issue 內文另以
|
||||||
* {@link issueBody} 反向引用 `PR #N`,形成雙向交叉連結。
|
* {@link issueBody} 反向引用 `PR #N`,形成雙向交叉連結。
|
||||||
*/
|
*/
|
||||||
function issueLinkComment({ issueNumber, issueUrl, severeCount, otherCount }) {
|
function prIssueLinkComment({ issueNumber, issueUrl, severeCount, otherCount }) {
|
||||||
return `${MARK}
|
return `${MARK}
|
||||||
## 🔍 AI Code Review|已建立追蹤問題
|
## 🔍 AI Code Review|已建立追蹤問題
|
||||||
|
|
||||||
@@ -421,5 +421,5 @@ module.exports = {
|
|||||||
issueBody,
|
issueBody,
|
||||||
issueFindingComment,
|
issueFindingComment,
|
||||||
nothingToReviewComment,
|
nothingToReviewComment,
|
||||||
issueLinkComment,
|
prIssueLinkComment,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const assert = require('node:assert/strict');
|
||||||
|
const test = require('node:test');
|
||||||
|
|
||||||
|
const gitea = require('../src/lib/gitea');
|
||||||
|
|
||||||
|
function withFetchStub(handler, callback) {
|
||||||
|
const originalFetch = global.fetch;
|
||||||
|
const calls = [];
|
||||||
|
global.fetch = async (url, options = {}) => {
|
||||||
|
calls.push({ url, options });
|
||||||
|
return handler(url, options);
|
||||||
|
};
|
||||||
|
return Promise.resolve()
|
||||||
|
.then(() => callback(calls))
|
||||||
|
.finally(() => {
|
||||||
|
global.fetch = originalFetch;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function jsonResponse(data, ok = true, status = 200) {
|
||||||
|
return {
|
||||||
|
ok,
|
||||||
|
status,
|
||||||
|
async text() {
|
||||||
|
return JSON.stringify(data);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
test('addIssueDependency 使用正確 endpoint、method 與 IssueMeta body', async () => {
|
||||||
|
const ctx = {
|
||||||
|
apiBase: 'https://gitea.example.test/api/v1',
|
||||||
|
token: 'hidden',
|
||||||
|
owner: 'owner',
|
||||||
|
repo: 'repo',
|
||||||
|
};
|
||||||
|
|
||||||
|
await withFetchStub(() => jsonResponse({ ok: true }), async (calls) => {
|
||||||
|
await gitea.addIssueDependency(ctx, 12, 34);
|
||||||
|
|
||||||
|
assert.equal(calls.length, 1);
|
||||||
|
assert.equal(calls[0].url, 'https://gitea.example.test/api/v1/repos/owner/repo/issues/12/dependencies');
|
||||||
|
assert.equal(calls[0].options.method, 'POST');
|
||||||
|
assert.equal(calls[0].options.headers.Authorization, 'token hidden');
|
||||||
|
assert.deepEqual(JSON.parse(calls[0].options.body), {
|
||||||
|
index: 34,
|
||||||
|
owner: 'owner',
|
||||||
|
repo: 'repo',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('createIssue 空 labels 不送出 labels 欄位', async () => {
|
||||||
|
const ctx = {
|
||||||
|
apiBase: 'https://gitea.example.test/api/v1',
|
||||||
|
token: 'hidden',
|
||||||
|
owner: 'owner',
|
||||||
|
repo: 'repo',
|
||||||
|
};
|
||||||
|
|
||||||
|
await withFetchStub(() => jsonResponse({ number: 5 }), async (calls) => {
|
||||||
|
await gitea.createIssue(ctx, { title: 'title', body: 'body', labels: [] });
|
||||||
|
|
||||||
|
assert.equal(calls[0].url, 'https://gitea.example.test/api/v1/repos/owner/repo/issues');
|
||||||
|
assert.equal(calls[0].options.method, 'POST');
|
||||||
|
assert.deepEqual(JSON.parse(calls[0].options.body), {
|
||||||
|
title: 'title',
|
||||||
|
body: 'body',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const assert = require('node:assert/strict');
|
||||||
|
const test = require('node:test');
|
||||||
|
|
||||||
|
const gitrepo = require('../src/lib/gitrepo');
|
||||||
|
const gitref = require('../src/lib/gitref');
|
||||||
|
|
||||||
|
test('assertSafeBranchRef 接受一般分支名稱', () => {
|
||||||
|
assert.equal(gitref.assertSafeBranchRef('feature/review-123', 'baseRef'), 'feature/review-123');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('assertSafeBranchRef 拒絕路徑穿越分支名稱', () => {
|
||||||
|
assert.throws(
|
||||||
|
() => gitref.assertSafeBranchRef('../../hooks/pre-push', 'baseRef'),
|
||||||
|
/不是安全的分支名稱/,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('resolveMergeBase 會在 git fetch 前拒絕不安全 baseRef', () => {
|
||||||
|
assert.throws(
|
||||||
|
() => gitrepo.resolveMergeBase(process.cwd(), '../../hooks/pre-push'),
|
||||||
|
/不是安全的分支名稱/,
|
||||||
|
);
|
||||||
|
});
|
||||||
@@ -0,0 +1,136 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const assert = require('node:assert/strict');
|
||||||
|
const test = require('node:test');
|
||||||
|
|
||||||
|
const review = require('../src/lib/review');
|
||||||
|
const diagnostics = require('../src/lib/diagnostics');
|
||||||
|
|
||||||
|
test('agentFailureDetail 預設不輸出 stderr/stdout 片段', () => {
|
||||||
|
const oldDebug = process.env.ACTIONS_STEP_DEBUG;
|
||||||
|
delete process.env.ACTIONS_STEP_DEBUG;
|
||||||
|
try {
|
||||||
|
const detail = diagnostics.agentFailureDetail({
|
||||||
|
ok: false,
|
||||||
|
error: Object.assign(new Error('boom'), { code: 1 }),
|
||||||
|
stderr: 'token=super-secret-value',
|
||||||
|
output: 'stdout with password=hidden',
|
||||||
|
});
|
||||||
|
assert.match(detail, /exit 1/);
|
||||||
|
assert.doesNotMatch(detail, /super-secret-value|password|stdout|stderr/);
|
||||||
|
} finally {
|
||||||
|
if (oldDebug === undefined) delete process.env.ACTIONS_STEP_DEBUG;
|
||||||
|
else process.env.ACTIONS_STEP_DEBUG = oldDebug;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('agentFailureDetail 在 debug 模式輸出遮罩後片段', () => {
|
||||||
|
const oldDebug = process.env.ACTIONS_STEP_DEBUG;
|
||||||
|
process.env.ACTIONS_STEP_DEBUG = 'true';
|
||||||
|
try {
|
||||||
|
const detail = diagnostics.agentFailureDetail({
|
||||||
|
ok: false,
|
||||||
|
error: Object.assign(new Error('boom'), { code: 2 }),
|
||||||
|
stderr: 'Authorization: Bearer abcdefghijklmnopqrstuvwxyz1234567890',
|
||||||
|
output: 'token=abcdefghijklmnopqrstuvwxyz1234567890TOKEN',
|
||||||
|
});
|
||||||
|
assert.match(detail, /exit 2/);
|
||||||
|
assert.match(detail, /stderr:Authorization: \*\*\*/);
|
||||||
|
assert.match(detail, /stdout:token=\*\*\*/);
|
||||||
|
assert.doesNotMatch(detail, /abcdefghijklmnopqrstuvwxyz/);
|
||||||
|
} finally {
|
||||||
|
if (oldDebug === undefined) delete process.env.ACTIONS_STEP_DEBUG;
|
||||||
|
else process.env.ACTIONS_STEP_DEBUG = oldDebug;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('postOthersToIssue 依序送出 issue 留言以維持排序', async () => {
|
||||||
|
const calls = [];
|
||||||
|
let active = 0;
|
||||||
|
let maxActive = 0;
|
||||||
|
const fakeGitea = {
|
||||||
|
async createCommentOnIssue(ctx, issueNumber, body) {
|
||||||
|
active += 1;
|
||||||
|
maxActive = Math.max(maxActive, active);
|
||||||
|
calls.push({ ctx, issueNumber, body });
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 20));
|
||||||
|
active -= 1;
|
||||||
|
return { id: calls.length };
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
await review.postOthersToIssue({
|
||||||
|
ctx: { token: 'hidden' },
|
||||||
|
gitea: fakeGitea,
|
||||||
|
issueNumber: 7,
|
||||||
|
others: [
|
||||||
|
{ severity: '警告', reviewer: 'Maya', file: 'a.js', startLine: 1, endLine: 1, problem: 'p1', suggestion: 's1' },
|
||||||
|
{ severity: '建議', reviewer: 'Bard', file: 'b.js', startLine: 2, endLine: 2, problem: 'p2', suggestion: 's2' },
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.equal(calls.length, 2);
|
||||||
|
assert.equal(calls[0].issueNumber, 7);
|
||||||
|
assert.equal(maxActive, 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('resultFilesToCommit 在建問題模式有嚴重問題時仍提交 findings', () => {
|
||||||
|
assert.deepEqual(
|
||||||
|
review.resultFilesToCommit({
|
||||||
|
createIssue: true,
|
||||||
|
severeCount: 1,
|
||||||
|
relativePath: '.gitea/ai-review/findings/run.json',
|
||||||
|
exclusionsChanged: false,
|
||||||
|
}),
|
||||||
|
['.gitea/ai-review/findings/run.json'],
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('resultFilesToCommit 在建問題模式無嚴重問題時只提交 exclusions 異動', () => {
|
||||||
|
assert.deepEqual(
|
||||||
|
review.resultFilesToCommit({
|
||||||
|
createIssue: true,
|
||||||
|
severeCount: 0,
|
||||||
|
relativePath: '.gitea/ai-review/findings/run.json',
|
||||||
|
exclusionsChanged: true,
|
||||||
|
}),
|
||||||
|
['.gitea/ai-review/exclusions.json'],
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('resolveOldIssueLinkComments 只標註舊追蹤 issue 連結', async () => {
|
||||||
|
const edited = [];
|
||||||
|
const fakeGitea = {
|
||||||
|
async whoAmI() {
|
||||||
|
return { login: 'bot' };
|
||||||
|
},
|
||||||
|
async listIssueComments() {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
user: { login: 'bot' },
|
||||||
|
body: '<!-- ai-code-review -->\n## 🔍 AI Code Review|已建立追蹤問題\nold',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
user: { login: 'bot' },
|
||||||
|
body: '<!-- ai-code-review -->\n## 📋 變更摘要(送審 git diff)\nkeep',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 3,
|
||||||
|
user: { login: 'someone' },
|
||||||
|
body: '<!-- ai-code-review -->\n## 🔍 AI Code Review|已建立追蹤問題\nkeep',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
},
|
||||||
|
async editIssueComment(ctx, commentId, body) {
|
||||||
|
edited.push({ ctx, commentId, body });
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
await review.resolveOldIssueLinkComments({ ctx: { token: 'hidden' }, gitea: fakeGitea });
|
||||||
|
|
||||||
|
assert.equal(edited.length, 1);
|
||||||
|
assert.equal(edited[0].commentId, 1);
|
||||||
|
assert.match(edited[0].body, /^> 〔已過時〕/);
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user