修复 Step 5 导航交棒后的完成收尾
This commit is contained in:
@@ -201,3 +201,59 @@ return {
|
||||
true
|
||||
);
|
||||
});
|
||||
|
||||
test('step 5 recovers from bfcache transport close when tab already reached chatgpt', async () => {
|
||||
const api = new Function(`
|
||||
const logs = [];
|
||||
let waitCalls = 0;
|
||||
|
||||
async function getTabId(source) {
|
||||
return source === 'openai-auth' ? 42 : null;
|
||||
}
|
||||
|
||||
async function waitForTabStableComplete(tabId) {
|
||||
waitCalls += 1;
|
||||
if (tabId !== 42) throw new Error('unexpected tab id');
|
||||
return { url: 'https://chatgpt.com/' };
|
||||
}
|
||||
|
||||
async function addLog(message, level, meta) {
|
||||
logs.push({ message, level, meta });
|
||||
}
|
||||
|
||||
function getErrorMessage(error) {
|
||||
return String(error?.message || error || '');
|
||||
}
|
||||
|
||||
${extractFunction('parseUrlSafely')}
|
||||
${extractFunction('isSignupEntryHost')}
|
||||
${extractFunction('isLikelyLoggedInChatgptHomeUrl')}
|
||||
${extractFunction('isStep5CompletionChatgptUrl')}
|
||||
${extractFunction('completeStep5FromTabUrlAfterTransportError')}
|
||||
|
||||
return {
|
||||
async run() {
|
||||
return completeStep5FromTabUrlAfterTransportError(new Error('The page keeping the extension port is moved into back/forward cache, so the message channel is closed.'));
|
||||
},
|
||||
snapshot() {
|
||||
return { logs, waitCalls };
|
||||
},
|
||||
};
|
||||
`)();
|
||||
|
||||
const result = await api.run();
|
||||
const snapshot = api.snapshot();
|
||||
|
||||
assert.deepStrictEqual(result, {
|
||||
profileSubmitted: true,
|
||||
postSubmitChecked: true,
|
||||
outcome: 'logged_in_home',
|
||||
url: 'https://chatgpt.com/',
|
||||
recoveredFromTransportError: true,
|
||||
});
|
||||
assert.equal(snapshot.waitCalls, 1);
|
||||
assert.equal(
|
||||
snapshot.logs.some(({ message }) => /通信中断,但后台确认标签页已进入 chatgpt\.com/.test(message)),
|
||||
true
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user