fix(pr-create): 錶沒在跑時 409 與 500 都不算失敗
Gitea 回「cannot stop a non-existent stopwatch」時用的狀態碼隨站台而異:這台回 409, 而腳本只認 500。結果是 PR 已經開出去了,卻以 exit 1 與 HTTP_ERROR 收場——照它自己 寫下的理由,那會讓人以為 PR 沒開成而重跑一次。三次重現(議題 #41、#50、#42)。 認的是「狀態碼在 409/500 這一組 **且** 訊息說的是碼錶」:只看訊息會把真的伺服器錯誤 一起吞掉,只看狀態碼會把別的衝突也當成沒錶。兩種狀態碼各一條測試,另加一條 「訊息對不上的 409 照常拋出」。 README 與 AGENTS.md 的「六個流程正本尚未到齊」也一併改掉——六份都在了,那句話會讓 使用者以為裝了也沒指令可用,在 AGENTS.md 裡還會誤導下一個 agent。並補一條測試把說法 與 prompts/ 的實際份數釘在一起,免得下次又走鐘。 議題 #54 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
+37
-8
@@ -303,21 +303,50 @@ test('PR 開失敗時不停錶:工時要記在真的有做事的那段時間
|
||||
assert.match(json.error.message, /422|already exists/);
|
||||
});
|
||||
|
||||
test('錶本來就沒在跑時不算失敗:PR 已經開出去了', async (t) => {
|
||||
// Gitea 對「沒有碼錶在跑」回 500;這時 PR 已經建立,不該把整件事報成失敗
|
||||
/**
|
||||
* 「沒有碼錶在跑」這件事,Gitea 不只用一種狀態碼回。
|
||||
* 站台版本不同回法就不同,而這時 PR 已經建立——把整件事報成失敗,使用者會以為 PR
|
||||
* 沒開成而重跑一次。
|
||||
*/
|
||||
const NO_STOPWATCH = [
|
||||
{ status: 500, message: 'cannot stop a non existent stopwatch' },
|
||||
{ status: 409, message: 'cannot stop a non-existent stopwatch' },
|
||||
];
|
||||
|
||||
for (const { status, message } of NO_STOPWATCH) {
|
||||
test(`錶本來就沒在跑時不算失敗(HTTP ${status}):PR 已經開出去了`, async (t) => {
|
||||
const stub = await withStub(t, {
|
||||
[`POST /api/v1/repos/${ISSUE_REPO}/issues/${INDEX}/stopwatch/stop`]: {
|
||||
status,
|
||||
body: { message },
|
||||
},
|
||||
});
|
||||
const file = bodyFile(`nowatch-${status}`, BODY);
|
||||
|
||||
const { code, json } = await runFull(file, stub);
|
||||
|
||||
assert.equal(code, 0, JSON.stringify(json));
|
||||
assert.equal(json.data.碼錶已停, false);
|
||||
assert.match(json.data.note ?? '', /碼錶/);
|
||||
assert.ok(json.data.url, 'PR 的網址照常回報:它真的開出去了');
|
||||
});
|
||||
}
|
||||
|
||||
test('訊息對不上碼錶的 409 照常拋出,不被一起吞掉', async (t) => {
|
||||
// 只有「沒有碼錶在跑」那一種能被當成不算失敗;其餘的 409 是真的有問題
|
||||
const stub = await withStub(t, {
|
||||
[`POST /api/v1/repos/${ISSUE_REPO}/issues/${INDEX}/stopwatch/stop`]: {
|
||||
status: 500,
|
||||
body: { message: 'cannot stop a non existent stopwatch' },
|
||||
status: 409,
|
||||
body: { message: 'issue is locked' },
|
||||
},
|
||||
});
|
||||
const file = bodyFile('nowatch', BODY);
|
||||
const file = bodyFile('locked', BODY);
|
||||
|
||||
const { code, json } = await runFull(file, stub);
|
||||
|
||||
assert.equal(code, 0, JSON.stringify(json));
|
||||
assert.equal(json.data.碼錶已停, false);
|
||||
assert.match(json.data.note ?? '', /碼錶/);
|
||||
assert.equal(code, 1);
|
||||
assert.equal(json.error.code, 'HTTP_ERROR');
|
||||
assert.match(json.error.message, /409/);
|
||||
});
|
||||
|
||||
test('沒給 --index 時擋下:停錶是這一步的一部分,忘了給會讓工時算不準', async (t) => {
|
||||
|
||||
Reference in New Issue
Block a user