fix(腳本契約): 長輸出不再被截斷,查重翻頁加上上限

process.stdout.write 之後立刻 process.exit 會截斷輸出——stdout 接到 pipe 時
寫入是非同步的。改為等 write 的 callback 回來再退出。實測舊寫法在約 83KB 處
被切斷,新增的回歸測試以 8000 筆標籤覆蓋這條路徑。

findIssueByTitle 的翻頁原本沒有上限,Gitea 若持續回滿一頁就會無限打下去。
加上 200 頁上限,超過即以 DEDUPE_LIMIT 報錯而非無聲回 null——無聲回 null 會
讓呼叫端把既有議題再建一次,正好是冪等查重要防的事。

parseFlags 取值時不再於三元運算式內遞增迴圈變數,改為獨立敘述。

測試工具的 maxBuffer 調高到 64MB:預設 1MB 會在長輸出時砍掉子行程,那是測試
工具的限制而非腳本的問題。

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-09-17 04:26:51 +00:00
co-authored by Claude Opus 5
parent 28dec83498
commit 4ae097f1e1
4 changed files with 55 additions and 9 deletions
+14
View File
@@ -111,3 +111,17 @@ test('plugin 根由自身檔案位置回推,templates 與 references 都在底
assert.ok(existsSync(templatesDir()));
assert.ok(existsSync(referencesDir()));
});
test('查重:翻頁有上限,查不完時報錯而不是無聲回 null', async (t) => {
// 無聲回 null 會讓呼叫端把既有議題再建一次,正好是查重要防的事
const full = Array.from({ length: 50 }, (_, i) => ({ number: i, title: `不相干的議題 ${i}` }));
const stub = await startStubGitea({
[`GET /api/v1/repos/${REPO}/issues`]: { status: 200, body: full },
});
t.after(() => stub.close());
await assert.rejects(
() => findIssueByTitle({ base: stub.base, token: 'x' }, REPO, '永遠找不到的標題'),
(error) => error.code === 'DEDUPE_LIMIT',
);
});