refactor flows into canonical runtime architecture

This commit is contained in:
QLHazyCoder
2026-05-21 07:21:34 +08:00
parent e2485d2e64
commit a7b35ee11a
167 changed files with 9034 additions and 3032 deletions
@@ -254,11 +254,11 @@ test('sidepanel source wires runtime signup phone field to background sync messa
test('sidepanel warns once before using phone signup with CPA source', async () => {
assert.match(
sidepanelSource,
/signupMethodButtons\.forEach\(\(button\) => \{[\s\S]*await confirmCpaPhoneSignupIfNeeded\(\{[\s\S]*signupMethod: nextSignupMethod,[\s\S]*panelMode: getSelectedPanelMode\(\),/
/signupMethodButtons\.forEach\(\(button\) => \{[\s\S]*await confirmCpaPhoneSignupIfNeeded\(\{[\s\S]*signupMethod: nextSignupMethod,[\s\S]*targetId: getSelectedPanelMode\(latestState\),/
);
assert.match(
sidepanelSource,
/selectPanelMode\.addEventListener\('change', async \(\) => \{[\s\S]*await confirmCpaPhoneSignupIfNeeded\(\{[\s\S]*signupMethod: getSelectedSignupMethod\(\),[\s\S]*panelMode: nextPanelMode,/
/selectPanelMode\.addEventListener\('change', async \(\) => \{[\s\S]*await confirmCpaPhoneSignupIfNeeded\(\{[\s\S]*signupMethod: getSelectedSignupMethod\(\),[\s\S]*targetId: nextPanelMode,/
);
const bundle = [
@@ -277,6 +277,7 @@ test('sidepanel warns once before using phone signup with CPA source', async ()
const SIGNUP_METHOD_PHONE = 'phone';
const SIGNUP_METHOD_EMAIL = 'email';
const DEFAULT_SIGNUP_METHOD = SIGNUP_METHOD_EMAIL;
const DEFAULT_ACTIVE_FLOW_ID = 'openai';
const CPA_PHONE_SIGNUP_PROMPT_DISMISSED_STORAGE_KEY = 'multipage-cpa-phone-signup-prompt-dismissed';
const CPA_PHONE_SIGNUP_WARNING_MESSAGE = '请确保打开手机接码设置中的“绑定后重登”开关,不然可能无法使用(有些版本无需开启)';
const storage = new Map();
@@ -291,6 +292,11 @@ const localStorage = {
storage.delete(key);
},
};
let latestState = {
activeFlowId: 'openai',
flowId: 'openai',
targetId: 'cpa',
};
let selectedSignupMethod = 'phone';
let selectedPanelMode = 'cpa';
let capturedOptions = null;
@@ -301,6 +307,12 @@ function getSelectedSignupMethod() {
function getSelectedPanelMode() {
return selectedPanelMode;
}
function getSelectedTargetId() {
return selectedPanelMode;
}
function getSelectedTargetIdForState() {
return selectedPanelMode;
}
async function openConfirmModalWithOption(options) {
capturedOptions = options;
return modalResult;
@@ -326,7 +338,7 @@ return {
assert.equal(api.shouldWarnCpaPhoneSignup('phone', 'sub2api'), false);
assert.equal(api.shouldWarnCpaPhoneSignup('phone', 'codex2api'), false);
const firstResult = await api.confirmCpaPhoneSignupIfNeeded({ signupMethod: 'phone', panelMode: 'cpa' });
const firstResult = await api.confirmCpaPhoneSignupIfNeeded({ signupMethod: 'phone', targetId: 'cpa' });
assert.equal(firstResult, true);
assert.equal(api.getCapturedOptions().title, 'CPA 手机号注册提醒');
assert.equal(api.getCapturedOptions().message, '请确保打开手机接码设置中的“绑定后重登”开关,不然可能无法使用(有些版本无需开启)');
@@ -335,7 +347,7 @@ return {
assert.equal(api.getDismissed(), null);
api.setModalResult({ confirmed: false, optionChecked: true });
const secondResult = await api.confirmCpaPhoneSignupIfNeeded({ signupMethod: 'phone', panelMode: 'cpa' });
const secondResult = await api.confirmCpaPhoneSignupIfNeeded({ signupMethod: 'phone', targetId: 'cpa' });
assert.equal(secondResult, false);
assert.equal(api.getDismissed(), '1');
assert.equal(api.shouldWarnCpaPhoneSignup('phone', 'cpa'), false);
@@ -354,11 +366,11 @@ const window = {
MultiPageFlowCapabilities: {
createFlowCapabilityRegistry() {
return {
resolveSidepanelCapabilities({ state = {}, panelMode = 'cpa', signupMethod = 'email' } = {}) {
resolveSidepanelCapabilities({ state = {}, targetId = 'cpa', signupMethod = 'email' } = {}) {
const phoneAllowed = String(state?.activeFlowId || '').trim().toLowerCase() === 'openai';
return {
canSelectPhoneSignup: phoneAllowed,
shouldWarnCpaPhoneSignup: phoneAllowed && signupMethod === 'phone' && panelMode === 'cpa',
shouldWarnCpaPhoneSignup: phoneAllowed && signupMethod === 'phone' && targetId === 'cpa',
};
},
};
@@ -368,11 +380,14 @@ const window = {
let latestState = {
activeFlowId: 'site-a',
accountContributionEnabled: false,
panelMode: 'cpa',
targetId: 'cpa',
};
const inputPhoneVerificationEnabled = { checked: true };
const inputPlusModeEnabled = { checked: false };
function getSelectedFlowId() { return latestState.activeFlowId; }
function getSelectedPanelMode() { return 'cpa'; }
function getSelectedTargetId() { return 'cpa'; }
function getSelectedTargetIdForState() { return 'cpa'; }
function getSelectedSignupMethod() { return 'phone'; }
function isCpaPhoneSignupPromptDismissed() { return false; }
${bundle}
@@ -1059,6 +1074,7 @@ function normalizeAutoDelayMinutes(value) { return Number(value) || 30; }
function normalizeAutoStepDelaySeconds(value) { return value === '' ? null : Number(value); }
function normalizeVerificationResendCount(value, fallback) { return Number(value) || fallback; }
function normalizePlusAccountAccessStrategy(value = '') { return String(value || '').trim().toLowerCase() === PLUS_ACCOUNT_ACCESS_STRATEGY_SUB2API_CODEX_SESSION ? PLUS_ACCOUNT_ACCESS_STRATEGY_SUB2API_CODEX_SESSION : PLUS_ACCOUNT_ACCESS_STRATEGY_OAUTH; }
function resolvePlusAccountAccessStrategyForTarget(value = '') { return normalizePlusAccountAccessStrategy(value); }
${extractFunction('normalizePhoneSmsProvider')}
${extractFunction('normalizePhoneSmsProviderValue')}
${extractFunction('normalizeFiveSimCountryCode')}