Merge remote-tracking branch 'origin/dev' into codex-review-pr-226
This commit is contained in:
@@ -54,9 +54,21 @@ function extractFunction(name) {
|
||||
function getStep5Bundle() {
|
||||
return [
|
||||
extractFunction('getStep5DirectCompletionPayload'),
|
||||
extractFunction('isSignupProfilePageUrl'),
|
||||
extractFunction('isStep5AllConsentText'),
|
||||
extractFunction('findStep5AllConsentCheckbox'),
|
||||
extractFunction('isStep5CheckboxChecked'),
|
||||
extractFunction('getStep5ProfilePathPatterns'),
|
||||
extractFunction('getStep5AuthRetryPathPatterns'),
|
||||
extractFunction('isStep5ProfilePageUrl'),
|
||||
extractFunction('getStep5AuthRetryPageState'),
|
||||
extractFunction('getStep5SubmitButton'),
|
||||
extractFunction('waitForStep5SubmitButton'),
|
||||
extractFunction('isStep5SubmitButtonClickable'),
|
||||
extractFunction('isStep5ProfileStillVisible'),
|
||||
extractFunction('getStep5PostSubmitSuccessState'),
|
||||
extractFunction('installStep5NavigationCompletionReporter'),
|
||||
extractFunction('waitForStep5SubmitOutcome'),
|
||||
extractFunction('step5_fillNameBirthday'),
|
||||
].join('\n');
|
||||
}
|
||||
@@ -73,6 +85,9 @@ const completeButton = {
|
||||
tagName: 'BUTTON',
|
||||
textContent: '\\u5b8c\\u6210\\u8d26\\u6237\\u521b\\u5efa',
|
||||
hidden: false,
|
||||
getAttribute() {
|
||||
return '';
|
||||
},
|
||||
};
|
||||
const allConsentLabel = {
|
||||
hidden: false,
|
||||
@@ -110,6 +125,7 @@ const document = {
|
||||
return null;
|
||||
case 'input[name="age"]':
|
||||
return ageInput;
|
||||
case 'button[type="submit"], input[type="submit"]':
|
||||
case 'button[type="submit"]':
|
||||
return completeButton;
|
||||
default:
|
||||
@@ -136,6 +152,8 @@ function log(message, level = 'info') {
|
||||
logs.push({ message, level });
|
||||
}
|
||||
|
||||
function throwIfStopped() {}
|
||||
|
||||
async function waitForElement() {
|
||||
return nameInput;
|
||||
}
|
||||
@@ -155,6 +173,14 @@ function isVisibleElement(el) {
|
||||
return Boolean(el) && !el.hidden;
|
||||
}
|
||||
|
||||
function isActionEnabled(el) {
|
||||
return Boolean(el) && !el.disabled && el.getAttribute?.('aria-disabled') !== 'true';
|
||||
}
|
||||
|
||||
function getActionText(el) {
|
||||
return el.textContent || '';
|
||||
}
|
||||
|
||||
async function setReactAriaBirthdaySelect() {
|
||||
throw new Error('setReactAriaBirthdaySelect should not run in age-mode test');
|
||||
}
|
||||
@@ -168,6 +194,9 @@ function simulateClick(el) {
|
||||
if (el === allConsentLabel || el === allConsentCheckbox) {
|
||||
allConsentCheckbox.checked = true;
|
||||
}
|
||||
if (el === completeButton) {
|
||||
location.href = 'https://chatgpt.com/';
|
||||
}
|
||||
}
|
||||
|
||||
function reportComplete(step, payload) {
|
||||
@@ -178,6 +207,17 @@ function normalizeInlineText(text) {
|
||||
return String(text || '').replace(/\\s+/g, ' ').trim();
|
||||
}
|
||||
|
||||
function getSignupAuthRetryPathPatterns() { return []; }
|
||||
function getAuthTimeoutErrorPageState() { return null; }
|
||||
async function recoverCurrentAuthRetryPage() { throw new Error('should not recover retry page'); }
|
||||
function createSignupUserAlreadyExistsError() { return new Error('user already exists'); }
|
||||
function createAuthMaxCheckAttemptsError() { return new Error('max_check_attempts'); }
|
||||
function getStep5ErrorText() { return ''; }
|
||||
function isStep5Ready() { return /^https:\\/\\/auth\\.openai\\.com\\//.test(location.href); }
|
||||
function isLikelyLoggedInChatgptHomeUrl() { return /^https:\\/\\/chatgpt\\.com\\//.test(location.href); }
|
||||
function isOAuthConsentPage() { return false; }
|
||||
function isAddPhonePageReady() { return false; }
|
||||
|
||||
${getStep5Bundle()}
|
||||
|
||||
return {
|
||||
@@ -205,9 +245,11 @@ return {
|
||||
|
||||
const snapshot = api.snapshot();
|
||||
assert.deepStrictEqual(result, {
|
||||
skippedPostSubmitCheck: true,
|
||||
directProceedToStep6: true,
|
||||
profileSubmitted: true,
|
||||
postSubmitChecked: true,
|
||||
ageMode: true,
|
||||
outcome: 'logged_in_home',
|
||||
url: 'https://chatgpt.com/',
|
||||
});
|
||||
assert.equal(snapshot.nameValue, 'Mia Harris');
|
||||
assert.equal(snapshot.ageValue, '19');
|
||||
@@ -220,9 +262,11 @@ return {
|
||||
{
|
||||
step: 5,
|
||||
payload: {
|
||||
skippedPostSubmitCheck: true,
|
||||
directProceedToStep6: true,
|
||||
profileSubmitted: true,
|
||||
postSubmitChecked: true,
|
||||
ageMode: true,
|
||||
outcome: 'logged_in_home',
|
||||
url: 'https://chatgpt.com/',
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
@@ -51,21 +51,43 @@ function extractFunction(name) {
|
||||
return source.slice(start, end);
|
||||
}
|
||||
|
||||
function getStep5OutcomeBundle() {
|
||||
return [
|
||||
extractFunction('getStep5ProfilePathPatterns'),
|
||||
extractFunction('getStep5AuthRetryPathPatterns'),
|
||||
extractFunction('isStep5ProfilePageUrl'),
|
||||
extractFunction('getStep5AuthRetryPageState'),
|
||||
extractFunction('getStep5SubmitButton'),
|
||||
extractFunction('waitForStep5SubmitButton'),
|
||||
extractFunction('isStep5SubmitButtonClickable'),
|
||||
extractFunction('isStep5ProfileStillVisible'),
|
||||
extractFunction('getStep5PostSubmitSuccessState'),
|
||||
extractFunction('installStep5NavigationCompletionReporter'),
|
||||
extractFunction('waitForStep5SubmitOutcome'),
|
||||
].join('\n');
|
||||
}
|
||||
|
||||
function getStep5Bundle() {
|
||||
return [
|
||||
extractFunction('getStep5DirectCompletionPayload'),
|
||||
extractFunction('isSignupProfilePageUrl'),
|
||||
extractFunction('isStep5AllConsentText'),
|
||||
extractFunction('findStep5AllConsentCheckbox'),
|
||||
extractFunction('isStep5CheckboxChecked'),
|
||||
getStep5OutcomeBundle(),
|
||||
extractFunction('step5_fillNameBirthday'),
|
||||
].join('\n');
|
||||
}
|
||||
|
||||
test('step 5 clicks submit and completes immediately on birthday page', async () => {
|
||||
test('step 5 waits for post-submit outcome before completing on birthday page', async () => {
|
||||
const step5Source = extractFunction('step5_fillNameBirthday');
|
||||
assert.ok(
|
||||
!step5Source.includes('waitForStep5SubmitOutcome('),
|
||||
'Step 5 提交后不应再等待页面结果'
|
||||
step5Source.includes('waitForStep5SubmitOutcome('),
|
||||
'Step 5 提交后必须等待页面结果'
|
||||
);
|
||||
assert.ok(
|
||||
!step5Source.includes('不再等待页面结果'),
|
||||
'Step 5 不应再保留直接完成的旧日志'
|
||||
);
|
||||
|
||||
const api = new Function(`
|
||||
@@ -84,6 +106,7 @@ const completeButton = {
|
||||
tagName: 'BUTTON',
|
||||
textContent: '完成帐户创建',
|
||||
hidden: false,
|
||||
getAttribute() { return ''; },
|
||||
};
|
||||
|
||||
const birthdaySelects = {
|
||||
@@ -92,6 +115,10 @@ const birthdaySelects = {
|
||||
'天': { label: '天', button: { hidden: false }, nativeSelect: {} },
|
||||
};
|
||||
|
||||
const location = {
|
||||
href: 'https://auth.openai.com/u/signup/profile',
|
||||
};
|
||||
|
||||
const document = {
|
||||
querySelector(selector) {
|
||||
switch (selector) {
|
||||
@@ -102,6 +129,7 @@ const document = {
|
||||
return null;
|
||||
case 'input[name="birthday"]':
|
||||
return hiddenBirthday;
|
||||
case 'button[type="submit"], input[type="submit"]':
|
||||
case 'button[type="submit"]':
|
||||
return completeButton;
|
||||
default:
|
||||
@@ -112,15 +140,14 @@ const document = {
|
||||
if (selector === 'input[name="allCheckboxes"][type="checkbox"]') {
|
||||
return [];
|
||||
}
|
||||
if (selector === 'button, [role="button"], input[type="button"], input[type="submit"]') {
|
||||
return [completeButton];
|
||||
}
|
||||
return [];
|
||||
},
|
||||
execCommand() {},
|
||||
};
|
||||
|
||||
const location = {
|
||||
href: 'https://auth.openai.com/u/signup/profile',
|
||||
};
|
||||
|
||||
function Event(type, init = {}) {
|
||||
this.type = type;
|
||||
this.bubbles = Boolean(init.bubbles);
|
||||
@@ -130,10 +157,8 @@ function log(message, level = 'info') {
|
||||
logs.push({ message, level });
|
||||
}
|
||||
|
||||
async function waitForElement() {
|
||||
return nameInput;
|
||||
}
|
||||
|
||||
function throwIfStopped() {}
|
||||
async function waitForElement() { return nameInput; }
|
||||
async function humanPause() {}
|
||||
async function sleep() {}
|
||||
|
||||
@@ -149,6 +174,14 @@ function isVisibleElement(el) {
|
||||
return Boolean(el) && !el.hidden;
|
||||
}
|
||||
|
||||
function isActionEnabled(el) {
|
||||
return Boolean(el) && !el.disabled && el.getAttribute?.('aria-disabled') !== 'true';
|
||||
}
|
||||
|
||||
function getActionText(el) {
|
||||
return el.textContent || '';
|
||||
}
|
||||
|
||||
async function setReactAriaBirthdaySelect(select, value) {
|
||||
selectedBirthday[select.label] = String(value).padStart(select.label === '年' ? 4 : 2, '0');
|
||||
if (selectedBirthday['年'] && selectedBirthday['月'] && selectedBirthday['天']) {
|
||||
@@ -162,17 +195,30 @@ async function waitForElementByText() {
|
||||
|
||||
function simulateClick(el) {
|
||||
clicks.push(el.textContent || el.tagName || 'element');
|
||||
if (el === completeButton) {
|
||||
location.href = 'https://chatgpt.com/';
|
||||
}
|
||||
}
|
||||
|
||||
function reportComplete(step, payload) {
|
||||
completions.push({ step, payload });
|
||||
}
|
||||
|
||||
function normalizeInlineText(text) {
|
||||
return String(text || '').replace(/\\s+/g, ' ').trim();
|
||||
}
|
||||
function normalizeInlineText(text) {
|
||||
return String(text || '').replace(/\\s+/g, ' ').trim();
|
||||
}
|
||||
function getSignupAuthRetryPathPatterns() { return []; }
|
||||
function getAuthTimeoutErrorPageState() { return null; }
|
||||
async function recoverCurrentAuthRetryPage() { throw new Error('should not recover retry page'); }
|
||||
function createSignupUserAlreadyExistsError() { return new Error('user already exists'); }
|
||||
function createAuthMaxCheckAttemptsError() { return new Error('max_check_attempts'); }
|
||||
function getStep5ErrorText() { return ''; }
|
||||
function isStep5Ready() { return /^https:\\/\\/auth\\.openai\\.com\\//.test(location.href); }
|
||||
function isLikelyLoggedInChatgptHomeUrl() { return /^https:\\/\\/chatgpt\\.com\\//.test(location.href); }
|
||||
function isOAuthConsentPage() { return false; }
|
||||
function isAddPhonePageReady() { return false; }
|
||||
|
||||
${getStep5Bundle()}
|
||||
${getStep5Bundle()}
|
||||
|
||||
return {
|
||||
async run(payload) {
|
||||
@@ -199,20 +245,20 @@ return {
|
||||
});
|
||||
|
||||
const snapshot = api.snapshot();
|
||||
assert.deepStrictEqual(
|
||||
result,
|
||||
{
|
||||
skippedPostSubmitCheck: true,
|
||||
directProceedToStep6: true,
|
||||
},
|
||||
'生日模式点击提交后应直接返回完成载荷'
|
||||
);
|
||||
assert.deepStrictEqual(result, {
|
||||
profileSubmitted: true,
|
||||
postSubmitChecked: true,
|
||||
outcome: 'logged_in_home',
|
||||
url: 'https://chatgpt.com/',
|
||||
});
|
||||
assert.deepStrictEqual(snapshot.completions, [
|
||||
{
|
||||
step: 5,
|
||||
payload: {
|
||||
skippedPostSubmitCheck: true,
|
||||
directProceedToStep6: true,
|
||||
profileSubmitted: true,
|
||||
postSubmitChecked: true,
|
||||
outcome: 'logged_in_home',
|
||||
url: 'https://chatgpt.com/',
|
||||
},
|
||||
},
|
||||
]);
|
||||
@@ -220,7 +266,185 @@ return {
|
||||
assert.equal(snapshot.nameValue, 'Test User');
|
||||
assert.equal(snapshot.birthdayValue, '2003-06-19');
|
||||
assert.ok(
|
||||
snapshot.logs.some(({ message }) => /不再等待页面结果/.test(message)),
|
||||
'日志应明确说明 Step 5 已直接完成'
|
||||
snapshot.logs.some(({ message }) => /资料提交结果已确认/.test(message)),
|
||||
'日志应明确说明 Step 5 已完成提交后检测'
|
||||
);
|
||||
});
|
||||
|
||||
test('step 5 retries submit while profile page remains visible', async () => {
|
||||
const api = new Function(`
|
||||
const realDateNow = Date.now;
|
||||
let now = 0;
|
||||
const logs = [];
|
||||
const completions = [];
|
||||
const clicks = [];
|
||||
const nameInput = { value: '', hidden: false };
|
||||
const ageInput = { value: '', hidden: false };
|
||||
const completeButton = {
|
||||
tagName: 'BUTTON',
|
||||
textContent: '完成帐户创建',
|
||||
hidden: false,
|
||||
getAttribute() { return ''; },
|
||||
};
|
||||
const location = {
|
||||
href: 'https://auth.openai.com/u/signup/profile',
|
||||
};
|
||||
const document = {
|
||||
querySelector(selector) {
|
||||
switch (selector) {
|
||||
case '[role="spinbutton"][data-type="year"]':
|
||||
case '[role="spinbutton"][data-type="month"]':
|
||||
case '[role="spinbutton"][data-type="day"]':
|
||||
case 'input[name="birthday"]':
|
||||
return null;
|
||||
case 'input[name="age"]':
|
||||
return /^https:\\/\\/auth\\.openai\\.com\\//.test(location.href) ? ageInput : null;
|
||||
case 'button[type="submit"], input[type="submit"]':
|
||||
case 'button[type="submit"]':
|
||||
return completeButton;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
},
|
||||
querySelectorAll(selector) {
|
||||
if (selector === 'input[name="allCheckboxes"][type="checkbox"]') return [];
|
||||
if (selector === 'input[type="checkbox"]') return [];
|
||||
if (selector === 'button, [role="button"], input[type="button"], input[type="submit"]') return [completeButton];
|
||||
return [];
|
||||
},
|
||||
execCommand() {},
|
||||
};
|
||||
|
||||
Date.now = () => now;
|
||||
function log(message, level = 'info') { logs.push({ message, level }); }
|
||||
function throwIfStopped() {}
|
||||
async function waitForElement() { return nameInput; }
|
||||
async function humanPause() {}
|
||||
async function sleep(ms = 0) { now += ms || 250; }
|
||||
function fillInput(input, value) { input.value = value; }
|
||||
function findBirthdayReactAriaSelect() { return null; }
|
||||
function isVisibleElement(el) { return Boolean(el) && !el.hidden; }
|
||||
function isActionEnabled(el) { return Boolean(el) && !el.disabled && el.getAttribute?.('aria-disabled') !== 'true'; }
|
||||
function getActionText(el) { return el.textContent || ''; }
|
||||
async function setReactAriaBirthdaySelect() { throw new Error('setReactAriaBirthdaySelect should not run'); }
|
||||
async function waitForElementByText() { return completeButton; }
|
||||
function simulateClick(el) {
|
||||
clicks.push(el.textContent || el.tagName || 'element');
|
||||
if (el === completeButton && clicks.filter((text) => text === '完成帐户创建').length >= 3) {
|
||||
location.href = 'https://chatgpt.com/';
|
||||
}
|
||||
}
|
||||
function reportComplete(step, payload) { completions.push({ step, payload }); }
|
||||
function normalizeInlineText(text) { return String(text || '').replace(/\\s+/g, ' ').trim(); }
|
||||
function getSignupAuthRetryPathPatterns() { return []; }
|
||||
function getAuthTimeoutErrorPageState() { return null; }
|
||||
async function recoverCurrentAuthRetryPage() { throw new Error('should not recover retry page'); }
|
||||
function createSignupUserAlreadyExistsError() { return new Error('user already exists'); }
|
||||
function createAuthMaxCheckAttemptsError() { return new Error('max_check_attempts'); }
|
||||
function getStep5ErrorText() { return ''; }
|
||||
function isStep5Ready() { return /^https:\\/\\/auth\\.openai\\.com\\//.test(location.href); }
|
||||
function isLikelyLoggedInChatgptHomeUrl() { return /^https:\\/\\/chatgpt\\.com\\//.test(location.href); }
|
||||
function isOAuthConsentPage() { return false; }
|
||||
function isAddPhonePageReady() { return false; }
|
||||
|
||||
${getStep5Bundle()}
|
||||
|
||||
return {
|
||||
run() {
|
||||
return step5_fillNameBirthday({
|
||||
firstName: 'Mia',
|
||||
lastName: 'Harris',
|
||||
age: 19,
|
||||
});
|
||||
},
|
||||
snapshot() {
|
||||
return { logs, completions, clicks, nameValue: nameInput.value, ageValue: ageInput.value };
|
||||
},
|
||||
restore() {
|
||||
Date.now = realDateNow;
|
||||
},
|
||||
};
|
||||
`)();
|
||||
|
||||
let result;
|
||||
try {
|
||||
result = await api.run();
|
||||
} finally {
|
||||
api.restore();
|
||||
}
|
||||
const snapshot = api.snapshot();
|
||||
|
||||
assert.deepStrictEqual(result, {
|
||||
profileSubmitted: true,
|
||||
postSubmitChecked: true,
|
||||
ageMode: true,
|
||||
outcome: 'logged_in_home',
|
||||
url: 'https://chatgpt.com/',
|
||||
});
|
||||
assert.equal(snapshot.nameValue, 'Mia Harris');
|
||||
assert.equal(snapshot.ageValue, '19');
|
||||
assert.equal(snapshot.clicks.filter((text) => text === '完成帐户创建').length, 3);
|
||||
assert.equal(snapshot.logs.some(({ message }) => /仍停留在资料页,正在重新点击/.test(message)), true);
|
||||
});
|
||||
|
||||
test('step 5 recovers auth retry page after profile submit', async () => {
|
||||
const api = new Function(`
|
||||
let retryVisible = true;
|
||||
let recoverCalls = 0;
|
||||
const location = { href: 'https://auth.openai.com/create-account/profile' };
|
||||
const document = {
|
||||
querySelector() { return null; },
|
||||
querySelectorAll() { return []; },
|
||||
};
|
||||
|
||||
function throwIfStopped() {}
|
||||
function log() {}
|
||||
async function sleep() {}
|
||||
async function humanPause() {}
|
||||
function simulateClick() {}
|
||||
function isVisibleElement() { return true; }
|
||||
function isActionEnabled() { return true; }
|
||||
function getActionText(el) { return el?.textContent || ''; }
|
||||
function getSignupAuthRetryPathPatterns() { return []; }
|
||||
function getAuthTimeoutErrorPageState() {
|
||||
if (!retryVisible) return null;
|
||||
return {
|
||||
retryEnabled: true,
|
||||
userAlreadyExistsBlocked: false,
|
||||
maxCheckAttemptsBlocked: false,
|
||||
};
|
||||
}
|
||||
async function recoverCurrentAuthRetryPage() {
|
||||
recoverCalls += 1;
|
||||
retryVisible = false;
|
||||
location.href = 'https://chatgpt.com/';
|
||||
}
|
||||
function createSignupUserAlreadyExistsError() { return new Error('user already exists'); }
|
||||
function createAuthMaxCheckAttemptsError() { return new Error('max_check_attempts'); }
|
||||
function getStep5ErrorText() { return ''; }
|
||||
function isStep5Ready() { return /^https:\\/\\/auth\\.openai\\.com\\//.test(location.href); }
|
||||
function isLikelyLoggedInChatgptHomeUrl() { return /^https:\\/\\/chatgpt\\.com\\//.test(location.href); }
|
||||
function isOAuthConsentPage() { return false; }
|
||||
function isAddPhonePageReady() { return false; }
|
||||
|
||||
${extractFunction('isSignupProfilePageUrl')}
|
||||
${getStep5OutcomeBundle()}
|
||||
|
||||
return {
|
||||
run() {
|
||||
return waitForStep5SubmitOutcome({ timeoutMs: 1000 });
|
||||
},
|
||||
snapshot() {
|
||||
return { recoverCalls };
|
||||
},
|
||||
};
|
||||
`)();
|
||||
|
||||
const result = await api.run();
|
||||
|
||||
assert.deepStrictEqual(result, {
|
||||
state: 'logged_in_home',
|
||||
url: 'https://chatgpt.com/',
|
||||
});
|
||||
assert.equal(api.snapshot().recoverCalls, 1);
|
||||
});
|
||||
|
||||
@@ -182,3 +182,175 @@ return {
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
test('step9 defers callback timeout while auth security verification is still redirecting', async () => {
|
||||
const api = new Function('step9ModuleSource', `
|
||||
const self = {};
|
||||
let webNavListener = null;
|
||||
let webNavCommittedListener = null;
|
||||
let step8TabUpdatedListener = null;
|
||||
let cleanupCalls = 0;
|
||||
let deferCalls = 0;
|
||||
let completePayload = null;
|
||||
const callbackUrl = 'http://localhost:1455/auth/callback?code=abc&state=xyz';
|
||||
|
||||
const chrome = {
|
||||
webNavigation: {
|
||||
onBeforeNavigate: {
|
||||
addListener(listener) {
|
||||
webNavListener = listener;
|
||||
setTimeout(() => {
|
||||
if (typeof webNavListener === 'function') {
|
||||
webNavListener({ tabId: 123, url: callbackUrl });
|
||||
}
|
||||
}, 25);
|
||||
},
|
||||
removeListener() {},
|
||||
},
|
||||
onCommitted: {
|
||||
addListener(listener) {
|
||||
webNavCommittedListener = listener;
|
||||
},
|
||||
removeListener() {},
|
||||
},
|
||||
},
|
||||
tabs: {
|
||||
onUpdated: {
|
||||
addListener(listener) {
|
||||
step8TabUpdatedListener = listener;
|
||||
},
|
||||
removeListener() {},
|
||||
},
|
||||
async update() {},
|
||||
},
|
||||
};
|
||||
|
||||
async function addLog() {}
|
||||
function cleanupStep8NavigationListeners() {
|
||||
cleanupCalls += 1;
|
||||
webNavListener = null;
|
||||
webNavCommittedListener = null;
|
||||
step8TabUpdatedListener = null;
|
||||
}
|
||||
function throwIfStep8SettledOrStopped(resolved) {
|
||||
if (resolved) throw new Error('already resolved');
|
||||
}
|
||||
async function getTabId() { return 123; }
|
||||
async function isTabAlive() { return true; }
|
||||
async function ensureStep8SignupPageReady() {}
|
||||
async function getOAuthFlowStepTimeoutMs(defaultTimeoutMs, options = {}) {
|
||||
if (options.actionLabel === 'OAuth localhost 回调') {
|
||||
return 1;
|
||||
}
|
||||
return defaultTimeoutMs;
|
||||
}
|
||||
async function shouldDeferStep9CallbackTimeout(details = {}) {
|
||||
deferCalls += 1;
|
||||
return Number(details.tabId) === 123;
|
||||
}
|
||||
async function waitForStep8Ready() {
|
||||
return {
|
||||
consentReady: true,
|
||||
url: 'https://auth.openai.com/sign-in-with-chatgpt/codex/consent',
|
||||
};
|
||||
}
|
||||
async function triggerStep8ContentStrategy() {}
|
||||
async function waitForStep8ClickEffect() {
|
||||
return {
|
||||
progressed: true,
|
||||
reason: 'url_changed',
|
||||
url: 'https://auth.openai.com/api/oauth/oauth2/auth?client_id=app_test',
|
||||
};
|
||||
}
|
||||
function getStep8CallbackUrlFromNavigation(details, signupTabId) {
|
||||
return Number(details?.tabId) === Number(signupTabId) ? details.url : '';
|
||||
}
|
||||
function getStep8CallbackUrlFromTabUpdate() { return ''; }
|
||||
function getStep8EffectLabel() { return 'URL 已变化'; }
|
||||
async function prepareStep8DebuggerClick() { return { rect: { centerX: 10, centerY: 10 } }; }
|
||||
async function clickWithDebugger() {}
|
||||
async function reloadStep8ConsentPage() {}
|
||||
async function reuseOrCreateTab() { return 123; }
|
||||
async function sleepWithStop() {}
|
||||
function setWebNavListener(listener) { webNavListener = listener; }
|
||||
function getWebNavListener() { return webNavListener; }
|
||||
function setWebNavCommittedListener(listener) { webNavCommittedListener = listener; }
|
||||
function getWebNavCommittedListener() { return webNavCommittedListener; }
|
||||
function setStep8TabUpdatedListener(listener) { step8TabUpdatedListener = listener; }
|
||||
function getStep8TabUpdatedListener() { return step8TabUpdatedListener; }
|
||||
function setStep8PendingReject() {}
|
||||
async function completeStepFromBackground(step, payload) {
|
||||
completePayload = { step, payload };
|
||||
}
|
||||
|
||||
const STEP8_CLICK_RETRY_DELAY_MS = 1;
|
||||
const STEP8_READY_WAIT_TIMEOUT_MS = 5;
|
||||
const STEP8_MAX_ROUNDS = 1;
|
||||
const STEP8_STRATEGIES = [
|
||||
{ mode: 'content', strategy: 'requestSubmit', label: 'form.requestSubmit' },
|
||||
];
|
||||
|
||||
${step9ModuleSource}
|
||||
|
||||
const executor = self.MultiPageBackgroundStep9.createStep9Executor({
|
||||
addLog,
|
||||
chrome,
|
||||
cleanupStep8NavigationListeners,
|
||||
clickWithDebugger,
|
||||
completeStepFromBackground,
|
||||
ensureStep8SignupPageReady,
|
||||
getOAuthFlowStepTimeoutMs,
|
||||
getStep8CallbackUrlFromNavigation,
|
||||
getStep8CallbackUrlFromTabUpdate,
|
||||
getStep8EffectLabel,
|
||||
getTabId,
|
||||
getWebNavCommittedListener,
|
||||
getWebNavListener,
|
||||
getStep8TabUpdatedListener,
|
||||
isTabAlive,
|
||||
prepareStep8DebuggerClick,
|
||||
reloadStep8ConsentPage,
|
||||
reuseOrCreateTab,
|
||||
setStep8PendingReject,
|
||||
setStep8TabUpdatedListener,
|
||||
setWebNavCommittedListener,
|
||||
setWebNavListener,
|
||||
shouldDeferStep9CallbackTimeout,
|
||||
sleepWithStop,
|
||||
STEP8_CLICK_RETRY_DELAY_MS,
|
||||
STEP8_MAX_ROUNDS,
|
||||
STEP8_READY_WAIT_TIMEOUT_MS,
|
||||
STEP8_STRATEGIES,
|
||||
throwIfStep8SettledOrStopped,
|
||||
triggerStep8ContentStrategy,
|
||||
waitForStep8ClickEffect,
|
||||
waitForStep8Ready,
|
||||
});
|
||||
|
||||
return {
|
||||
executeStep9: executor.executeStep9,
|
||||
snapshot() {
|
||||
return {
|
||||
cleanupCalls,
|
||||
deferCalls,
|
||||
completePayload,
|
||||
};
|
||||
},
|
||||
};
|
||||
`)(step9ModuleSource);
|
||||
|
||||
await api.executeStep9({
|
||||
oauthUrl: 'https://auth.openai.com/original-oauth',
|
||||
visibleStep: 12,
|
||||
});
|
||||
|
||||
const snapshot = api.snapshot();
|
||||
assert.equal(snapshot.deferCalls >= 1, true);
|
||||
assert.equal(snapshot.cleanupCalls >= 1, true);
|
||||
assert.deepEqual(snapshot.completePayload, {
|
||||
step: 12,
|
||||
payload: {
|
||||
localhostUrl: 'http://localhost:1455/auth/callback?code=abc&state=xyz',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
@@ -448,7 +448,12 @@ test('verification flow keeps step 8 successful when code submit transport fails
|
||||
pollCloudflareTempEmailVerificationCode: async () => ({}),
|
||||
pollHotmailVerificationCode: async () => ({}),
|
||||
pollLuckmailVerificationCode: async () => ({}),
|
||||
sendToContentScript: async () => ({}),
|
||||
sendToContentScript: async (_source, message) => {
|
||||
if (message.type === 'FILL_CODE') {
|
||||
throw new Error('message channel is closed before a response was received');
|
||||
}
|
||||
return {};
|
||||
},
|
||||
sendToContentScriptResilient: async (_source, message) => {
|
||||
if (message.type === 'FILL_CODE') {
|
||||
throw new Error('message channel is closed before a response was received');
|
||||
@@ -1282,6 +1287,151 @@ test('verification flow uses resilient signup-page transport when submitting ver
|
||||
assert.ok(resilientCalls[0].options.timeoutMs >= 30000);
|
||||
});
|
||||
|
||||
test('verification flow does not replay step 8 code submit after transient auth-page transport failure', async () => {
|
||||
const directMessages = [];
|
||||
const resilientMessages = [];
|
||||
|
||||
const helpers = api.createVerificationFlowHelpers({
|
||||
addLog: async () => {},
|
||||
chrome: {
|
||||
tabs: {
|
||||
update: async () => {},
|
||||
},
|
||||
},
|
||||
CLOUDFLARE_TEMP_EMAIL_PROVIDER: 'cloudflare-temp-email',
|
||||
completeStepFromBackground: async () => {},
|
||||
confirmCustomVerificationStepBypassRequest: async () => ({ confirmed: true }),
|
||||
getHotmailVerificationPollConfig: () => ({}),
|
||||
getHotmailVerificationRequestTimestamp: () => 0,
|
||||
getState: async () => ({}),
|
||||
getTabId: async () => 1,
|
||||
HOTMAIL_PROVIDER: 'hotmail-api',
|
||||
isRetryableContentScriptTransportError: (error) => /did not respond/i.test(String(error?.message || error || '')),
|
||||
isStopError: () => false,
|
||||
LUCKMAIL_PROVIDER: 'luckmail-api',
|
||||
MAIL_2925_VERIFICATION_INTERVAL_MS: 15000,
|
||||
MAIL_2925_VERIFICATION_MAX_ATTEMPTS: 15,
|
||||
pollCloudflareTempEmailVerificationCode: async () => ({}),
|
||||
pollHotmailVerificationCode: async () => ({}),
|
||||
pollLuckmailVerificationCode: async () => ({}),
|
||||
sendToContentScript: async (_source, message) => {
|
||||
directMessages.push(message.type);
|
||||
if (message.type === 'FILL_CODE') {
|
||||
throw new Error('步骤 8:页面通信异常 did not respond in 30s');
|
||||
}
|
||||
return {};
|
||||
},
|
||||
sendToContentScriptResilient: async (_source, message) => {
|
||||
resilientMessages.push(message.type);
|
||||
if (message.type === 'GET_LOGIN_AUTH_STATE') {
|
||||
return {
|
||||
state: 'verification_page',
|
||||
verificationErrorText: '代码不正确',
|
||||
url: 'https://auth.openai.com/email-verification',
|
||||
};
|
||||
}
|
||||
throw new Error('FILL_CODE should not be replayed through resilient transport');
|
||||
},
|
||||
sendToMailContentScriptResilient: async () => ({}),
|
||||
setState: async () => {},
|
||||
setStepStatus: async () => {},
|
||||
sleepWithStop: async () => {},
|
||||
throwIfStopped: () => {},
|
||||
VERIFICATION_POLL_MAX_ROUNDS: 5,
|
||||
});
|
||||
|
||||
const result = await helpers.submitVerificationCode(8, '510725', { completionStep: 11 });
|
||||
|
||||
assert.deepStrictEqual(result, {
|
||||
invalidCode: true,
|
||||
errorText: '代码不正确',
|
||||
url: 'https://auth.openai.com/email-verification',
|
||||
});
|
||||
assert.deepStrictEqual(directMessages, ['FILL_CODE']);
|
||||
assert.deepStrictEqual(resilientMessages, ['GET_LOGIN_AUTH_STATE']);
|
||||
});
|
||||
|
||||
test('verification flow requests a new code immediately after Cloudflare Temp Email code is rejected', async () => {
|
||||
const events = [];
|
||||
const pollPayloads = [];
|
||||
const completed = [];
|
||||
|
||||
const helpers = api.createVerificationFlowHelpers({
|
||||
addLog: async () => {},
|
||||
chrome: {
|
||||
tabs: {
|
||||
update: async () => {},
|
||||
},
|
||||
},
|
||||
CLOUDFLARE_TEMP_EMAIL_PROVIDER: 'cloudflare-temp-email',
|
||||
completeStepFromBackground: async (_step, payload) => {
|
||||
completed.push(payload);
|
||||
},
|
||||
confirmCustomVerificationStepBypassRequest: async () => ({ confirmed: true }),
|
||||
getHotmailVerificationPollConfig: () => ({}),
|
||||
getHotmailVerificationRequestTimestamp: () => 0,
|
||||
getState: async () => ({}),
|
||||
getTabId: async () => 1,
|
||||
HOTMAIL_PROVIDER: 'hotmail-api',
|
||||
isStopError: () => false,
|
||||
LUCKMAIL_PROVIDER: 'luckmail-api',
|
||||
MAIL_2925_VERIFICATION_INTERVAL_MS: 15000,
|
||||
MAIL_2925_VERIFICATION_MAX_ATTEMPTS: 15,
|
||||
pollCloudflareTempEmailVerificationCode: async (_step, _state, payload) => {
|
||||
pollPayloads.push(payload);
|
||||
const code = pollPayloads.length === 1 ? '111111' : '222222';
|
||||
events.push(['poll', code]);
|
||||
return { code, emailTimestamp: pollPayloads.length };
|
||||
},
|
||||
pollHotmailVerificationCode: async () => ({}),
|
||||
pollLuckmailVerificationCode: async () => ({}),
|
||||
sendToContentScript: async (_source, message) => {
|
||||
if (message.type === 'RESEND_VERIFICATION_CODE') {
|
||||
events.push(['resend', message.step]);
|
||||
return {};
|
||||
}
|
||||
if (message.type === 'FILL_CODE') {
|
||||
events.push(['submit', message.payload.code]);
|
||||
return message.payload.code === '111111'
|
||||
? { invalidCode: true, errorText: '代码不正确' }
|
||||
: { success: true };
|
||||
}
|
||||
return {};
|
||||
},
|
||||
sendToMailContentScriptResilient: async () => ({}),
|
||||
setState: async () => {},
|
||||
setStepStatus: async () => {},
|
||||
sleepWithStop: async () => {},
|
||||
throwIfStopped: () => {},
|
||||
VERIFICATION_POLL_MAX_ROUNDS: 5,
|
||||
});
|
||||
|
||||
await helpers.resolveVerificationStep(
|
||||
8,
|
||||
{
|
||||
email: 'user@example.com',
|
||||
loginVerificationRequestedAt: Date.now(),
|
||||
verificationResendCount: 1,
|
||||
},
|
||||
{ provider: 'cloudflare-temp-email', label: 'Cloudflare Temp Email' },
|
||||
{
|
||||
completionStep: 11,
|
||||
lastResendAt: Date.now(),
|
||||
resendIntervalMs: 25000,
|
||||
}
|
||||
);
|
||||
|
||||
assert.deepStrictEqual(events, [
|
||||
['poll', '111111'],
|
||||
['submit', '111111'],
|
||||
['resend', 8],
|
||||
['poll', '222222'],
|
||||
['submit', '222222'],
|
||||
]);
|
||||
assert.deepStrictEqual(pollPayloads[1].excludeCodes, ['111111']);
|
||||
assert.equal(completed[0].code, '222222');
|
||||
});
|
||||
|
||||
test('verification flow forwards optional signup profile payload when submitting signup verification code', async () => {
|
||||
const resilientCalls = [];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user