From 8c2cb2f8e0aa800fe2a263e4a76f6543309530a1 Mon Sep 17 00:00:00 2001 From: QLHazyCoder <2825305047@qq.com> Date: Sat, 30 May 2026 02:35:07 +0800 Subject: [PATCH] fix: stop GPC flow on no-trial logs --- .../background/steps/fill-plus-checkout.js | 13 ++++++++++ ...us-checkout-billing-tab-resolution.test.js | 25 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/flows/openai/background/steps/fill-plus-checkout.js b/flows/openai/background/steps/fill-plus-checkout.js index 9b7cadc..1674567 100644 --- a/flows/openai/background/steps/fill-plus-checkout.js +++ b/flows/openai/background/steps/fill-plus-checkout.js @@ -289,6 +289,18 @@ return summary ? ` 最近日志:${summary}` : ''; } + function hasGpcNoTrialFailure(pageState = {}) { + if (pageState.noTrial) { + return true; + } + const text = normalizeText([ + pageState.lastLogLine, + pageState.logText, + pageState.bodyText, + ].filter(Boolean).join(' ')); + return /(?:该|此|当前)?账[户号].{0,12}(?:没有|无|不具备).{0,8}试用资格|(?:没有|无|不具备).{0,8}试用资格/.test(text); + } + async function ensureGpcCardMode(tabId) { if (!chrome?.scripting?.executeScript) { throw new Error('步骤 7:当前运行环境不支持脚本注入,无法切换 GPC 卡密充值模式。'); @@ -485,6 +497,7 @@ while (Date.now() <= deadline) { throwIfStopped(); const pageState = await inspectGpcPortalPage(tabId); + pageState.noTrial = hasGpcNoTrialFailure(pageState); const buttonText = normalizeText(pageState.startButtonText); await collectStatusLog(pageState, buttonText); diff --git a/tests/plus-checkout-billing-tab-resolution.test.js b/tests/plus-checkout-billing-tab-resolution.test.js index 680039d..ae0d559 100644 --- a/tests/plus-checkout-billing-tab-resolution.test.js +++ b/tests/plus-checkout-billing-tab-resolution.test.js @@ -1119,6 +1119,31 @@ test('GPC billing fails current round without restart when account has no trial assert.equal(events.completed.length, 0); }); +test('GPC billing treats no-trial log text as terminal even when page flag is missing', async () => { + const { events, executor, pageHarness } = createGpcPageExecutorHarness([ + { startButtonText: '开始 Plus 充值', logText: 'SYSTEM 页面已就绪' }, + { startButtonText: '任务进行中', logText: '处理中' }, + { + startButtonText: '开始 Plus 充值', + logText: '[02:30:00] ACTION 任务开始执行... [02:30:18] ERROR 该账号没有试用资格', + noTrial: false, + }, + ]); + + await assert.rejects( + () => executor.executePlusCheckoutBilling({ + plusPaymentMethod: 'gpc-helper', + plusCheckoutSource: 'gpc-helper', + plusCheckoutTabId: 77, + }), + /PLUS_CHECKOUT_NON_FREE_TRIAL::.*该账户没有试用资格.*最近日志:\[02:30:18\] ERROR 该账号没有试用资格/ + ); + + assert.equal(pageHarness.clicks.length, 1); + assert.equal(events.logs.some((entry) => /准备再次启动/.test(entry.message)), false); + assert.equal(events.completed.length, 0); +}); + test('GPC billing times out when page never finishes', async () => { const { executor, pageHarness } = createGpcPageExecutorHarness([ { startButtonText: '任务进行中', logText: '处理中' },