test(release-cleanup): 補上結束碼、sanitizeBody 與 logger 輸出測試
新增子行程驗證 index.js 失敗時以非零狀態結束、fetchAllPages 錯誤訊息 清理控制字元與長度限制、以及 logger 各輸出函式格式與 stdout/stderr 分流測試。 測試共 56 項全數通過。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
87db9030d6
commit
826b559006
@@ -122,6 +122,26 @@ test('fetchAllPages 在頁數超過 MAX_PAGES 時中止以避免無限迴圈', a
|
||||
)
|
||||
})
|
||||
|
||||
test('fetchAllPages 的錯誤訊息會清理控制字元並限制長度(sanitizeBody)', async () => {
|
||||
const nasty = 'line1\nline2\r\tinjected' + 'x'.repeat(500)
|
||||
globalThis.fetch = async () => ({
|
||||
ok: false,
|
||||
status: 500,
|
||||
text: async () => nasty,
|
||||
})
|
||||
const client = new GiteaClient({})
|
||||
let message = ''
|
||||
try {
|
||||
await client.fetchAllPages('https://example.com/api')
|
||||
} catch (error) {
|
||||
message = error.message
|
||||
}
|
||||
// 控制字元(換行、Tab 等)已被移除
|
||||
assert.doesNotMatch(message, /[\u0000-\u001F]/)
|
||||
// 回應內容片段受 200 字元上限約束(原始有 500 個 x)
|
||||
assert.ok((message.match(/x/g) || []).length <= 200)
|
||||
})
|
||||
|
||||
test('deleteResource 回傳 HTTP 狀態碼', async () => {
|
||||
globalThis.fetch = async (url, opts) => {
|
||||
assert.equal(opts.method, 'DELETE')
|
||||
|
||||
Reference in New Issue
Block a user