-
Notifications
You must be signed in to change notification settings - Fork 5.4k
fix: plugin-mysql support, initPromise and other minor fixes #6143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
odilitime
wants to merge
28
commits into
develop
Choose a base branch
from
spartan-prod
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,292
−404
Open
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
32c190d
add/expose initPromise
odilitime 8cdd3f0
update loggeer, add initPromise & hasElizaOS()
odilitime 6237f0f
better mysql detection/support
odilitime 5514e50
scenario mysql support
odilitime 6478827
new tests
odilitime 8b50109
jest => mock
odilitime 6af60f4
better mysql support
odilitime 52245ca
new mysql utils
odilitime b7e9fe4
use new mysql utils, refactor init so they're similar, security note
odilitime 620ad94
match initPromise behavior better
odilitime a214829
better mysql support/detection
odilitime f89b4ad
new test
odilitime 924175e
throw if cli didnt provide any db plugins
odilitime 96c2b1d
lower debug
odilitime 12952bb
make database configurable
odilitime c762525
use ENV to drive adapter selection
odilitime 2fc676d
ensure world
odilitime 7d22f51
Merge branch 'develop' into spartan-prod
standujar 0460612
Merge branch 'develop' into spartan-prod
wtfsayo ab0728b
Detect MySQL usage from plugin name instead of env var
wtfsayo 04fbb20
Merge develop into spartan-prod
wtfsayo efe1536
Fix property name and formatting in AgentRuntime
wtfsayo 7fdcafa
Refactor plugin registration and improve test mocks
wtfsayo 47c78e4
Merge branch 'develop' into spartan-prod
wtfsayo 90984f5
fix(core): resolve initPromise after world/room creation completes
wtfsayo a406e55
Merge remote-tracking branch 'origin/develop' into spartan-prod
wtfsayo ca4ae47
chore: merge develop into spartan-prod
wtfsayo f4e1d41
Add tests for plugin adapter registration order
wtfsayo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
221 changes: 221 additions & 0 deletions
221
packages/cli/src/commands/scenario/__tests__/plugin-selection.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| }); | ||
| }); | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.