feat: 添加登录超时恢复逻辑,优化登录流程中的错误处理与状态管理

This commit is contained in:
QLHazyCoder
2026-04-23 00:05:18 +08:00
parent 6039cbaf87
commit 9b4feea87c
4 changed files with 353 additions and 40 deletions
+2 -1
View File
@@ -87,7 +87,8 @@ test('step6LoginFromPasswordPage switches to one-time-code login when password i
globalThis.log = (message, level = 'info') => {
logs.push({ message, level });
};
globalThis.step6SwitchToOneTimeCodeLogin = async (value) => {
globalThis.step6SwitchToOneTimeCodeLogin = async (payload, value) => {
assert.deepStrictEqual(payload, { email: 'user@example.com', password: '' });
assert.strictEqual(value, snapshot);
return { step6Outcome: 'success', via: 'switch_to_one_time_code_login' };
};
+143
View File
@@ -72,12 +72,18 @@ async function recoverCurrentAuthRetryPage() {
return { recovered: true };
}
function throwIfStopped() {}
async function sleep() {}
function log(message, level = 'info') {
logs.push({ message, level });
}
${extractFunction('createStep6SuccessResult')}
${extractFunction('createStep6RecoverableResult')}
${extractFunction('normalizeStep6Snapshot')}
${extractFunction('waitForKnownLoginAuthState')}
${extractFunction('createStep6LoginTimeoutRecoveryTransition')}
${extractFunction('createStep6LoginTimeoutRecoverableResult')}
return {
@@ -104,6 +110,141 @@ return {
assert.equal(result.message, '当前页面处于登录超时报错页。');
});
test('step 7 timeout recovery transition continues from password page after retry succeeds', async () => {
const api = new Function(`
const logs = [];
let recoverCalls = 0;
let currentState = 'login_timeout_error_page';
const location = {
href: 'https://auth.openai.com/log-in',
};
function inspectLoginAuthState() {
return {
state: currentState,
url: location.href,
};
}
async function recoverCurrentAuthRetryPage() {
recoverCalls += 1;
currentState = 'password_page';
return { recovered: true };
}
function throwIfStopped() {}
async function sleep() {}
function log(message, level = 'info') {
logs.push({ message, level });
}
${extractFunction('createStep6SuccessResult')}
${extractFunction('createStep6RecoverableResult')}
${extractFunction('normalizeStep6Snapshot')}
${extractFunction('waitForKnownLoginAuthState')}
${extractFunction('createStep6LoginTimeoutRecoveryTransition')}
return {
async run() {
return createStep6LoginTimeoutRecoveryTransition(
'login_timeout_error_page',
{ state: 'login_timeout_error_page', url: location.href },
'当前页面处于登录超时报错页。',
{
via: 'login_timeout_initial_recovered',
}
);
},
snapshot() {
return { logs, recoverCalls };
},
};
`)();
const result = await api.run();
const snapshot = api.snapshot();
assert.equal(snapshot.recoverCalls, 1);
assert.equal(result.action, 'password');
assert.equal(result.snapshot.state, 'password_page');
assert.equal(snapshot.logs.some(({ message }) => /密码页/.test(message)), true);
});
test('step 7 entry resumes password flow after retry page recovery reaches password page', async () => {
const api = new Function(`
const logs = [];
let recoverCalls = 0;
let currentState = 'login_timeout_error_page';
const location = {
href: 'https://auth.openai.com/log-in',
};
function inspectLoginAuthState() {
return {
state: currentState,
url: location.href,
};
}
async function recoverCurrentAuthRetryPage() {
recoverCalls += 1;
currentState = 'password_page';
return { recovered: true };
}
function throwIfStopped() {}
async function sleep() {}
function log(message, level = 'info') {
logs.push({ message, level });
}
async function step6LoginFromPasswordPage(payload, snapshot) {
return { branch: 'password', payload, snapshot };
}
async function step6LoginFromEmailPage(payload, snapshot) {
return { branch: 'email', payload, snapshot };
}
async function finalizeStep6VerificationReady(options) {
return { branch: 'verification', options };
}
function throwForStep6FatalState() {}
${extractFunction('createStep6SuccessResult')}
${extractFunction('createStep6RecoverableResult')}
${extractFunction('normalizeStep6Snapshot')}
${extractFunction('waitForKnownLoginAuthState')}
${extractFunction('createStep6LoginTimeoutRecoveryTransition')}
${extractFunction('step6_login')}
return {
async run() {
return step6_login({
email: 'user@example.com',
password: 'secret',
});
},
snapshot() {
return { logs, recoverCalls };
},
};
`)();
const result = await api.run();
const snapshot = api.snapshot();
assert.equal(snapshot.recoverCalls, 1);
assert.equal(result.branch, 'password');
assert.equal(result.snapshot.state, 'password_page');
assert.equal(snapshot.logs.some(({ message }) => /密码页/.test(message)), true);
});
test('step 7 finalize converts verification page that falls into retry page into recoverable result', async () => {
const api = new Function(`
const logs = [];
@@ -150,6 +291,8 @@ function getLoginAuthStateLabel(snapshot) {
${extractFunction('createStep6SuccessResult')}
${extractFunction('createStep6RecoverableResult')}
${extractFunction('normalizeStep6Snapshot')}
${extractFunction('waitForKnownLoginAuthState')}
${extractFunction('createStep6LoginTimeoutRecoveryTransition')}
${extractFunction('createStep6LoginTimeoutRecoverableResult')}
${extractFunction('finalizeStep6VerificationReady')}