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
@@ -3,13 +3,17 @@ const assert = require('node:assert/strict');
const fs = require('node:fs');
function loadRegisterRunnerApi() {
const stateSource = fs.readFileSync('background/kiro/state.js', 'utf8');
const runnerSource = fs.readFileSync('background/kiro/register-runner.js', 'utf8');
const stateSource = fs.readFileSync('flows/kiro/background/state.js', 'utf8');
const runnerSource = fs.readFileSync('flows/kiro/background/register-runner.js', 'utf8');
const globalScope = {};
new Function('self', `${stateSource}; ${runnerSource}; return self;`)(globalScope);
return globalScope.MultiPageBackgroundKiroRegisterRunner;
}
function getKiroRuntime(state = {}) {
return state?.runtimeState?.flowState?.kiro || {};
}
test('kiro register runner module exposes a factory and Kiro official sign-in entry', () => {
const api = loadRegisterRunnerApi();
assert.equal(typeof api?.createKiroRegisterRunner, 'function');
@@ -17,7 +21,7 @@ test('kiro register runner module exposes a factory and Kiro official sign-in en
});
test('kiro register runner removed the old AWS device authorization bootstrap', () => {
const source = fs.readFileSync('background/kiro/register-runner.js', 'utf8');
const source = fs.readFileSync('flows/kiro/background/register-runner.js', 'utf8');
assert.doesNotMatch(source, /startBuilderIdDeviceLogin/);
assert.doesNotMatch(source, /device_authorization/);
assert.doesNotMatch(source, /verificationUriComplete/);
@@ -25,7 +29,7 @@ test('kiro register runner removed the old AWS device authorization bootstrap',
});
test('kiro register runner uses a shared 3-minute page-load timeout budget', () => {
const source = fs.readFileSync('background/kiro/register-runner.js', 'utf8');
const source = fs.readFileSync('flows/kiro/background/register-runner.js', 'utf8');
assert.match(source, /DEFAULT_KIRO_PAGE_LOAD_TIMEOUT_MS/);
assert.match(source, /createTimeoutBudget/);
assert.match(source, /resolveTimeoutBudget/);
@@ -34,7 +38,7 @@ test('kiro register runner uses a shared 3-minute page-load timeout budget', ()
});
test('kiro register consent step treats Kiro Web signed-in page as completion', () => {
const source = fs.readFileSync('background/kiro/register-runner.js', 'utf8');
const source = fs.readFileSync('flows/kiro/background/register-runner.js', 'utf8');
assert.match(source, /readKiroRegisterPageState\(tabId, \{/);
assert.match(source, /\['authorization_page', 'success_page', 'kiro_web_signed_in'\]\.includes\(landingResult\?\.state\)/);
assert.match(source, /landingResult\?\.state === 'authorization_page'/);
@@ -42,7 +46,7 @@ test('kiro register consent step treats Kiro Web signed-in page as completion',
});
test('kiro register runner uses registration-only page states instead of shared OpenAI names', () => {
const source = fs.readFileSync('background/kiro/register-runner.js', 'utf8');
const source = fs.readFileSync('flows/kiro/background/register-runner.js', 'utf8');
assert.match(source, /KIRO_REGISTER_PAGE_STATES/);
assert.match(source, /'register_otp_page'/);
assert.match(source, /'create_password_page'/);
@@ -54,7 +58,7 @@ test('kiro register runner uses registration-only page states instead of shared
});
test('kiro register runner fails existing-account login branches during registration', () => {
const source = fs.readFileSync('background/kiro/register-runner.js', 'utf8');
const source = fs.readFileSync('flows/kiro/background/register-runner.js', 'utf8');
assert.match(source, /KIRO_REGISTER_EXISTING_ACCOUNT_STATES/);
assert.match(source, /assertKiroRegistrationOnlyState\(landingResult, currentState, 2, resolvedEmail\)/);
assert.match(source, /邮箱.*已进入 AWS Builder ID 登录页/);
@@ -64,12 +68,16 @@ test('kiro register runner fails existing-account login branches during registra
test('kiro submit-email stops immediately when AWS routes the email to login', async () => {
const api = loadRegisterRunnerApi();
const currentState = {
kiroRuntime: {
session: {
registerTabId: 101,
},
register: {
loginUrl: 'https://app.kiro.dev/signin',
runtimeState: {
flowState: {
kiro: {
session: {
registerTabId: 101,
},
register: {
loginUrl: 'https://app.kiro.dev/signin',
},
},
},
},
};
@@ -119,18 +127,22 @@ test('kiro submit-email stops immediately when AWS routes the email to login', a
assert.equal(completed, false);
assert.equal(sentMessages.some((message) => message.type === 'EXECUTE_NODE'), true);
assert.equal(statePatches.some((patch) => /已进入 AWS Builder ID 登录页/.test(patch.kiroRuntime?.session?.lastError || '')), true);
assert.equal(statePatches.some((patch) => /已进入 AWS Builder ID 登录页/.test(getKiroRuntime(patch).session?.lastError || '')), true);
});
test('kiro submit-email can adopt an already-open registration OTP page without allocating a new mailbox', async () => {
const api = loadRegisterRunnerApi();
const currentState = {
kiroRuntime: {
session: {
registerTabId: 102,
},
register: {
loginUrl: 'https://app.kiro.dev/signin',
runtimeState: {
flowState: {
kiro: {
session: {
registerTabId: 102,
},
register: {
loginUrl: 'https://app.kiro.dev/signin',
},
},
},
},
};
@@ -163,8 +175,8 @@ test('kiro submit-email can adopt an already-open registration OTP page without
await runner.executeKiroSubmitEmail({ nodeId: 'kiro-submit-email', ...currentState });
assert.equal(completedPayload?.kiroRuntime?.register?.email, 'manual-user@duck.com');
assert.equal(completedPayload?.kiroRuntime?.register?.status, 'waiting_otp');
assert.equal(completedPayload?.kiroRuntime?.register?.verificationRequestedAt, 0);
assert.equal(getKiroRuntime(completedPayload).register?.email, 'manual-user@duck.com');
assert.equal(getKiroRuntime(completedPayload).register?.status, 'waiting_otp');
assert.equal(getKiroRuntime(completedPayload).register?.verificationRequestedAt, 0);
assert.equal(sentMessages.some((message) => message.type === 'EXECUTE_NODE'), false);
});