feat(network): integrate outbound route module on Ultra1.4 baseline

This commit is contained in:
daniellee2015
2026-04-27 13:25:46 +08:00
parent c98cfd7053
commit 2706d98225
16 changed files with 7979 additions and 26 deletions
+230
View File
@@ -159,6 +159,236 @@ test('Plus login-code step reuses step 8 verification logic but completes visibl
assert.deepStrictEqual(remainingStepCalls, [11, 11]);
});
test('step 8 completes directly when auth page is already on OAuth consent page', async () => {
const events = {
resolveCalls: 0,
completeCalls: [],
setStates: [],
rerunStep7: 0,
};
const executor = api.createStep8Executor({
addLog: async () => {},
chrome: {
tabs: {
update: async () => {},
},
},
CLOUDFLARE_TEMP_EMAIL_PROVIDER: 'cloudflare-temp-email',
completeStepFromBackground: async (step, payload) => {
events.completeCalls.push({ step, payload });
},
confirmCustomVerificationStepBypass: async () => {},
ensureStep8VerificationPageReady: async () => ({
state: 'oauth_consent_page',
}),
rerunStep7ForStep8Recovery: async () => {
events.rerunStep7 += 1;
},
getOAuthFlowRemainingMs: async () => 9000,
getOAuthFlowStepTimeoutMs: async (defaultTimeoutMs) => Math.min(defaultTimeoutMs, 9000),
getMailConfig: () => ({
provider: 'qq',
label: 'QQ 邮箱',
source: 'mail-qq',
url: 'https://mail.qq.com',
navigateOnReuse: false,
}),
getState: async () => ({ email: 'user@example.com', password: 'secret' }),
getTabId: async (sourceName) => (sourceName === 'signup-page' ? 1 : 2),
HOTMAIL_PROVIDER: 'hotmail-api',
isTabAlive: async () => true,
isVerificationMailPollingError: () => false,
LUCKMAIL_PROVIDER: 'luckmail-api',
resolveVerificationStep: async () => {
events.resolveCalls += 1;
},
reuseOrCreateTab: async () => {},
setState: async (payload) => {
events.setStates.push(payload);
},
setStepStatus: async () => {},
shouldUseCustomRegistrationEmail: () => false,
STANDARD_MAIL_VERIFICATION_RESEND_INTERVAL_MS: 25000,
STEP7_MAIL_POLLING_RECOVERY_MAX_ATTEMPTS: 8,
throwIfStopped: () => {},
});
await executor.executeStep8({
email: 'user@example.com',
password: 'secret',
oauthUrl: 'https://oauth.example/latest',
});
assert.equal(events.resolveCalls, 0);
assert.equal(events.rerunStep7, 0);
assert.deepStrictEqual(events.setStates, [
{
step8VerificationTargetEmail: '',
loginVerificationRequestedAt: null,
},
]);
assert.deepStrictEqual(events.completeCalls, [
{
step: 8,
payload: {
loginVerificationRequestedAt: null,
skipLoginVerificationStep: true,
directOAuthConsentPage: true,
},
},
]);
});
test('step 8 retries in-place when polling fails but auth page still stays on verification page', async () => {
const events = {
ensureCalls: 0,
resolveCalls: 0,
rerunStep7: 0,
};
const pageStates = [
{ state: 'verification_page', displayedEmail: 'user@example.com' },
{ state: 'verification_page', displayedEmail: 'user@example.com' },
{ state: 'verification_page', displayedEmail: 'user@example.com' },
];
const executor = api.createStep8Executor({
addLog: async () => {},
chrome: {
tabs: {
update: async () => {},
},
},
CLOUDFLARE_TEMP_EMAIL_PROVIDER: 'cloudflare-temp-email',
completeStepFromBackground: async () => {},
confirmCustomVerificationStepBypass: async () => {},
ensureStep8VerificationPageReady: async () => {
events.ensureCalls += 1;
return pageStates[Math.min(events.ensureCalls - 1, pageStates.length - 1)];
},
rerunStep7ForStep8Recovery: async () => {
events.rerunStep7 += 1;
},
getOAuthFlowRemainingMs: async () => 9000,
getOAuthFlowStepTimeoutMs: async (defaultTimeoutMs) => Math.min(defaultTimeoutMs, 9000),
getMailConfig: () => ({
provider: 'qq',
label: 'QQ 邮箱',
source: 'mail-qq',
url: 'https://mail.qq.com',
navigateOnReuse: false,
}),
getState: async () => ({ email: 'user@example.com', password: 'secret' }),
getTabId: async (sourceName) => (sourceName === 'signup-page' ? 1 : 2),
HOTMAIL_PROVIDER: 'hotmail-api',
isTabAlive: async () => true,
isVerificationMailPollingError: (error) => /页面通信异常|did not respond/i.test(String(error?.message || error || '')),
LUCKMAIL_PROVIDER: 'luckmail-api',
resolveVerificationStep: async () => {
events.resolveCalls += 1;
if (events.resolveCalls === 1) {
throw new Error('步骤 8:页面通信异常 did not respond in 30s');
}
},
reuseOrCreateTab: async () => {},
setState: async () => {},
setStepStatus: async () => {},
shouldUseCustomRegistrationEmail: () => false,
STANDARD_MAIL_VERIFICATION_RESEND_INTERVAL_MS: 25000,
STEP7_MAIL_POLLING_RECOVERY_MAX_ATTEMPTS: 8,
throwIfStopped: () => {},
});
await executor.executeStep8({
email: 'user@example.com',
password: 'secret',
oauthUrl: 'https://oauth.example/latest',
});
assert.equal(events.resolveCalls, 2);
assert.equal(events.rerunStep7, 0);
assert.equal(events.ensureCalls >= 3, true);
});
test('step 8 completes when polling fails but recovery probe shows oauth consent page', async () => {
const events = {
ensureCalls: 0,
resolveCalls: 0,
rerunStep7: 0,
completeCalls: [],
};
const pageStates = [
{ state: 'verification_page', displayedEmail: 'user@example.com' },
{ state: 'oauth_consent_page' },
];
const executor = api.createStep8Executor({
addLog: async () => {},
chrome: {
tabs: {
update: async () => {},
},
},
CLOUDFLARE_TEMP_EMAIL_PROVIDER: 'cloudflare-temp-email',
completeStepFromBackground: async (step, payload) => {
events.completeCalls.push({ step, payload });
},
confirmCustomVerificationStepBypass: async () => {},
ensureStep8VerificationPageReady: async () => {
events.ensureCalls += 1;
return pageStates[Math.min(events.ensureCalls - 1, pageStates.length - 1)];
},
rerunStep7ForStep8Recovery: async () => {
events.rerunStep7 += 1;
},
getOAuthFlowRemainingMs: async () => 9000,
getOAuthFlowStepTimeoutMs: async (defaultTimeoutMs) => Math.min(defaultTimeoutMs, 9000),
getMailConfig: () => ({
provider: 'qq',
label: 'QQ 邮箱',
source: 'mail-qq',
url: 'https://mail.qq.com',
navigateOnReuse: false,
}),
getState: async () => ({ email: 'user@example.com', password: 'secret' }),
getTabId: async (sourceName) => (sourceName === 'signup-page' ? 1 : 2),
HOTMAIL_PROVIDER: 'hotmail-api',
isTabAlive: async () => true,
isVerificationMailPollingError: (error) => /页面通信异常|did not respond/i.test(String(error?.message || error || '')),
LUCKMAIL_PROVIDER: 'luckmail-api',
resolveVerificationStep: async () => {
events.resolveCalls += 1;
throw new Error('步骤 8:页面通信异常 did not respond in 30s');
},
reuseOrCreateTab: async () => {},
setState: async () => {},
setStepStatus: async () => {},
shouldUseCustomRegistrationEmail: () => false,
STANDARD_MAIL_VERIFICATION_RESEND_INTERVAL_MS: 25000,
STEP7_MAIL_POLLING_RECOVERY_MAX_ATTEMPTS: 8,
throwIfStopped: () => {},
});
await executor.executeStep8({
email: 'user@example.com',
password: 'secret',
oauthUrl: 'https://oauth.example/latest',
});
assert.equal(events.resolveCalls, 1);
assert.equal(events.rerunStep7, 0);
assert.deepStrictEqual(events.completeCalls, [
{
step: 8,
payload: {
loginVerificationRequestedAt: null,
skipLoginVerificationStep: true,
directOAuthConsentPage: true,
},
},
]);
});
test('step 8 uses a fixed 10-minute lookback window and disables resend interval for 2925 mailbox polling', async () => {
let capturedOptions = null;
let ensureCalls = 0;
+109
View File
@@ -132,6 +132,115 @@ return {
);
});
test('step 8 ready check keeps waiting when retryPage is reported on consent URL', async () => {
const api = new Function(`
let pollCount = 0;
function throwIfStopped() {}
async function sleepWithStop() {}
async function ensureStep8SignupPageReady() {}
async function getState() {
return { phoneVerificationEnabled: true };
}
const phoneVerificationHelpers = {
async completePhoneVerificationFlow() {
throw new Error('should not trigger phone verification flow');
},
};
async function getStep8PageState() {
pollCount += 1;
if (pollCount === 1) {
return {
url: 'https://auth.openai.com/sign-in-with-chatgpt/codex/consent',
retryPage: true,
consentPage: true,
consentReady: false,
addPhonePage: false,
phoneVerificationPage: false,
};
}
return {
url: 'https://auth.openai.com/sign-in-with-chatgpt/codex/consent',
retryPage: false,
consentPage: true,
consentReady: true,
addPhonePage: false,
phoneVerificationPage: false,
};
}
${extractFunction('waitForStep8Ready')}
return {
async run() {
return waitForStep8Ready(88, 1000);
},
};
`)();
const result = await api.run();
assert.equal(result?.consentReady, true);
assert.equal(result?.retryPage, false);
});
test('step 8 click effect ignores consent-like retry snapshots and waits for real page progress', async () => {
const api = new Function(`
let pollCount = 0;
const chrome = {
tabs: {
async get() {
return {
id: 88,
url: 'https://auth.openai.com/sign-in-with-chatgpt/codex/consent',
};
},
},
};
function throwIfStopped() {}
async function sleepWithStop() {}
async function ensureStep8SignupPageReady() {}
async function getStep8PageState() {
pollCount += 1;
if (pollCount === 1) {
return {
url: 'https://auth.openai.com/sign-in-with-chatgpt/codex/consent',
retryPage: true,
consentPage: true,
consentReady: false,
addPhonePage: false,
verificationPage: false,
};
}
return {
url: 'https://chatgpt.com/',
retryPage: false,
consentPage: false,
consentReady: false,
addPhonePage: false,
verificationPage: false,
};
}
${extractFunction('waitForStep8ClickEffect')}
return {
async run() {
return waitForStep8ClickEffect(
88,
'https://auth.openai.com/sign-in-with-chatgpt/codex/consent',
1000
);
},
};
`)();
const result = await api.run();
assert.equal(result?.progressed, true);
assert.equal(result?.reason, 'left_consent_page');
assert.match(String(result?.url || ''), /chatgpt\.com/);
});
test('step 8 ready check completes phone verification flow before waiting for OAuth consent', async () => {
const api = new Function(`
let pollCount = 0;
+73
View File
@@ -419,6 +419,79 @@ test('verification flow completes step 8 and flags phone verification when add-p
]);
});
test('verification flow keeps step 8 successful when code submit transport fails but auth page already reaches oauth consent', async () => {
const events = [];
const helpers = api.createVerificationFlowHelpers({
addLog: async (message) => {
events.push(['log', message]);
},
chrome: {
tabs: {
update: async () => {},
},
},
CLOUDFLARE_TEMP_EMAIL_PROVIDER: 'cloudflare-temp-email',
completeStepFromBackground: async (_step, payload) => {
events.push(['complete', payload.code]);
},
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 () => ({}),
pollHotmailVerificationCode: async () => ({}),
pollLuckmailVerificationCode: async () => ({}),
sendToContentScript: async () => ({}),
sendToContentScriptResilient: async (_source, message) => {
if (message.type === 'FILL_CODE') {
throw new Error('message channel is closed before a response was received');
}
if (message.type === 'GET_LOGIN_AUTH_STATE') {
return {
state: 'oauth_consent_page',
url: 'https://auth.openai.com/authorize?client_id=test',
};
}
return {};
},
sendToMailContentScriptResilient: async () => ({
code: '654321',
emailTimestamp: 123,
}),
setState: async (payload) => {
events.push(['state', payload.lastLoginCode || payload.lastSignupCode]);
},
setStepStatus: async () => {},
sleepWithStop: async () => {},
throwIfStopped: () => {},
VERIFICATION_POLL_MAX_ROUNDS: 5,
});
const result = await helpers.resolveVerificationStep(
8,
{ email: 'user@example.com', lastLoginCode: null },
{ provider: 'qq', label: 'QQ Mail' },
{}
);
assert.deepStrictEqual(result, {
phoneVerificationRequired: false,
url: 'https://auth.openai.com/authorize?client_id=test',
});
assert.deepStrictEqual(events.filter((entry) => entry[0] !== 'log'), [
['state', '654321'],
['complete', '654321'],
]);
assert.ok(events.some((entry) => entry[0] === 'log' && /通信中断/.test(entry[1])));
});
test('verification flow treats manual step 8 add-phone confirmation as the same fatal add-phone error', async () => {
const helpers = api.createVerificationFlowHelpers({
addLog: async () => {},