refactor flows into canonical runtime architecture
This commit is contained in:
@@ -1,20 +1,19 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const { readSourceRegistryBundle } = require('./helpers/script-bundles.js');
|
||||
|
||||
function loadSourceRegistry() {
|
||||
const flowRegistrySource = fs.readFileSync('shared/flow-registry.js', 'utf8');
|
||||
const sourceRegistrySource = fs.readFileSync('shared/source-registry.js', 'utf8');
|
||||
const globalScope = {};
|
||||
new Function('self', `${flowRegistrySource}; ${sourceRegistrySource}; return self;`)(globalScope);
|
||||
new Function('self', `${readSourceRegistryBundle()}; return self;`)(globalScope);
|
||||
return globalScope.MultiPageSourceRegistry.createSourceRegistry();
|
||||
}
|
||||
|
||||
test('background imports shared source registry module', () => {
|
||||
const source = fs.readFileSync('background.js', 'utf8');
|
||||
assert.match(source, /shared\/flow-registry\.js/);
|
||||
assert.match(source, /shared\/settings-schema\.js/);
|
||||
assert.match(source, /shared\/source-registry\.js/);
|
||||
assert.match(source, /core\/flow-kernel\/flow-registry\.js/);
|
||||
assert.match(source, /core\/flow-kernel\/settings-schema\.js/);
|
||||
assert.match(source, /core\/flow-kernel\/source-registry\.js/);
|
||||
assert.match(source, /shared\/kiro-timeouts\.js/);
|
||||
});
|
||||
|
||||
@@ -23,10 +22,10 @@ test('manifest loads shared source registry before content utils in static bundl
|
||||
for (const entry of manifest.content_scripts || []) {
|
||||
const scripts = Array.isArray(entry.js) ? entry.js : [];
|
||||
if (!scripts.includes('content/utils.js')) continue;
|
||||
assert.ok(scripts.includes('shared/source-registry.js'));
|
||||
assert.ok(scripts.includes('core/flow-kernel/source-registry.js'));
|
||||
assert.ok(
|
||||
scripts.indexOf('shared/source-registry.js') < scripts.indexOf('content/utils.js'),
|
||||
'shared/source-registry.js must load before content/utils.js'
|
||||
scripts.indexOf('core/flow-kernel/source-registry.js') < scripts.indexOf('content/utils.js'),
|
||||
'core/flow-kernel/source-registry.js must load before content/utils.js'
|
||||
);
|
||||
}
|
||||
});
|
||||
@@ -35,8 +34,8 @@ test('manifest no longer ships a static Kiro content bundle', () => {
|
||||
const manifest = JSON.parse(fs.readFileSync('manifest.json', 'utf8'));
|
||||
const hasStaticKiroBundle = (manifest.content_scripts || []).some((entry) => {
|
||||
const scripts = Array.isArray(entry.js) ? entry.js : [];
|
||||
return scripts.includes('content/kiro/register-page.js')
|
||||
|| scripts.includes('content/kiro/desktop-authorize-page.js');
|
||||
return scripts.includes('flows/kiro/content/register-page.js')
|
||||
|| scripts.includes('flows/kiro/content/desktop-authorize-page.js');
|
||||
});
|
||||
|
||||
assert.equal(hasStaticKiroBundle, false);
|
||||
@@ -46,19 +45,20 @@ test('background injects shared Kiro timeout module before Kiro content scripts'
|
||||
const source = fs.readFileSync('background.js', 'utf8');
|
||||
assert.match(
|
||||
source,
|
||||
/const KIRO_REGISTER_INJECT_FILES = \['shared\/source-registry\.js', 'shared\/kiro-timeouts\.js', 'content\/utils\.js', 'content\/kiro\/register-page\.js'\];/
|
||||
/const KIRO_REGISTER_INJECT_FILES = \['flows\/openai\/index\.js', 'flows\/kiro\/index\.js', 'flows\/index\.js', 'core\/flow-kernel\/flow-registry\.js', 'core\/flow-kernel\/source-registry\.js', 'shared\/kiro-timeouts\.js', 'content\/utils\.js', 'flows\/kiro\/content\/register-page\.js'\];/
|
||||
);
|
||||
assert.match(
|
||||
source,
|
||||
/const KIRO_DESKTOP_AUTHORIZE_INJECT_FILES = \['shared\/source-registry\.js', 'shared\/kiro-timeouts\.js', 'content\/utils\.js', 'content\/kiro\/desktop-authorize-page\.js'\];/
|
||||
/const KIRO_DESKTOP_AUTHORIZE_INJECT_FILES = \['flows\/openai\/index\.js', 'flows\/kiro\/index\.js', 'flows\/index\.js', 'core\/flow-kernel\/flow-registry\.js', 'core\/flow-kernel\/source-registry\.js', 'shared\/kiro-timeouts\.js', 'content\/utils\.js', 'flows\/kiro\/content\/desktop-authorize-page\.js'\];/
|
||||
);
|
||||
});
|
||||
|
||||
test('shared source registry exposes canonical Kiro sources and drivers', () => {
|
||||
const registry = loadSourceRegistry();
|
||||
|
||||
assert.equal(registry.resolveCanonicalSource('signup-page'), 'openai-auth');
|
||||
assert.deepEqual(registry.getSourceKeys('signup-page'), ['openai-auth', 'signup-page']);
|
||||
assert.equal(registry.resolveCanonicalSource('openai-auth'), 'openai-auth');
|
||||
assert.deepEqual(registry.getSourceKeys('openai-auth'), ['openai-auth']);
|
||||
assert.equal(registry.resolveCanonicalSource('signup-page'), 'signup-page');
|
||||
assert.equal(registry.getSourceLabel('openai-auth'), '认证页');
|
||||
|
||||
assert.equal(
|
||||
@@ -132,9 +132,9 @@ test('shared source registry exposes canonical Kiro sources and drivers', () =>
|
||||
assert.equal(registry.driverAcceptsCommand('openai-auth', 'submit-signup-email'), true);
|
||||
assert.equal(registry.driverAcceptsCommand('content/platform-panel', 'platform-verify'), true);
|
||||
assert.equal(registry.driverAcceptsCommand('openai-auth', 'platform-verify'), false);
|
||||
assert.equal(registry.driverAcceptsCommand('content/kiro/register-page', 'kiro-submit-password'), true);
|
||||
assert.equal(registry.driverAcceptsCommand('content/kiro/desktop-authorize-page', 'kiro-complete-desktop-authorize'), true);
|
||||
assert.equal(registry.driverAcceptsCommand('background/kiro-register', 'kiro-open-register-page'), true);
|
||||
assert.equal(registry.driverAcceptsCommand('background/kiro-desktop-authorize', 'kiro-start-desktop-authorize'), true);
|
||||
assert.equal(registry.driverAcceptsCommand('background/kiro-publisher-kiro-rs', 'kiro-upload-credential'), true);
|
||||
assert.equal(registry.driverAcceptsCommand('flows/kiro/content/register-page', 'kiro-submit-password'), true);
|
||||
assert.equal(registry.driverAcceptsCommand('flows/kiro/content/desktop-authorize-page', 'kiro-complete-desktop-authorize'), true);
|
||||
assert.equal(registry.driverAcceptsCommand('flows/kiro/background/register-runner', 'kiro-open-register-page'), true);
|
||||
assert.equal(registry.driverAcceptsCommand('flows/kiro/background/desktop-authorize-runner', 'kiro-start-desktop-authorize'), true);
|
||||
assert.equal(registry.driverAcceptsCommand('flows/kiro/background/publisher-kiro-rs', 'kiro-upload-credential'), true);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user