test: 整併測試至 app/test 並解決 AI 審查 findings #8

Closed
jiantw83 wants to merge 23 commits from test/consolidate-app-test-20260626-111823 into develop
2 changed files with 7 additions and 45 deletions
Showing only changes of commit 14c7ac4ed0 - Show all commits
+6
View File
@@ -64,5 +64,11 @@
"role": "Leo", "role": "Leo",
"original_finding": "withFetch 為全域 fetch 的通用封裝工具,目前定義在特定測試檔案內。建議提取至獨立的測試工具檔案(例如 app/test/test-utils.js)以提升重用性。", "original_finding": "withFetch 為全域 fetch 的通用封裝工具,目前定義在特定測試檔案內。建議提取至獨立的測試工具檔案(例如 app/test/test-utils.js)以提升重用性。",
"reason": "目前僅 releases.test.js 單一測試檔使用 withFetchlogger.test.js 使用的是不同的 stdout/stderr 攔截輔助),尚無第二個消費者;為單一用途提前抽出共用模組屬過度設計。" "reason": "目前僅 releases.test.js 單一測試檔使用 withFetchlogger.test.js 使用的是不同的 stdout/stderr 攔截輔助),尚無第二個消費者;為單一用途提前抽出共用模組屬過度設計。"
},
{
"location": "app/test/logger.test.js:8",
"role": "Leo",
"original_finding": "在測試中使用 monkey-patch 直接覆蓋 process.stdout.write 或 process.stderr.write 是極度危險的模式,可能導致狀態污染;建議重構 logger 使其支援依賴注入。",
"reason": "攔截已於 finally 還原原本的 write,無狀態污染,且為 Node 測試 stdout/stderr 輸出的標準作法;logger 僅是寫入 stdout/stderr 的薄封裝,為其引入依賴注入框架屬過度設計。已將兩個攔截輔助合併為單一 captureStream。"
} }
] ]
+1 -45
View File
@@ -1,45 +1 @@
[ []
{
"level": "critical",
"role": "Maya",
"location": "app/releases.js:68",
"problem": "新增的異常處理邏輯截斷了 `text` 為 200 字元,但在 `text` 為極大值或無法轉為字串時未進行防禦性檢查,且截斷點可能將多位元組字元拆分導致亂碼。",
"suggestion": "請確保 `text` 是字串後再截斷,並使用正確處理多位元組字元的方式(如 `Array.from(text).slice(0, 200).join('')`)以避免亂碼。",
"is_new": true
},
{
"level": "warning",
"role": "Maya",
"location": "app/config.js:61",
"problem": "新增的 `assertRepository` 函式缺乏對 owner/repo 字串長度的邊界檢查,且變數名稱 `valid` 過於通用,語義不夠明確。",
"suggestion": "建議在 `assertRepository` 中加入長度限制檢查,並將 `valid` 更名為 `isRepoFormatValid` 或類似具備明確語義的命名。"
},
{
"level": "warning",
"role": "Leo",
"location": "app/test/logger.test.js:8",
"problem": "在測試中使用 monkey-patch 直接覆蓋 `process.stdout.write` 或 `process.stderr.write` 是極度危險的模式,可能導致狀態污染;且針對 `logger.error` 的測試不夠全面。",
"suggestion": "建議重構 `logger` 使其支援依賴注入;並增加針對錯誤內容包含情況及非字串參數的斷言測試。"
},
{
"level": "warning",
"role": "Maya",
"location": "app/test/config.test.js:84",
"problem": "缺少針對 `assertRepository` 邊界條件(如空字串、異常格式)的測試。",
"suggestion": "補上 `assert.throws` 測試案例以涵蓋上述邊界條件,確保驗證邏輯完整。"
},
{
"level": "info",
"role": "Bard",
"location": "app/releases.js:67",
"problem": "將截斷字串直接串接在 Error 訊息中若處理不當易造成混淆,變數名稱 `snippet` 語義不明確。",
"suggestion": "建議在錯誤訊息中對片段內容進行適當標記,並將變數更名為 `contentSnippet`。"
},
{
"level": "info",
"role": "Bard",
"location": "app/test/logger.test.js:10",
"problem": "測試工具函式 `captureStdout` 與 `captureStderr` 邏輯高度重複,不符合 DRY 原則。",
"suggestion": "建議抽取出通用的 `captureStream(stream, fn)` 函式以提升可維護性。"
}
]