From 6db6725c0c9ab18cf7a14a47c79919b79c07a2cf Mon Sep 17 00:00:00 2001 From: QLHazyCoder <2825305047@qq.com> Date: Fri, 22 May 2026 09:35:15 +0800 Subject: [PATCH] fix kiro verification email source --- flows/kiro/background/register-runner.js | 11 +-- ...ground-kiro-register-runner-module.test.js | 94 +++++++++++++++++++ 2 files changed, 98 insertions(+), 7 deletions(-) diff --git a/flows/kiro/background/register-runner.js b/flows/kiro/background/register-runner.js index 9322f10..1f29096 100644 --- a/flows/kiro/background/register-runner.js +++ b/flows/kiro/background/register-runner.js @@ -710,14 +710,12 @@ return KIRO_REGISTER_EXISTING_ACCOUNT_STATES.includes(cleanString(pageState)); } - function resolveKiroRegisterEmail(currentState = {}, pageState = {}, fallbackEmail = '') { - const runtimeState = readKiroRuntime(currentState); + function resolveKiroRegisterEmail(currentState = {}, _pageState = {}, fallbackEmail = '') { return cleanString( fallbackEmail - || pageState?.email - || pageState?.accountEmail - || runtimeState.register?.email || currentState?.email + || currentState?.registrationEmailState?.current + || currentState?.registrationEmailState?.previous ).toLowerCase(); } @@ -886,8 +884,7 @@ } function buildKiroVerificationPollPayload(step, state = {}, mail = {}, filterAfterTimestamp = 0) { - const runtimeState = readKiroRuntime(state); - const targetEmail = cleanString(runtimeState.register?.email || state?.email).toLowerCase(); + const targetEmail = resolveKiroRegisterEmail(state); const targetEmailHints = targetEmail ? [targetEmail] : []; const isMail2925Provider = String(mail?.provider || '').trim().toLowerCase() === '2925'; const normalizedProvider = String(mail?.provider || '').trim().toLowerCase(); diff --git a/tests/background-kiro-register-runner-module.test.js b/tests/background-kiro-register-runner-module.test.js index 886071d..40d6ace 100644 --- a/tests/background-kiro-register-runner-module.test.js +++ b/tests/background-kiro-register-runner-module.test.js @@ -146,6 +146,7 @@ test('kiro submit-email can adopt an already-open registration OTP page without }, }, }, + email: 'manual-user@duck.com', }; const sentMessages = []; let completedPayload = null; @@ -183,9 +184,102 @@ test('kiro submit-email can adopt an already-open registration OTP page without assert.equal(sentMessages.some((message) => message.type === 'EXECUTE_NODE'), false); }); +test('kiro verification polling uses the registration email field instead of page text', async () => { + const api = loadRegisterRunnerApi(); + const currentState = { + email: 'skater-twine-carve@duck.com', + registrationEmailState: { + current: 'skater-twine-carve@duck.com', + previous: 'skater-twine-carve@duck.com', + source: 'flow', + updatedAt: Date.now(), + }, + runtimeState: { + flowState: { + kiro: { + session: { + registerTabId: 103, + }, + register: { + email: 'stale-wrong@duck.comchange', + loginUrl: 'https://app.kiro.dev/signin', + verificationRequestedAt: 1000, + }, + }, + }, + }, + }; + const sentMessages = []; + const pollPayloads = []; + let completedPayload = null; + const runner = api.createKiroRegisterRunner({ + addLog: async () => {}, + chrome: { + tabs: { + get: async (tabId) => ({ id: tabId, url: 'https://us-east-1.signin.aws/platform/d/signup' }), + update: async () => {}, + }, + }, + completeNodeFromBackground: async (_nodeId, payload) => { + completedPayload = payload; + }, + getMailConfig: () => ({ + provider: 'cloudflare-temp-email', + source: 'cloudflare-temp-email', + label: 'Cloudflare Temp Email', + }), + getState: async () => currentState, + getTabId: async () => 103, + isTabAlive: async () => true, + pollCloudflareTempEmailVerificationCode: async (_step, _state, payload) => { + pollPayloads.push(payload); + return { code: '123456', emailTimestamp: 2000, mailId: 'mail-1' }; + }, + sendToContentScriptResilient: async (_sourceId, message) => { + sentMessages.push(message); + if (message.type === 'ENSURE_KIRO_PAGE_STATE') { + return { + state: 'register_otp_page', + url: 'https://us-east-1.signin.aws/platform/d/signup', + email: 'skater-twine-carve@duck.comchange', + accountEmail: 'skater-twine-carve@duck.comchange', + }; + } + if (message.type === 'EXECUTE_NODE') { + return { submitted: true, state: 'verification_submitted' }; + } + if (message.type === 'ENSURE_KIRO_STATE_CHANGE') { + return { + state: 'create_password_page', + url: 'https://us-east-1.signin.aws/platform/d/signup', + email: 'skater-twine-carve@duck.comchange', + }; + } + return {}; + }, + setState: async () => {}, + }); + + await runner.executeKiroSubmitVerificationCode({ + nodeId: 'kiro-submit-verification-code', + ...currentState, + }); + + assert.equal(pollPayloads.length, 1); + assert.equal(pollPayloads[0].targetEmail, 'skater-twine-carve@duck.com'); + assert.deepEqual(pollPayloads[0].targetEmailHints, ['skater-twine-carve@duck.com']); + assert.equal(sentMessages.some((message) => ( + message.type === 'EXECUTE_NODE' + && message.nodeId === 'kiro-submit-verification-code' + && message.payload?.code === '123456' + )), true); + assert.equal(getKiroRuntime(completedPayload).register?.email, 'skater-twine-carve@duck.com'); +}); + test('kiro submit-email reuses the step 1 register tab even when the source registry was reset', async () => { const api = loadRegisterRunnerApi(); const currentState = { + email: 'fresh-user@duck.com', runtimeState: { flowState: { kiro: {