test(release-cleanup): 補上異常結構 release 與 fetchAllPages 失敗測試

新增 cleanupReleases 處理 null/缺欄位 release 不拋例外的測試,以及
cleanupOrphanTags 在 fetchAllPages 拋錯時向外拋出的測試。測試共 64 項全數通過。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jeffery
2026-06-26 13:59:49 +08:00
co-authored by Claude Opus 4.8
parent 24bcad7141
commit 9a71e2d09d
2 changed files with 26 additions and 0 deletions
+14
View File
@@ -140,6 +140,20 @@ test('cleanupReleases 在刪除回傳非 204 時記錄錯誤至 stderr', async (
assert.match(chunks.join(''), /\[ERR\]/)
})
test('cleanupReleases 對含 null/異常結構的 release 不拋例外且照常處理正常項目', async () => {
const client = fakeClient([
{ id: 3, tag_name: 'v3', name: 'n3', created_at: '2024-03-01T00:00:00Z' },
null,
{ created_at: '2024-02-01T00:00:00Z' }, // 缺 id/tag_name
{ id: 1, tag_name: 'v1', name: 'n1', created_at: '2024-01-01T00:00:00Z' },
])
await assert.doesNotReject(() =>
cleanupReleases(client, { releaseApiUrl: 'http://x/releases', keepCount: 1 }),
)
// 保留最新(id=3);待刪除者中僅 id=1 為有效正整數 id,其餘(null、缺 id)被略過
assert.deepEqual(client.deleted, ['http://x/releases/1'])
})
test('cleanupReleases 略過沒有 id 的 release', async () => {
const client = fakeClient([
{ id: 1, tag_name: 'v3', name: 'n3', created_at: '2024-03-01T00:00:00Z' },
+12
View File
@@ -114,6 +114,18 @@ test('cleanupOrphanTags 在刪除回傳非 204 時繼續處理其餘 tag 並記
assert.match(chunks.join(''), /\[ERR\]/)
})
test('cleanupOrphanTags 在 fetchAllPages 拋錯時向外拋出', async () => {
const client = {
async fetchAllPages() {
throw new Error('GET http://x/releases?page=1 failed: HTTP 500')
},
async deleteResource() {
return 204
},
}
await assert.rejects(() => cleanupOrphanTags(client, config), /HTTP 500/)
})
test('cleanupOrphanTags 對含特殊字元的 tag 名稱進行 URL 編碼(防路徑穿越)', async () => {
const client = fakeClient({
releases: [],