fix: stop GPC flow on no-trial logs

This commit is contained in:
QLHazyCoder
2026-05-30 02:35:07 +08:00
parent 0afa951814
commit 8c2cb2f8e0
2 changed files with 38 additions and 0 deletions
@@ -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);
@@ -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: '处理中' },