From f0a42cd98da7a47d332464215b0131c84a60fb0b Mon Sep 17 00:00:00 2001 From: Jeffery Date: Fri, 26 Jun 2026 15:26:08 +0800 Subject: [PATCH] =?UTF-8?q?test(git):=20=E8=A3=9C=20commitAndPush=20?= =?UTF-8?q?=E5=9C=A8=20push=20=E5=A4=B1=E6=95=97=E6=99=82=E4=B8=8D?= =?UTF-8?q?=E4=B8=AD=E6=96=B7=E6=B5=81=E7=A8=8B=E7=9A=84=E6=B8=AC=E8=A9=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.8 (1M context) --- app/test/git.test.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/test/git.test.js b/app/test/git.test.js index a4b4965..9d9b151 100644 --- a/app/test/git.test.js +++ b/app/test/git.test.js @@ -208,6 +208,23 @@ describe('commitAndPush', () => { assert.ok(logs.some(line => line.includes('Step8 commit 成功但 push 失敗'))); assert.ok(logs.some(line => line.includes('pre-receive hook declined'))); }); + + it('does not throw and does not mistake a failed push for success (commit still ran, push attempted)', async () => { + // commit 成功、僅 push 失敗:函式必須吞掉錯誤不中斷上層流程。 + const spawn = makeSpawn({ + push: () => ({ status: 1, stdout: '', stderr: 'fatal: unable to access remote', error: null }), + }); + + await assert.doesNotReject( + () => commitAndPush(workspace, path.join(workspace, 'repo'), spawn, sourceRoot), + 'push failure must not crash the pipeline', + ); + + const commitCall = spawn.calls.find(c => c.args[0] === 'commit'); + assert.ok(commitCall, 'commit should still run before the failed push'); + const pushCall = spawn.calls.find(c => c.args[0] === 'push'); + assert.ok(pushCall, 'push should have been attempted'); + }); }); describe('cloneRepo', () => {