From 61bc34678b54fce9fec5134024dbc1135dc49eaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A5=81=E8=BF=9E=E6=B5=B7?= <2825305047@qq.com> Date: Sat, 18 Apr 2026 20:54:31 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E8=BF=90=E8=A1=8C=E6=8E=A7=E5=88=B6=E5=99=A8=EF=BC=8C=E9=81=87?= =?UTF-8?q?=E5=88=B0=20add-phone=20=E9=A1=B5=E6=97=B6=E7=9B=B4=E6=8E=A5?= =?UTF-8?q?=E7=BB=93=E6=9D=9F=E5=BD=93=E5=89=8D=E8=BD=AE=E5=B9=B6=E7=BB=A7?= =?UTF-8?q?=E7=BB=AD=E4=B8=8B=E4=B8=80=E8=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- background/auto-run-controller.js | 38 ++++++++++++++++++--------- tests/auto-run-add-phone-stop.test.js | 13 +++++---- 项目完整链路说明.md | 2 +- 项目文件结构说明.md | 2 +- 4 files changed, 35 insertions(+), 20 deletions(-) diff --git a/background/auto-run-controller.js b/background/auto-run-controller.js index 40d905e..36cc6d9 100644 --- a/background/auto-run-controller.js +++ b/background/auto-run-controller.js @@ -460,30 +460,42 @@ const blockedByAddPhone = typeof isAddPhoneAuthFailure === 'function' && isAddPhoneAuthFailure(err); const canRetry = !blockedByAddPhone && autoRunSkipFailures && attemptRun < maxAttemptsForRound; - if (blockedByAddPhone) { - roundSummary.status = 'failed'; - roundSummary.finalFailureReason = reason; - } - await setState({ autoRunRoundSummaries: serializeAutoRunRoundSummaries(totalRuns, roundSummaries), }); if (blockedByAddPhone) { + roundSummary.status = 'failed'; + roundSummary.finalFailureReason = reason; + await setState({ + autoRunRoundSummaries: serializeAutoRunRoundSummaries(totalRuns, roundSummaries), + }); await appendRoundRecordIfNeeded('failed', reason); cancelPendingCommands('当前轮因认证流程进入 add-phone 已终止。'); await broadcastStopToContentScripts(); + if (!autoRunSkipFailures) { + await addLog( + `第 ${targetRun}/${totalRuns} 轮触发 add-phone/手机号页,自动重试未开启,当前自动运行将停止。`, + 'warn' + ); + stoppedEarly = true; + await broadcastAutoRunStatus('stopped', { + currentRun: targetRun, + totalRuns, + attemptRun, + sessionId: 0, + }); + break; + } + + await addLog(`第 ${targetRun}/${totalRuns} 轮触发 add-phone/手机号页,本轮将直接失败并跳过剩余重试。`, 'warn'); await addLog( - `第 ${targetRun}/${totalRuns} 轮触发 add-phone/手机号页,当前自动运行将立即停止,不再重试或进入下一轮。`, + targetRun < totalRuns + ? `第 ${targetRun}/${totalRuns} 轮因 add-phone/手机号页提前结束,自动流程将继续下一轮。` + : `第 ${targetRun}/${totalRuns} 轮因 add-phone/手机号页提前结束,已无后续轮次,本次自动运行结束。`, 'warn' ); - stoppedEarly = true; - await broadcastAutoRunStatus('stopped', { - currentRun: targetRun, - totalRuns, - attemptRun, - sessionId: 0, - }); + forceFreshTabsNextRun = true; break; } diff --git a/tests/auto-run-add-phone-stop.test.js b/tests/auto-run-add-phone-stop.test.js index af16ce7..0ca3f7e 100644 --- a/tests/auto-run-add-phone-stop.test.js +++ b/tests/auto-run-add-phone-stop.test.js @@ -6,7 +6,7 @@ const source = fs.readFileSync('background/auto-run-controller.js', 'utf8'); const globalScope = {}; const api = new Function('self', `${source}; return self.MultiPageBackgroundAutoRunController;`)(globalScope); -test('auto-run controller does not retry add-phone failures even when auto retry is enabled', async () => { +test('auto-run controller skips add-phone failures to the next round instead of stopping when auto retry is enabled', async () => { const events = { logs: [], broadcasts: [], @@ -123,7 +123,9 @@ test('auto-run controller does not retry add-phone failures even when auto retry }, runAutoSequenceFromStep: async () => { events.runCalls += 1; - throw new Error('步骤 8:验证码提交后页面进入手机号页面,当前流程无法继续自动授权。 URL: https://auth.openai.com/add-phone'); + if (events.runCalls === 1) { + throw new Error('步骤 8:验证码提交后页面进入手机号页面,当前流程无法继续自动授权。 URL: https://auth.openai.com/add-phone'); + } }, runtime, setState: async (updates = {}) => { @@ -151,17 +153,18 @@ test('auto-run controller does not retry add-phone failures even when auto retry }, }); - await controller.autoRunLoop(1, { + await controller.autoRunLoop(2, { autoRunSkipFailures: true, mode: 'restart', }); - assert.equal(events.runCalls, 1, 'add-phone fatal failure should stop before the next auto attempt starts'); + assert.equal(events.runCalls, 2, 'add-phone failure should skip the current round and continue with the next round'); assert.equal(events.broadcasts.some(({ phase }) => phase === 'retrying'), false, 'add-phone fatal failure should not enter retrying phase'); assert.equal(events.accountRecords.length, 1, 'fatal add-phone should still persist a failed round record'); assert.equal(events.accountRecords[0].status, 'failed'); assert.match(events.accountRecords[0].reason, /add-phone/); - assert.ok(events.logs.some(({ message }) => /add-phone\/手机号页/.test(message))); + assert.ok(events.logs.some(({ message }) => /继续下一轮/.test(message))); + assert.equal(events.broadcasts.some(({ phase }) => phase === 'stopped'), false, 'add-phone failure should not stop the whole auto-run when skip failures is enabled'); assert.equal(runtime.state.autoRunActive, false); assert.equal(runtime.state.autoRunSessionId, 0); }); diff --git a/项目完整链路说明.md b/项目完整链路说明.md index 6ae3520..c5f2e3a 100644 --- a/项目完整链路说明.md +++ b/项目完整链路说明.md @@ -453,7 +453,7 @@ - 步骤 7 内部仍保留登录态恢复的有限重试,但 `add-phone / 手机号页` 属于立即跳出的不可重试错误 - 步骤 8 若在验证码提交后进入 `add-phone / 手机号页`,会直接抛出 fatal 错误,不再先标记步骤成功 - 一旦进入步骤 7~10,遇到普通报错且认证流程未进入 `add-phone`,则自动回到步骤 7 无限重开 - - 如果命中 `add-phone / 手机号页` 这类 fatal 错误,则不仅不会回到步骤 7 重开,也不会进入 controller 的下一次自动重试 attempt + - 如果命中 `add-phone / 手机号页` 这类 fatal 错误,则不会再做当前轮的内部重试;当开启自动重试/跳过失败时,会直接结束当前轮并继续下一轮,而不是把整条自动流程暂停 - 如果是手动停止,则立即退出自动流程,不会再触发“回到步骤 7 重开” 6. 如果失败,根据设置决定: - 立即停止 diff --git a/项目文件结构说明.md b/项目文件结构说明.md index 940ec68..b6c2b8c 100644 --- a/项目文件结构说明.md +++ b/项目文件结构说明.md @@ -124,7 +124,7 @@ - `tests/auth-page-recovery.test.js`:测试认证页共享恢复层的重试页识别与恢复行为。 - `tests/auto-run-fresh-attempt-reset.test.js`:测试自动运行在新一轮开始前会重置旧运行时上下文,并补充 `gmailBaseEmail` / `mail2925BaseEmail` 在 fresh reset 后仍被保留的回归验证。 - `tests/auto-run-timer-session-guard.test.js`:测试自动运行的旧计时计划在 Stop 使 session 失效后,不能再把已停止的自动流程重新拉起。 -- `tests/auto-run-add-phone-stop.test.js`:测试自动运行控制器在开启自动重试时,遇到 `add-phone / 手机号页` 也会立即停止,不会再开新 attempt。 +- `tests/auto-run-add-phone-stop.test.js`:测试自动运行控制器在开启自动重试时,遇到 `add-phone / 手机号页` 会直接结束当前轮并继续下一轮,而不是把整条自动流程暂停。 - `tests/auto-run-step6-restart.test.js`:测试自动运行在后半段授权链路遇错时会回到步骤 7 重开,并在命中 add-phone 或泛化手机号页 fatal 错误时停止重开。 - `tests/auto-step-random-delay.test.js`:测试自动运行步间延迟与旧配置键兼容解析。 - `tests/background-auto-run-module.test.js`:测试自动运行控制器模块已接入且导出工厂。