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 8 additions and 6 deletions
Showing only changes of commit da83f4fc30 - Show all commits
+5 -3
View File
@@ -58,9 +58,11 @@ function assertHttpUrl(name, value) {
// 驗證 repository 為 owner/repo 格式(僅允許字母數字與 . _ -,且拒絕 . 與 .. 路徑穿越段)
function assertRepository(name, value) {
const parts = value.split('/');
const valid = parts.length === 2
&& parts.every((part) => /^[A-Za-z0-9._-]+$/.test(part) && part !== '.' && part !== '..');
if (!valid) {
const isRepoFormatValid = parts.length === 2
&& parts.every((part) => part.length > 0 && part.length <= 100
&& /^[A-Za-z0-9._-]+$/.test(part)
Review

嚴重等級🔵 建議
審查員:Leo
問題:在 assertGiteaRepositoryFormat 函式中,當 value.split('/') 的長度不為 2 時,拋出的錯誤訊息僅籠統地說「格式錯誤」。若使用者輸入了包含多個斜線或完全沒有斜線的字串,這類訊息對修正環境變數幫助有限。
建議:建議區分「格式不符」與「內容不符」的錯誤細節,例如提示「必須為 owner/repo 格式,包含一個斜線」。

**嚴重等級**:🔵 建議 **審查員**:Leo **問題**:在 `assertGiteaRepositoryFormat` 函式中,當 `value.split('/')` 的長度不為 2 時,拋出的錯誤訊息僅籠統地說「格式錯誤」。若使用者輸入了包含多個斜線或完全沒有斜線的字串,這類訊息對修正環境變數幫助有限。 **建議**:建議區分「格式不符」與「內容不符」的錯誤細節,例如提示「必須為 owner/repo 格式,包含一個斜線」。
&& part !== '.' && part !== '..');
if (!isRepoFormatValid) {
Ghost marked this conversation as resolved
Review

嚴重等級🟡 警告
審查員:Bard
問題:函數 assertRepository 命名較為通用,但其實際行為僅在驗證 Gitea 的 owner/repo 格式。命名未能直接體現其檢查邏輯與該領域規則。
建議:建議重新命名為 assertGiteaRepositoryFormat,讓開發者一眼就能看出該函數在檢查特定的 Gitea 倉庫格式規範。

**嚴重等級**:🟡 警告 **審查員**:Bard **問題**:函數 `assertRepository` 命名較為通用,但其實際行為僅在驗證 Gitea 的 `owner/repo` 格式。命名未能直接體現其檢查邏輯與該領域規則。 **建議**:建議重新命名為 `assertGiteaRepositoryFormat`,讓開發者一眼就能看出該函數在檢查特定的 Gitea 倉庫格式規範。
throw new Error(`${name} 格式錯誤,必須為 owner/repo`);
}
}
+3 -3
View File
1
@@ -63,9 +63,9 @@ async function fetchReleases(baseUrl, options = {}) {
try {
pageJson = JSON.parse(text);
} catch {
// 附上截斷回傳內容片段,便於除錯回傳格式異常
const snippet = text.slice(0, 200);
throw new Error(`release API 回傳資料無法解析 (page=${page}): ${snippet}`);
// 以字元(而非 UTF-16 碼元)截斷回傳內容片段,避免拆分多位元組字元造成亂碼
const contentSnippet = Array.from(text).slice(0, 200).join('');
throw new Error(`release API 回傳資料無法解析 (page=${page}),回應內容片段:「${contentSnippet}`);
}
if (pageJson === null) {