feat: Enhance Step 9 diagnostics and error handling

- Refactor getStatusBadgeEntries to use createStep9Entry for better encapsulation.
- Introduce error visual signals detection in createStep9Entry.
- Add functions to identify OAuth callback timeout failures and step 9 failure texts.
- Update buildStep9StatusDiagnostics to include error visual summaries and handle conflicts between success and failure states.
- Implement new tests for step 9 diagnostics, ensuring correct behavior with success badges and error banners.
- Remove outdated tests related to step 5 onboarding and redirect race conditions.
- Add new tests for auto-run behavior in step 6 restart scenarios.
This commit is contained in:
QLHazyCoder
2026-04-17 04:33:14 +08:00
parent 1a5f569d16
commit c745405f90
17 changed files with 772 additions and 691 deletions
@@ -6,47 +6,42 @@ const source = fs.readFileSync('background/steps/fill-profile.js', 'utf8');
const globalScope = {};
const api = new Function('self', `${source}; return self.MultiPageBackgroundStep5;`)(globalScope);
test('step 5 transport error returns immediately after completion signal arrives', async () => {
test('step 5 forwards generated profile data and relies on completion signal flow', async () => {
const events = {
redirectWaitCalls: 0,
onboardingCalls: 0,
logs: [],
messages: [],
};
const transportError = new Error('The message port closed before a response was received.');
const executor = api.createStep5Executor({
addLog: async (message, level) => {
events.logs.push({ message, level: level || 'info' });
},
generateRandomBirthday: () => ({ year: 2003, month: 6, day: 19 }),
generateRandomName: () => ({ firstName: 'Test', lastName: 'User' }),
getState: async () => ({
stepStatuses: {
5: 'completed',
},
}),
getTabId: async () => 123,
handleChatgptOnboardingSkip: async () => {
events.onboardingCalls += 1;
},
isRetryableContentScriptTransportError: (error) => error === transportError,
LOG_PREFIX: '[test]',
sendToContentScript: async () => {
throw transportError;
},
waitForStep5ChatgptRedirect: async () => {
events.redirectWaitCalls += 1;
return { id: 123, url: 'https://chatgpt.com/' };
sendToContentScript: async (source, message) => {
events.messages.push({ source, message });
return { accepted: true };
},
});
await executor.executeStep5();
assert.equal(events.redirectWaitCalls, 0, '收到完成信号后不应再等待 ChatGPT 跳转');
assert.equal(events.onboardingCalls, 0, '收到完成信号后不应再触发 onboarding 跳过');
assert.ok(
events.logs.some(({ message }) => /已收到完成信号直接结束当前步骤/.test(message)),
'应记录 Step 5 已按完成信号直接结束'
);
assert.deepStrictEqual(events.messages, [
{
source: 'signup-page',
message: {
type: 'EXECUTE_STEP',
step: 5,
source: 'background',
payload: {
firstName: 'Test',
lastName: 'User',
year: 2003,
month: 6,
day: 19,
},
},
},
]);
assert.ok(events.logs.some(({ message }) => /已生成姓名 Test User/.test(message)));
});