fix: stop silent skipping of steps 3/4/5 on ChatGPT home, throw explicit error instead

This commit is contained in:
QLHazyCoder
2026-04-25 19:33:21 +08:00
parent 171b375a0b
commit 0125839d2b
2 changed files with 31 additions and 7 deletions
+19 -3
View File
@@ -85,6 +85,9 @@
const reasonText = getErrorMessage(reasonMessage); const reasonText = getErrorMessage(reasonMessage);
const reasonSuffix = reasonText ? `(触发原因:${reasonText}` : ''; const reasonSuffix = reasonText ? `(触发原因:${reasonText}` : '';
await addLog(`步骤 2:检测到当前会话已登录 ChatGPT,已跳过注册链路(步骤 3/4/5),将直接进入步骤 6。${reasonSuffix}`, 'warn'); await addLog(`步骤 2:检测到当前会话已登录 ChatGPT,已跳过注册链路(步骤 3/4/5),将直接进入步骤 6。${reasonSuffix}`, 'warn');
const message = `姝ラ 2锛氭娴嬪埌褰撳墠鐣欏湪宸茬櫥褰?ChatGPT 棣栭〉锛屽凡闃绘鑷姩璺宠繃姝ラ 3/4/5銆傝鍏堟墽琛屾楠?1 娓呯悊浼氳瘽鍚庨噸璇曘€?${reasonSuffix}`;
await addLog(message, 'error');
throw new Error(message);
await completeStepFromBackground(2, { await completeStepFromBackground(2, {
email: resolvedEmail, email: resolvedEmail,
nextSignupState: 'already_logged_in_home', nextSignupState: 'already_logged_in_home',
@@ -95,6 +98,19 @@
return true; return true;
} }
async function failStep2OnLoggedInSession(tabId, reasonMessage = '') {
const currentUrl = await getTabUrl(tabId);
if (!isLikelyLoggedInChatgptHomeUrl(currentUrl)) {
return false;
}
const reasonText = getErrorMessage(reasonMessage);
const reasonSuffix = reasonText ? `(触发原因:${reasonText}` : '';
const message = `步骤 2:检测到当前停留在已登录 ChatGPT 首页,已阻止自动跳过步骤 3/4/5。请先执行步骤 1 清理会话后重试。${reasonSuffix}`;
await addLog(message, 'error');
throw new Error(message);
}
async function submitSignupEmail(resolvedEmail, options = {}) { async function submitSignupEmail(resolvedEmail, options = {}) {
const { const {
timeoutMs = 35000, timeoutMs = 35000,
@@ -142,7 +158,7 @@
signupTabId = (await ensureSignupAuthEntryPageReady(2)).tabId; signupTabId = (await ensureSignupAuthEntryPageReady(2)).tabId;
} catch (entryError) { } catch (entryError) {
const entryErrorMessage = getErrorMessage(entryError); const entryErrorMessage = getErrorMessage(entryError);
if (await completeStep2AsLoggedInSession(signupTabId, resolvedEmail, entryErrorMessage)) { if (await failStep2OnLoggedInSession(signupTabId, entryErrorMessage)) {
return; return;
} }
await addLog('步骤 2:切换认证入口失败,正在重新打开官网入口并重试提交邮箱...', 'warn'); await addLog('步骤 2:切换认证入口失败,正在重新打开官网入口并重试提交邮箱...', 'warn');
@@ -170,7 +186,7 @@
if (step2Result?.error) { if (step2Result?.error) {
const retryErrorMessage = getErrorMessage(step2Result.error); const retryErrorMessage = getErrorMessage(step2Result.error);
if (isSignupEntryUnavailableErrorMessage(retryErrorMessage)) { if (isSignupEntryUnavailableErrorMessage(retryErrorMessage)) {
if (await completeStep2AsLoggedInSession(signupTabId, resolvedEmail, retryErrorMessage)) { if (await failStep2OnLoggedInSession(signupTabId, retryErrorMessage)) {
return; return;
} }
await addLog('步骤 2:认证入口仍不可用,正在重新进入官网注册入口再重试一次...', 'warn'); await addLog('步骤 2:认证入口仍不可用,正在重新进入官网注册入口再重试一次...', 'warn');
@@ -198,7 +214,7 @@
if ( if (
(isSignupEntryUnavailableErrorMessage(finalErrorMessage) (isSignupEntryUnavailableErrorMessage(finalErrorMessage)
|| isRetryableStep2TransportErrorMessage(finalErrorMessage)) || isRetryableStep2TransportErrorMessage(finalErrorMessage))
&& await completeStep2AsLoggedInSession(signupTabId, resolvedEmail, finalErrorMessage) && await failStep2OnLoggedInSession(signupTabId, finalErrorMessage)
) { ) {
return; return;
} }
@@ -84,7 +84,7 @@ test('step 2 keeps password flow when landing on password page', async () => {
]); ]);
}); });
test('step 2 falls back to already-logged-in branch when auth entry recovery fails on chatgpt home', async () => { test('step 2 stops with an explicit error instead of silently skipping 3/4/5 on chatgpt home', async () => {
const completedPayloads = []; const completedPayloads = [];
const logs = []; const logs = [];
@@ -117,10 +117,18 @@ test('step 2 falls back to already-logged-in branch when auth entry recovery fai
SIGNUP_PAGE_INJECT_FILES: [], SIGNUP_PAGE_INJECT_FILES: [],
}); });
await executor.executeStep2({ email: 'user@example.com' }); await assert.rejects(
() => executor.executeStep2({ email: 'user@example.com' }),
/3\/4\/5/
);
assert.equal(completedPayloads.length, 1); assert.deepStrictEqual(completedPayloads, []);
assert.deepStrictEqual(completedPayloads[0], { assert.ok(logs.some((item) => /3\/4\/5/.test(item.message)));
return;
if (false) await executor.executeStep2({ email: 'user@example.com' });
if (false) assert.equal(completedPayloads.length, 1);
if (false) assert.deepStrictEqual(completedPayloads[0], {
step: 2, step: 2,
payload: { payload: {
email: 'user@example.com', email: 'user@example.com',