426e9eeabd
Voice Workbench / headless workbench (mocked backends) (push) Has been cancelled
Voice Workbench / real acoustic lane (nightly, provisioned only) (push) Has been cancelled
ci / test (push) Has been cancelled
ci / lint-and-format (push) Has been cancelled
ci / build (push) Has been cancelled
ci / dev-startup (push) Has been cancelled
gitleaks / gitleaks (push) Has been cancelled
Markdown Links / Relative Markdown Links (push) Has been cancelled
Quality (Extended) / Homepage Build (PR smoke) (push) Has been cancelled
Quality (Extended) / Comment-only diff guard (push) Has been cancelled
Quality (Extended) / Format + Type Safety Ratchet (push) Has been cancelled
Quality (Extended) / Develop Gate (secret scan + UI determinism) (push) Has been cancelled
Quality (Extended) / Develop Gate (lint) (push) Has been cancelled
Chat shell gestures / Chat shell gesture + parity e2e (push) Has been cancelled
Cloud Gateway Discord / Test (push) Has been cancelled
Benchmark Bridge Tests / benchmark (bunx @biomejs/biome check packages/lifeops-bench/src, benchmark-lint) (push) Has been cancelled
Benchmark Bridge Tests / benchmark (bunx vitest run --config packages/lifeops-bench/vitest.config.ts --root packages/lifeops-bench --passWithNoTests, benchmark-tests) (push) Has been cancelled
Build Agent Image / build-and-push (push) Has been cancelled
Dev Smoke / bun run dev onboarding chat (push) Has been cancelled
Dev Smoke / Vite HMR dependency-level smoke (push) Has been cancelled
Electrobun Submodule Guard / electrobun gitlink is fetchable (push) Has been cancelled
Publish @elizaos/example-code / check_npm (push) Has been cancelled
Publish @elizaos/example-code / publish_npm (push) Has been cancelled
Publish @elizaos/plugin-elizacloud / verify_version (push) Has been cancelled
Publish @elizaos/plugin-elizacloud / publish_npm (push) Has been cancelled
Sandbox Live Smoke / Sandbox live smoke (push) Has been cancelled
Snap Build & Test / Build Snap (amd64) (push) Has been cancelled
Snap Build & Test / Build Snap (arm64) (push) Has been cancelled
Test Packaging / elizaos CLI global-install smoke (node + bun) (push) Has been cancelled
Cloud Gateway Webhook / Test (push) Has been cancelled
Cloud Tests / lint-and-types (push) Has been cancelled
Cloud Tests / unit-tests (push) Has been cancelled
Cloud Tests / integration-tests (push) Has been cancelled
Cloud Tests / e2e-tests (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
Deploy Apps Worker (Product 2) / Determine environment (push) Has been cancelled
Deploy Apps Worker (Product 2) / Deploy apps worker to apps-control host (${{ needs.determine-env.outputs.environment }}) (push) Has been cancelled
Deploy Eliza Provisioning Worker / Determine environment (push) Has been cancelled
Deploy Eliza Provisioning Worker / Deploy worker to Hetzner host (${{ needs.determine-env.outputs.environment }} @ ${{ needs.determine-env.outputs.deployment_sha }}) (push) Has been cancelled
Dev Smoke / Classify changed paths (push) Has been cancelled
supply-chain / sbom (push) Has been cancelled
supply-chain / vulnerability-scan (push) Has been cancelled
Build, Push & Deploy to Phala Cloud / build-and-push (push) Has been cancelled
Test Packaging / Validate Packaging Configs (push) Has been cancelled
Test Packaging / Build & Test PyPI Package (push) Has been cancelled
Test Packaging / PyPI on Python ${{ matrix.python }} (push) Has been cancelled
Test Packaging / Pack & Test JS Tarballs (push) Has been cancelled
UI Fixture E2E / ui-fixture-e2e (push) Has been cancelled
UI Fixture E2E / fixture-e2e (push) Has been cancelled
UI Story Gate / story-gate (push) Has been cancelled
vault-ci / test (macos-latest) (push) Has been cancelled
vault-ci / test (ubuntu-latest) (push) Has been cancelled
vault-ci / test (windows-latest) (push) Has been cancelled
vault-ci / app-core wiring tests (push) Has been cancelled
verify-patches / verify patches/CHECKSUMS.sha256 (push) Has been cancelled
Voice Benchmark Smoke / voice-emotion fixture smoke (push) Has been cancelled
Voice Benchmark Smoke / voiceagentbench fixture smoke (push) Has been cancelled
Voice Benchmark Smoke / voicebench-quality unit smoke (push) Has been cancelled
Voice Benchmark Smoke / voicebench TypeScript unit (no audio) (push) Has been cancelled
Voice Benchmark Smoke / voice bench smoke summary (push) Has been cancelled
Windows CI / windows ([bun run --cwd packages/app-core test bun run --cwd packages/elizaos test bun run --cwd packages/cloud/shared test], app-and-cli) (push) Has been cancelled
Windows CI / windows ([bun run --cwd packages/scenario-runner test bun run --cwd packages/vault test bun run --cwd packages/security test bun run --cwd plugins/plugin-coding-tools test], framework-packages) (push) Has been cancelled
Windows CI / windows ([bun run --cwd plugins/plugin-elizacloud test bun run --cwd plugins/plugin-discord test bun run --cwd plugins/plugin-anthropic test bun run --cwd plugins/plugin-openai test bun run --cwd plugins/plugin-app-control test bun run --cwd plugins/pl… (push) Has been cancelled
Windows CI / windows ([node packages/scripts/run-turbo.mjs run build --filter=@elizaos/core --filter=@elizaos/shared --filter=@elizaos/agent --concurrency=4 node packages/scripts/run-bash-linux-only.mjs scripts/verify-riscv64-buildpaths.sh node packages/scripts/run… (push) Has been cancelled
Windows CI / windows ([node packages/scripts/run-turbo.mjs run typecheck --filter=@elizaos/core --filter=@elizaos/shared --filter=@elizaos/cloud-shared --concurrency=4 bun run --cwd packages/core test bun run --cwd packages/shared test], core-runtime, 75) (push) Has been cancelled
258 lines
8.5 KiB
TypeScript
258 lines
8.5 KiB
TypeScript
/**
|
|
* End-to-end simulation of how `RuntimeMigrator` behaves across the real
|
|
* multi-plugin boot sequence — separate migrator instances per plugin (as
|
|
* each plugin's `init` would create), a simulated app restart, and a single
|
|
* migrator shared across plugins — asserting migrations stay idempotent and
|
|
* both plugin schemas (`@elizaos/plugin-sql`, `polymarket`) coexist. Runs
|
|
* against a real Postgres/PGlite database via `createIsolatedTestDatabaseForMigration`.
|
|
*/
|
|
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
|
|
|
interface MigrationRow {
|
|
plugin_name: string;
|
|
hash: string;
|
|
created_at: string | Date;
|
|
[key: string]: unknown;
|
|
}
|
|
|
|
interface SnapshotRow {
|
|
plugin_name: string;
|
|
count: string | number;
|
|
[key: string]: unknown;
|
|
}
|
|
|
|
interface SchemaRow {
|
|
schema_name: string;
|
|
[key: string]: unknown;
|
|
}
|
|
|
|
interface TablesPerSchemaRow {
|
|
schemaname: string;
|
|
table_count: string | number;
|
|
[key: string]: unknown;
|
|
}
|
|
|
|
interface TableRow {
|
|
tablename: string;
|
|
[key: string]: unknown;
|
|
}
|
|
|
|
interface SchemaExistsRow {
|
|
public_exists: boolean;
|
|
polymarket_exists: boolean;
|
|
[key: string]: unknown;
|
|
}
|
|
|
|
import { sql } from "drizzle-orm";
|
|
import { RuntimeMigrator } from "../../runtime-migrator";
|
|
import * as coreSchema from "../../schema";
|
|
import type { DrizzleDatabase } from "../../types";
|
|
import { testPolymarketSchema } from "../schema-data/test-plugin-schema";
|
|
import { createIsolatedTestDatabaseForMigration } from "../test-helpers";
|
|
|
|
describe("Actual Runtime Scenario - Plugin Loading Simulation", () => {
|
|
let db: DrizzleDatabase;
|
|
let cleanup: () => Promise<void>;
|
|
|
|
beforeAll(async () => {
|
|
console.log("\n🚀 Simulating actual runtime plugin loading scenario...\n");
|
|
|
|
const testSetup = await createIsolatedTestDatabaseForMigration("actual_runtime");
|
|
cleanup = testSetup.cleanup;
|
|
db = testSetup.db;
|
|
});
|
|
|
|
afterAll(async () => {
|
|
if (cleanup) {
|
|
await cleanup();
|
|
}
|
|
});
|
|
|
|
it("should handle plugin migrations as they would be loaded at runtime", async () => {
|
|
console.log("=".repeat(80));
|
|
console.log("SCENARIO: Application Startup");
|
|
console.log("=".repeat(80));
|
|
|
|
console.log("\n📦 Step 1: Loading plugin-sql (database adapter)...");
|
|
|
|
const sqlPluginMigrator = new RuntimeMigrator(db);
|
|
await sqlPluginMigrator.initialize();
|
|
|
|
await sqlPluginMigrator.migrate("@elizaos/plugin-sql", coreSchema, {
|
|
verbose: false,
|
|
});
|
|
|
|
console.log("✅ plugin-sql loaded and migrated");
|
|
|
|
const afterSqlPlugin = await db.execute(sql`
|
|
SELECT plugin_name, hash, created_at
|
|
FROM migrations._migrations
|
|
ORDER BY created_at ASC
|
|
`);
|
|
console.log(`\n📊 Migrations after plugin-sql: ${afterSqlPlugin.rows.length}`);
|
|
for (const m of afterSqlPlugin.rows as MigrationRow[]) {
|
|
console.log(` - ${m.plugin_name}`);
|
|
}
|
|
|
|
console.log("\n📦 Step 2: Loading polymarket plugin...");
|
|
|
|
console.log("\n--- Testing Scenario A: Polymarket creates its own migrator ---");
|
|
const polymarketMigrator = new RuntimeMigrator(db);
|
|
// initialize() is idempotent: it detects the existing migration tables.
|
|
await polymarketMigrator.initialize();
|
|
|
|
await polymarketMigrator.migrate("polymarket", testPolymarketSchema, {
|
|
verbose: false,
|
|
});
|
|
|
|
console.log("✅ polymarket loaded and migrated (own migrator)");
|
|
|
|
const afterPolymarket = await db.execute(sql`
|
|
SELECT plugin_name, hash, created_at
|
|
FROM migrations._migrations
|
|
ORDER BY created_at ASC
|
|
`);
|
|
console.log(`\n📊 Migrations after polymarket: ${afterPolymarket.rows.length}`);
|
|
for (const m of afterPolymarket.rows as MigrationRow[]) {
|
|
console.log(` - ${m.plugin_name}`);
|
|
}
|
|
|
|
expect(afterPolymarket.rows.length).toBe(2);
|
|
|
|
console.log(`\n${"=".repeat(80)}`);
|
|
console.log("SCENARIO: Application Restart");
|
|
console.log("=".repeat(80));
|
|
|
|
console.log("\n🔄 Simulating application restart...");
|
|
|
|
// New migrator instances, as each plugin's init would create on restart.
|
|
const sqlPluginMigrator2 = new RuntimeMigrator(db);
|
|
await sqlPluginMigrator2.initialize();
|
|
|
|
await sqlPluginMigrator2.migrate("@elizaos/plugin-sql", coreSchema, {
|
|
verbose: false,
|
|
});
|
|
|
|
const polymarketMigrator2 = new RuntimeMigrator(db);
|
|
await polymarketMigrator2.initialize();
|
|
|
|
await polymarketMigrator2.migrate("polymarket", testPolymarketSchema, {
|
|
verbose: false,
|
|
});
|
|
|
|
// Re-migrating on restart must stay idempotent: still exactly 2 rows.
|
|
const afterRestart = await db.execute(sql`
|
|
SELECT plugin_name, hash, created_at
|
|
FROM migrations._migrations
|
|
ORDER BY created_at ASC
|
|
`);
|
|
console.log(`\n📊 Migrations after restart: ${afterRestart.rows.length}`);
|
|
expect(afterRestart.rows.length).toBe(2);
|
|
|
|
console.log(`\n${"=".repeat(80)}`);
|
|
console.log("DIAGNOSTICS");
|
|
console.log("=".repeat(80));
|
|
|
|
console.log("\n🔍 Checking snapshots:");
|
|
const snapshots = await db.execute(sql`
|
|
SELECT plugin_name, COUNT(*) as count
|
|
FROM migrations._snapshots
|
|
GROUP BY plugin_name
|
|
`);
|
|
for (const s of snapshots.rows as SnapshotRow[]) {
|
|
console.log(` - ${s.plugin_name}: ${s.count} snapshots`);
|
|
}
|
|
|
|
console.log("\n🔍 Checking schemas:");
|
|
const schemas = await db.execute(sql`
|
|
SELECT schema_name
|
|
FROM information_schema.schemata
|
|
WHERE schema_name NOT IN ('pg_catalog', 'information_schema', 'pg_toast')
|
|
ORDER BY schema_name
|
|
`);
|
|
console.log("Schemas:", schemas.rows.map((r: SchemaRow) => r.schema_name).join(", "));
|
|
|
|
console.log("\n🔍 Tables per schema:");
|
|
const tablesPerSchema = await db.execute(sql`
|
|
SELECT schemaname, COUNT(*) as table_count
|
|
FROM pg_tables
|
|
WHERE schemaname NOT IN ('pg_catalog', 'information_schema', 'pg_toast')
|
|
GROUP BY schemaname
|
|
ORDER BY schemaname
|
|
`);
|
|
for (const t of tablesPerSchema.rows as TablesPerSchemaRow[]) {
|
|
console.log(` - ${t.schemaname}: ${t.table_count} tables`);
|
|
}
|
|
});
|
|
|
|
it("should test shared migrator scenario", async () => {
|
|
console.log(`\n${"=".repeat(80)}`);
|
|
console.log("SCENARIO: Shared Migrator Instance");
|
|
console.log("=".repeat(80));
|
|
|
|
console.log("\n🧹 Cleaning up database from previous test...");
|
|
|
|
await db.execute(sql`DROP SCHEMA IF EXISTS polymarket CASCADE`);
|
|
|
|
// Migration tables (`migrations` schema) are dropped separately below.
|
|
const tables = await db.execute(sql`
|
|
SELECT tablename FROM pg_tables
|
|
WHERE schemaname = 'public'
|
|
AND tablename NOT LIKE 'spatial_ref_sys'
|
|
AND tablename NOT LIKE 'geography_columns'
|
|
AND tablename NOT LIKE 'geometry_columns'
|
|
AND tablename NOT LIKE 'raster_columns'
|
|
AND tablename NOT LIKE 'raster_overviews'
|
|
`);
|
|
|
|
for (const table of tables.rows as TableRow[]) {
|
|
await db.execute(sql.raw(`DROP TABLE IF EXISTS public."${table.tablename}" CASCADE`));
|
|
}
|
|
|
|
// Dropped entirely; `initialize()` below recreates it.
|
|
await db.execute(sql`DROP SCHEMA IF EXISTS migrations CASCADE`);
|
|
|
|
console.log("\n🔄 Testing with shared migrator instance...");
|
|
|
|
const sharedMigrator = new RuntimeMigrator(db);
|
|
await sharedMigrator.initialize();
|
|
|
|
console.log("\n📦 plugin-sql using shared migrator...");
|
|
await sharedMigrator.migrate("@elizaos/plugin-sql", coreSchema, {
|
|
verbose: false,
|
|
});
|
|
|
|
console.log("📦 polymarket using shared migrator...");
|
|
await sharedMigrator.migrate("polymarket", testPolymarketSchema, {
|
|
verbose: false,
|
|
});
|
|
|
|
const finalMigrations = await db.execute(sql`
|
|
SELECT plugin_name, hash, created_at
|
|
FROM migrations._migrations
|
|
ORDER BY created_at ASC
|
|
`);
|
|
|
|
console.log(`\n📊 Final migrations with shared migrator: ${finalMigrations.rows.length}`);
|
|
for (const m of finalMigrations.rows as MigrationRow[]) {
|
|
console.log(` - ${m.plugin_name}`);
|
|
}
|
|
|
|
expect(finalMigrations.rows.length).toBe(2);
|
|
|
|
const schemasExist = await db.execute(sql`
|
|
SELECT
|
|
EXISTS (SELECT 1 FROM information_schema.schemata WHERE schema_name = 'public') as public_exists,
|
|
EXISTS (SELECT 1 FROM information_schema.schemata WHERE schema_name = 'polymarket') as polymarket_exists
|
|
`);
|
|
|
|
const result = schemasExist.rows[0] as SchemaExistsRow;
|
|
console.log("\n✅ Schema verification:");
|
|
console.log(` - public schema: ${result.public_exists ? "exists" : "missing"}`);
|
|
console.log(` - polymarket schema: ${result.polymarket_exists ? "exists" : "missing"}`);
|
|
|
|
expect(result.public_exists).toBe(true);
|
|
expect(result.polymarket_exists).toBe(true);
|
|
});
|
|
});
|