From 466011d4e526d1ab2fe41d9a35185ddde15a6843 Mon Sep 17 00:00:00 2001 From: QLHazyCoder <2825305047@qq.com> Date: Sat, 18 Apr 2026 00:29:20 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E9=80=BB=E8=BE=91=EF=BC=8C=E7=A1=AE=E4=BF=9D?= =?UTF-8?q?=E5=AF=86=E7=A0=81=E9=87=8D=E8=AF=95=E9=A1=B5=E9=9D=A2=E4=B8=8D?= =?UTF-8?q?=E8=A2=AB=E8=A7=86=E4=B8=BA=E9=AA=8C=E8=AF=81=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E6=B7=BB=E5=8A=A0=E7=9B=B8=E5=85=B3=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- content/signup-page.js | 15 +- tests/signup-verification-state-guard.test.js | 142 ++++++++++++++++++ 2 files changed, 153 insertions(+), 4 deletions(-) create mode 100644 tests/signup-verification-state-guard.test.js diff --git a/content/signup-page.js b/content/signup-page.js index bfe73e9..a9c7146 100644 --- a/content/signup-page.js +++ b/content/signup-page.js @@ -752,10 +752,17 @@ function isOAuthConsentPage() { } function isVerificationPageStillVisible() { + if (getCurrentAuthRetryPageState('signup_password') || getCurrentAuthRetryPageState('login')) { + return false; + } if (getVerificationCodeTarget()) return true; if (findResendVerificationCodeTrigger({ allowDisabled: true })) return true; if (document.querySelector('form[action*="email-verification" i]')) return true; + if (!isEmailVerificationPage()) { + return false; + } + return VERIFICATION_PAGE_PATTERN.test(getPageTextSnapshot()); } @@ -1314,10 +1321,6 @@ function inspectSignupVerificationState() { return { state: 'step5' }; } - if (isVerificationPageStillVisible()) { - return { state: 'verification' }; - } - if (isSignupPasswordErrorPage()) { const timeoutPage = getSignupPasswordTimeoutErrorPageState(); return { @@ -1326,6 +1329,10 @@ function inspectSignupVerificationState() { }; } + if (isVerificationPageStillVisible()) { + return { state: 'verification' }; + } + if (isSignupEmailAlreadyExistsPage()) { return { state: 'email_exists' }; } diff --git a/tests/signup-verification-state-guard.test.js b/tests/signup-verification-state-guard.test.js new file mode 100644 index 0000000..3cb8b23 --- /dev/null +++ b/tests/signup-verification-state-guard.test.js @@ -0,0 +1,142 @@ +const test = require('node:test'); +const assert = require('node:assert/strict'); +const fs = require('node:fs'); + +const source = fs.readFileSync('content/signup-page.js', 'utf8'); + +function extractFunction(name) { + const markers = [`async function ${name}(`, `function ${name}(`]; + const start = markers + .map((marker) => source.indexOf(marker)) + .find((index) => index >= 0); + if (start < 0) { + throw new Error(`missing function ${name}`); + } + + let parenDepth = 0; + let signatureEnded = false; + let braceStart = -1; + for (let i = start; i < source.length; i += 1) { + const ch = source[i]; + if (ch === '(') { + parenDepth += 1; + } else if (ch === ')') { + parenDepth -= 1; + if (parenDepth === 0) { + signatureEnded = true; + } + } else if (ch === '{' && signatureEnded) { + braceStart = i; + break; + } + } + + if (braceStart < 0) { + throw new Error(`missing body for function ${name}`); + } + + let depth = 0; + let end = braceStart; + for (; end < source.length; end += 1) { + const ch = source[end]; + if (ch === '{') depth += 1; + if (ch === '}') { + depth -= 1; + if (depth === 0) { + end += 1; + break; + } + } + } + + return source.slice(start, end); +} + +test('verification visibility text fallback should not treat password retry page as verification page', () => { + const api = new Function(` +const VERIFICATION_PAGE_PATTERN = /check\\s+your\\s+inbox|we\\s+emailed|resend/i; +const document = { + querySelector() { + return null; + }, +}; + +function getCurrentAuthRetryPageState(flow) { + if (flow === 'signup_password') { + return { retryEnabled: true }; + } + return null; +} + +function getVerificationCodeTarget() { + return null; +} + +function findResendVerificationCodeTrigger() { + return null; +} + +function isEmailVerificationPage() { + return false; +} + +function getPageTextSnapshot() { + return 'Check your inbox and resend email if needed'; +} + +${extractFunction('isVerificationPageStillVisible')} + +return { + run() { + return isVerificationPageStillVisible(); + }, +}; +`)(); + + assert.equal(api.run(), false); +}); + +test('signup verification state should prioritize retry error page over verification visibility', () => { + const api = new Function(` +function isStep5Ready() { + return false; +} + +function isVerificationPageStillVisible() { + return true; +} + +function isSignupPasswordErrorPage() { + return true; +} + +function getSignupPasswordTimeoutErrorPageState() { + return { retryButton: { textContent: 'Try again' } }; +} + +function isSignupEmailAlreadyExistsPage() { + return false; +} + +function getSignupPasswordInput() { + return null; +} + +function getSignupPasswordSubmitButton() { + return null; +} + +${extractFunction('inspectSignupVerificationState')} + +return { + run() { + return inspectSignupVerificationState(); + }, +}; +`)(); + + assert.deepStrictEqual(api.run(), { + state: 'error', + retryButton: { textContent: 'Try again' }, + }); +});