Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
32c190d
add/expose initPromise
odilitime Nov 13, 2025
8cdd3f0
update loggeer, add initPromise & hasElizaOS()
odilitime Nov 13, 2025
6237f0f
better mysql detection/support
odilitime Nov 13, 2025
5514e50
scenario mysql support
odilitime Nov 13, 2025
6478827
new tests
odilitime Nov 13, 2025
8b50109
jest => mock
odilitime Nov 13, 2025
6af60f4
better mysql support
odilitime Nov 13, 2025
52245ca
new mysql utils
odilitime Nov 13, 2025
b7e9fe4
use new mysql utils, refactor init so they're similar, security note
odilitime Nov 13, 2025
620ad94
match initPromise behavior better
odilitime Nov 13, 2025
a214829
better mysql support/detection
odilitime Nov 13, 2025
f89b4ad
new test
odilitime Nov 13, 2025
924175e
throw if cli didnt provide any db plugins
odilitime Nov 13, 2025
96c2b1d
lower debug
odilitime Nov 13, 2025
12952bb
make database configurable
odilitime Nov 14, 2025
c762525
use ENV to drive adapter selection
odilitime Nov 14, 2025
2fc676d
ensure world
odilitime Nov 14, 2025
7d22f51
Merge branch 'develop' into spartan-prod
standujar Nov 19, 2025
0460612
Merge branch 'develop' into spartan-prod
wtfsayo Nov 29, 2025
ab0728b
Detect MySQL usage from plugin name instead of env var
wtfsayo Nov 29, 2025
04fbb20
Merge develop into spartan-prod
wtfsayo Nov 30, 2025
efe1536
Fix property name and formatting in AgentRuntime
wtfsayo Nov 30, 2025
7fdcafa
Refactor plugin registration and improve test mocks
wtfsayo Nov 30, 2025
47c78e4
Merge branch 'develop' into spartan-prod
wtfsayo Dec 1, 2025
90984f5
fix(core): resolve initPromise after world/room creation completes
wtfsayo Dec 1, 2025
a406e55
Merge remote-tracking branch 'origin/develop' into spartan-prod
wtfsayo Dec 1, 2025
ca4ae47
chore: merge develop into spartan-prod
wtfsayo Dec 1, 2025
f4e1d41
Add tests for plugin adapter registration order
wtfsayo Dec 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

221 changes: 221 additions & 0 deletions packages/cli/src/commands/scenario/__tests__/plugin-selection.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
/**
* Plugin Selection Tests for Scenario Runtime
* Ensures plugin-sql and plugin-mysql are not loaded simultaneously
*/

import { describe, it, expect, beforeEach, afterEach } from 'bun:test';

describe('Scenario Plugin Selection', () => {
let originalMysqlUrl: string | undefined;

beforeEach(() => {
originalMysqlUrl = process.env.MYSQL_URL;
});

afterEach(() => {
if (originalMysqlUrl !== undefined) {
process.env.MYSQL_URL = originalMysqlUrl;
} else {
delete process.env.MYSQL_URL;
}
});

it('should select plugin-sql when MYSQL_URL is not set', () => {
delete process.env.MYSQL_URL;

// Simulate the default plugin selection logic from runtime-factory
const defaultDatabasePlugin = process.env.MYSQL_URL
? '@elizaos/plugin-mysql'
: '@elizaos/plugin-sql';

expect(defaultDatabasePlugin).toBe('@elizaos/plugin-sql');
});

it('should select plugin-mysql when MYSQL_URL is set', () => {
process.env.MYSQL_URL = 'mysql://user:password@localhost:3306/testdb';

// Simulate the default plugin selection logic from runtime-factory
const defaultDatabasePlugin = process.env.MYSQL_URL
? '@elizaos/plugin-mysql'
: '@elizaos/plugin-sql';

expect(defaultDatabasePlugin).toBe('@elizaos/plugin-mysql');
});

it('should remove plugin-sql when plugin-mysql is present in plugin list', () => {
const pluginNames = [
'@elizaos/plugin-mysql',
'@elizaos/plugin-sql',
'@elizaos/plugin-openai',
'@elizaos/plugin-bootstrap',
];

// Simulate the conflict detection logic from runtime-factory
const hasMysqlPlugin = pluginNames.some(
(p) => p === '@elizaos/plugin-mysql' || p === 'plugin-mysql'
);
const hasSqlPlugin = pluginNames.some(
(p) => p === '@elizaos/plugin-sql' || p === 'plugin-sql'
);

let finalPluginNames = pluginNames;
if (hasMysqlPlugin && hasSqlPlugin) {
// Remove plugin-sql if plugin-mysql is present
finalPluginNames = pluginNames.filter(
(p) => p !== '@elizaos/plugin-sql' && p !== 'plugin-sql'
);
}

expect(finalPluginNames).toContain('@elizaos/plugin-mysql');
expect(finalPluginNames).not.toContain('@elizaos/plugin-sql');
expect(finalPluginNames).toContain('@elizaos/plugin-openai');
expect(finalPluginNames).toContain('@elizaos/plugin-bootstrap');
});

it('should keep plugin-sql when plugin-mysql is not present', () => {
const pluginNames = [
'@elizaos/plugin-sql',
'@elizaos/plugin-openai',
'@elizaos/plugin-bootstrap',
];

// Simulate the conflict detection logic from runtime-factory
const hasMysqlPlugin = pluginNames.some(
(p) => p === '@elizaos/plugin-mysql' || p === 'plugin-mysql'
);
const hasSqlPlugin = pluginNames.some(
(p) => p === '@elizaos/plugin-sql' || p === 'plugin-sql'
);

let finalPluginNames = pluginNames;
if (hasMysqlPlugin && hasSqlPlugin) {
finalPluginNames = pluginNames.filter(
(p) => p !== '@elizaos/plugin-sql' && p !== 'plugin-sql'
);
}

expect(finalPluginNames).toContain('@elizaos/plugin-sql');
expect(finalPluginNames).not.toContain('@elizaos/plugin-mysql');
});

it('should handle plugin names without @elizaos/ prefix', () => {
const pluginNames = ['plugin-mysql', 'plugin-sql', 'plugin-openai'];

// Simulate the conflict detection logic from runtime-factory
const hasMysqlPlugin = pluginNames.some(
(p) => p === '@elizaos/plugin-mysql' || p === 'plugin-mysql'
);
const hasSqlPlugin = pluginNames.some(
(p) => p === '@elizaos/plugin-sql' || p === 'plugin-sql'
);

let finalPluginNames = pluginNames;
if (hasMysqlPlugin && hasSqlPlugin) {
finalPluginNames = pluginNames.filter(
(p) => p !== '@elizaos/plugin-sql' && p !== 'plugin-sql'
);
}

expect(finalPluginNames).toContain('plugin-mysql');
expect(finalPluginNames).not.toContain('plugin-sql');
});

it('should work with mixed plugin name formats', () => {
const pluginNames = [
'@elizaos/plugin-mysql',
'plugin-sql', // Different format
'@elizaos/plugin-openai',
];

// Simulate the conflict detection logic from runtime-factory
const hasMysqlPlugin = pluginNames.some(
(p) => p === '@elizaos/plugin-mysql' || p === 'plugin-mysql'
);
const hasSqlPlugin = pluginNames.some(
(p) => p === '@elizaos/plugin-sql' || p === 'plugin-sql'
);

let finalPluginNames = pluginNames;
if (hasMysqlPlugin && hasSqlPlugin) {
finalPluginNames = pluginNames.filter(
(p) => p !== '@elizaos/plugin-sql' && p !== 'plugin-sql'
);
}

expect(finalPluginNames).toContain('@elizaos/plugin-mysql');
expect(finalPluginNames).not.toContain('plugin-sql');
expect(finalPluginNames.length).toBe(2); // mysql and openai
});

it('should prefer plugin-mysql in scenario when both MYSQL_URL is set and plugins specified', () => {
process.env.MYSQL_URL = 'mysql://localhost:3306/db';

const scenarioPlugins = ['@elizaos/plugin-openai'];

// Simulate scenario plugin selection logic
const hasMysqlPlugin = scenarioPlugins.some(
(p: string) => p === '@elizaos/plugin-mysql' || p === 'plugin-mysql'
);
const useMysql = hasMysqlPlugin || !!process.env.MYSQL_URL;

const defaultPlugins = [
useMysql ? '@elizaos/plugin-mysql' : '@elizaos/plugin-sql',
'@elizaos/plugin-bootstrap',
'@elizaos/plugin-openai',
];

const finalPlugins = Array.from(new Set([...scenarioPlugins, ...defaultPlugins]));

expect(finalPlugins).toContain('@elizaos/plugin-mysql');
expect(finalPlugins).not.toContain('@elizaos/plugin-sql');
});

it('should use plugin-sql in scenario when MYSQL_URL is not set', () => {
delete process.env.MYSQL_URL;

const scenarioPlugins: string[] = [];

// Simulate scenario plugin selection logic
const hasMysqlPlugin = scenarioPlugins.some(
(p: string) => p === '@elizaos/plugin-mysql' || p === 'plugin-mysql'
);
const useMysql = hasMysqlPlugin || !!process.env.MYSQL_URL;

const defaultPlugins = [
useMysql ? '@elizaos/plugin-mysql' : '@elizaos/plugin-sql',
'@elizaos/plugin-bootstrap',
'@elizaos/plugin-openai',
];

const finalPlugins = Array.from(new Set([...scenarioPlugins, ...defaultPlugins]));

expect(finalPlugins).toContain('@elizaos/plugin-sql');
expect(finalPlugins).not.toContain('@elizaos/plugin-mysql');
});

it('should respect explicit plugin-mysql in scenario plugins even without MYSQL_URL', () => {
delete process.env.MYSQL_URL;

const scenarioPlugins = ['@elizaos/plugin-mysql', '@elizaos/plugin-openai'];

// Simulate scenario plugin selection logic
const hasMysqlPlugin = scenarioPlugins.some(
(p: string) => p === '@elizaos/plugin-mysql' || p === 'plugin-mysql'
);
const useMysql = hasMysqlPlugin || !!process.env.MYSQL_URL;

const defaultPlugins = [
useMysql ? '@elizaos/plugin-mysql' : '@elizaos/plugin-sql',
'@elizaos/plugin-bootstrap',
'@elizaos/plugin-openai',
];

const finalPlugins = Array.from(new Set([...scenarioPlugins, ...defaultPlugins]));

expect(finalPlugins).toContain('@elizaos/plugin-mysql');
expect(finalPlugins).not.toContain('@elizaos/plugin-sql');
// Should only have one instance of plugin-mysql (deduped by Set)
expect(finalPlugins.filter((p) => p === '@elizaos/plugin-mysql').length).toBe(1);
});
});

34 changes: 23 additions & 11 deletions packages/cli/src/commands/scenario/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,22 +159,34 @@ export const scenario = new Command()
// Initialize Reporter
reporter = new Reporter();
reporter.reportStart(scenario);

// Extract plugin names from scenario configuration, filtering by enabled status
const scenarioPlugins = Array.isArray((scenario as any).plugins)
? (scenario as any).plugins
.filter((p: any) => p.enabled !== false) // Only include enabled plugins (default to true if not specified)
.map((p: any) => (typeof p === 'string' ? p : p.name)) // Extract name if it's an object
: [];

// Determine which database plugin to use
// If plugin-mysql is specified in scenario plugins or MYSQL_URL is set, use plugin-mysql
// Otherwise, use plugin-sql (default)
const hasMysqlPlugin = scenarioPlugins.some(
(p: string) => p === '@elizaos/plugin-mysql' || p === 'plugin-mysql'
);
const useMysql = hasMysqlPlugin || !!process.env.MYSQL_URL;

const defaultPlugins = [
'@elizaos/plugin-sql',
useMysql ? '@elizaos/plugin-mysql' : '@elizaos/plugin-sql',
'@elizaos/plugin-bootstrap',
'@elizaos/plugin-openai',
];
// Ensure PGLite uses isolated directory per scenario run when not overridden
if (!process.env.PGLITE_DATA_DIR) {

// Ensure PGLite uses isolated directory per scenario run when not overridden (only for SQL plugin)
if (!useMysql && !process.env.PGLITE_DATA_DIR) {
const uniqueDir = `${process.cwd()}/test-data/scenario-${Date.now()}-${Math.random().toString(36).slice(2)}`;
process.env.PGLITE_DATA_DIR = uniqueDir;
}
// Extract plugin names from scenario configuration, filtering by enabled status
const scenarioPlugins = Array.isArray((scenario as any).plugins)
? (scenario as any).plugins
.filter((p: any) => p.enabled !== false) // Only include enabled plugins (default to true if not specified)
.map((p: any) => (typeof p === 'string' ? p : p.name)) // Extract name if it's an object
: [];

const finalPlugins = Array.from(new Set([...scenarioPlugins, ...defaultPlugins]));
logger.info(`Using plugins: ${JSON.stringify(finalPlugins)}`);
// Determine environment provider based on scenario type
Expand Down Expand Up @@ -468,12 +480,12 @@ export const scenario = new Command()
}
await runtime.close();
logger.info('Runtime shutdown complete');
} catch {}
} catch { }
}
if (server && createdServer) {
try {
await shutdownScenarioServer(server, serverPort);
} catch {}
} catch { }
}

// Report final result and exit with appropriate code
Expand Down
25 changes: 23 additions & 2 deletions packages/cli/src/commands/scenario/src/runtime-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ export async function createScenarioAgent(
server: AgentServer,
agentName: string = 'scenario-agent',
pluginNames: string[] = [
'@elizaos/plugin-sql',
// Conditionally select database plugin based on environment
process.env.MYSQL_URL ? '@elizaos/plugin-mysql' : '@elizaos/plugin-sql',
'@elizaos/plugin-openai',
'@elizaos/plugin-bootstrap',
]
Expand All @@ -171,11 +172,31 @@ export async function createScenarioAgent(
console.log(
`🔧 [DEBUG] createScenarioAgent called for agent: ${agentName}, plugins: ${pluginNames.join(', ')}`
);

// Ensure we don't have both plugin-sql and plugin-mysql loaded simultaneously
const hasMysqlPlugin = pluginNames.some(
(p) => p === '@elizaos/plugin-mysql' || p === 'plugin-mysql'
);
const hasSqlPlugin = pluginNames.some(
(p) => p === '@elizaos/plugin-sql' || p === 'plugin-sql'
);

let finalPluginNames = pluginNames;
if (hasMysqlPlugin && hasSqlPlugin) {
// Remove plugin-sql if plugin-mysql is present
finalPluginNames = pluginNames.filter(
(p) => p !== '@elizaos/plugin-sql' && p !== 'plugin-sql'
);
console.log(
`🔧 [DEBUG] Removed plugin-sql because plugin-mysql is present. Using: ${finalPluginNames.join(', ')}`
);
}

const character: Character = {
name: agentName,
id: stringToUuid(agentName),
bio: 'A test agent for scenario execution',
plugins: pluginNames,
plugins: finalPluginNames,
settings: {
// Let ConfigManager populate minimal, file-scoped secrets.
secrets: {},
Expand Down
Loading
Loading