test: 整併測試至 app/test 並解決 AI 審查 findings #8
@@ -3,7 +3,7 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
|
||||
const { fetchReleases } = require('../releases');
|
||||
const { fetchReleases, truncateString } = require('../releases');
|
||||
|
||||
// 以可控的假回應替換全域 fetch,並於結束後還原
|
||||
function withFetch(handler, run) {
|
||||
@@ -77,6 +77,15 @@ test('fetchReleases 對無法解析的 JSON 回應拋錯', async () => {
|
||||
);
|
||||
});
|
||||
|
||||
test('truncateString 以字元截斷且不拆分多位元組字元(emoji 代理對)', () => {
|
||||
|
Ghost marked this conversation as resolved
Outdated
|
||||
const emojis = '😀'.repeat(25);
|
||||
const result = truncateString(emojis, 10);
|
||||
// 應得到完整 10 個 emoji(以 code point 計),不殘留落單的代理碼元
|
||||
assert.equal(Array.from(result).length, 10);
|
||||
assert.equal(result, '😀'.repeat(10));
|
||||
assert.ok(!/[\uD800-\uDBFF](?![\uDC00-\uDFFF])/.test(result), '不應殘留落單的高代理碼元');
|
||||
});
|
||||
|
||||
test('fetchReleases 解析失敗時截斷過長的回應片段', async () => {
|
||||
const huge = `{${'x'.repeat(5000)}`;
|
||||
await withFetch(
|
||||
|
||||
Reference in New Issue
Block a user
嚴重等級:🟡 警告
審查員:Maya
問題:新增的 JSON 解析錯誤處理邏輯中,對於回應內容片段(contentSnippet)的生成與截斷行為並未進行驗證。目前的測試僅檢查錯誤訊息是否包含特定字串,未確保截斷邏輯在邊界條件(如超長回應、包含特殊字元)下是否正確。
建議:建議在
app/test/releases.test.js中增加針對無法解析 JSON 的測試案例,並具體斷言錯誤訊息中包含預期的片段內容,特別是需要測試超長字串截斷是否符合預期。