refactor shared flow settings and runtime cleanup
This commit is contained in:
@@ -78,6 +78,9 @@ test('grok verification runner polls by flow node and submits normalized code',
|
||||
registerTab: async () => {},
|
||||
sendToContentScriptResilient: async (sourceId, message) => {
|
||||
calls.push({ type: 'send', sourceId, message });
|
||||
if (message.nodeId === 'GET_PAGE_STATE') {
|
||||
return { submitted: true, state: 'verification_code_entry', url: 'https://accounts.x.ai/verify' };
|
||||
}
|
||||
return { submitted: true, state: 'profile_entry', url: 'https://accounts.x.ai/profile' };
|
||||
},
|
||||
setState: async (patch) => {
|
||||
@@ -97,7 +100,9 @@ test('grok verification runner polls by flow node and submits normalized code',
|
||||
assert.equal(pollCall.options.state.activeFlowId, 'grok');
|
||||
assert.equal(pollCall.options.state.visibleStep, 3);
|
||||
|
||||
const sendCall = calls.find((entry) => entry.type === 'send');
|
||||
const sendCall = calls.find((entry) => (
|
||||
entry.type === 'send' && entry.message.nodeId === 'grok-submit-verification-code'
|
||||
));
|
||||
assert.equal(sendCall.sourceId, 'grok-register-page');
|
||||
assert.equal(sendCall.message.type, 'EXECUTE_NODE');
|
||||
assert.equal(sendCall.message.nodeId, 'grok-submit-verification-code');
|
||||
@@ -110,6 +115,75 @@ test('grok verification runner polls by flow node and submits normalized code',
|
||||
assert.equal(getGrokRuntime(completedPayload).register.status, 'verified');
|
||||
});
|
||||
|
||||
test('grok verification runner waits for verification page before polling mail', async () => {
|
||||
const api = loadGrokRunnerApi();
|
||||
let pollCalled = false;
|
||||
let currentState = {
|
||||
activeFlowId: 'grok',
|
||||
grokRegisterTabId: 102,
|
||||
grokEmail: 'grok-user@example.com',
|
||||
grokVerificationRequestedAt: 1000000,
|
||||
runtimeState: {
|
||||
flowState: {
|
||||
grok: {
|
||||
session: {
|
||||
registerTabId: 102,
|
||||
},
|
||||
register: {
|
||||
email: 'grok-user@example.com',
|
||||
verificationRequestedAt: 1000000,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const originalDateNow = Date.now;
|
||||
let fakeNow = 1000000;
|
||||
const runner = api.createGrokRegisterRunner({
|
||||
addLog: async () => {},
|
||||
chrome: {
|
||||
tabs: {
|
||||
get: async (tabId) => ({ id: tabId }),
|
||||
update: async () => {},
|
||||
},
|
||||
},
|
||||
completeNodeFromBackground: async () => {},
|
||||
ensureContentScriptReadyOnTab: async () => {},
|
||||
getState: async () => currentState,
|
||||
getTabId: async () => 102,
|
||||
isTabAlive: async () => true,
|
||||
pollFlowVerificationCode: async () => {
|
||||
pollCalled = true;
|
||||
return { code: 'ABC-123', messageId: 'mail-001' };
|
||||
},
|
||||
registerTab: async () => {},
|
||||
sendToContentScriptResilient: async (_sourceId, message) => {
|
||||
if (message.nodeId === 'GET_PAGE_STATE') {
|
||||
return { submitted: true, state: 'email_entry', url: 'https://accounts.x.ai/sign-up' };
|
||||
}
|
||||
return { submitted: true, state: 'profile_entry', url: 'https://accounts.x.ai/profile' };
|
||||
},
|
||||
setState: async (patch) => {
|
||||
currentState = { ...currentState, ...patch };
|
||||
},
|
||||
sleepWithStop: async (ms = 0) => {
|
||||
fakeNow += Number(ms) || 1000;
|
||||
},
|
||||
waitForTabStableComplete: async () => {},
|
||||
});
|
||||
|
||||
Date.now = () => fakeNow;
|
||||
try {
|
||||
await assert.rejects(
|
||||
() => runner.executeGrokSubmitVerificationCode({ nodeId: 'grok-submit-verification-code', ...currentState }),
|
||||
/尚未进入验证码页面/
|
||||
);
|
||||
} finally {
|
||||
Date.now = originalDateNow;
|
||||
}
|
||||
assert.equal(pollCalled, false);
|
||||
});
|
||||
|
||||
test('grok SSO extraction stores only the current cookie without logging the secret value', async () => {
|
||||
const api = loadGrokRunnerApi();
|
||||
const logs = [];
|
||||
|
||||
Reference in New Issue
Block a user