Skip to content

Commit

Permalink
remove junk and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lalalune committed Feb 10, 2025
1 parent 20a7b47 commit e421d93
Show file tree
Hide file tree
Showing 82 changed files with 1,048 additions and 7,158 deletions.
16 changes: 0 additions & 16 deletions .github/workflows/greetings.yml

This file was deleted.

10 changes: 0 additions & 10 deletions .github/workflows/minimal-merge-queue.yml

This file was deleted.

18 changes: 0 additions & 18 deletions .github/workflows/require-develop.yml

This file was deleted.

28 changes: 0 additions & 28 deletions .github/workflows/smoke-tests.yml

This file was deleted.

33 changes: 0 additions & 33 deletions .github/workflows/stale.yml

This file was deleted.

8 changes: 0 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,6 @@ packages/plugin-nvidia-nim/docs
# Edriziai specific ignores
characters/edriziai-info/secrets.json

# Bug Hunter logs and checkpoints
scripts/bug_hunt/logs/
scripts/bug_hunt/logs/*.log
scripts/bug_hunt/checkpoints/
scripts/bug_hunt/checkpoints/*.json
scripts/bug_hunt/reports/
scripts/bug_hunt/reports/*.md

lit-config.json

# Configuration to exclude the extra and local_docs directories
Expand Down
Binary file modified bun.lockb
Binary file not shown.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
"docker:bash": "bash ./scripts/docker.sh bash",
"docker:start": "bash ./scripts/docker.sh start",
"docker": "bun docker:build && bun docker:run && bun docker:bash",
"smokeTests": "bash ./scripts/smokeTests.sh",
"test": "bash ./scripts/integrationTests.sh"
"test-e2e": "turbo run test --filter=@elizaos/agent"
},
"devDependencies": {
"@biomejs/biome": "^1.9.4",
Expand Down
3 changes: 2 additions & 1 deletion packages/agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"scripts": {
"start": "node --loader ts-node/esm src/index.ts",
"dev": "node --loader ts-node/esm src/index.ts",
"check-types": "tsc --noEmit"
"check-types": "tsc --noEmit",
"test": "vitest"
},
"nodemonConfig": {
"watch": [
Expand Down
2 changes: 1 addition & 1 deletion packages/agent/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export function createApiRouter(
return;
}

if (process.env.USE_CHARACTER_STORAGE === "true") {
if (agent.getSetting("USE_CHARACTER_STORAGE") === "true") {
try {
const filename = `${agent.agentId}.json`;
const uploadDir = path.join(
Expand Down
3 changes: 2 additions & 1 deletion packages/agent/src/defaultCharacter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export const defaultCharacter: Character = {
"@elizaos/plugin-openai",
"@elizaos/plugin-discord",
"@elizaos/plugin-node",
"elizaos/plugin-telegram",
"@elizaos/plugin-telegram",
"@elizaos/plugin-twitter",
],
settings: {
secrets: {},
Expand Down
2 changes: 1 addition & 1 deletion packages/agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ async function startAgent(

// initialize cache
const cache = initializeCache(
process.env.CACHE_STORE ?? CacheStore.DATABASE,
runtime.getSetting("CACHE_STORE") ?? CacheStore.DATABASE,
character,
"",
db
Expand Down
149 changes: 149 additions & 0 deletions packages/agent/src/plugins.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
import dotenv from 'dotenv';
dotenv.config({ path: '../../.env' });

import {
AgentRuntime,
CacheManager,
DbCacheAdapter,
logger,
stringToUuid,
TestSuite,
type IAgentRuntime,
type IDatabaseAdapter,
type IDatabaseCacheAdapter
} from "@elizaos/core";
import { afterAll, beforeAll, describe, it } from 'vitest';
import { defaultCharacter } from "./defaultCharacter";

let runtime: IAgentRuntime;
let db: IDatabaseAdapter & IDatabaseCacheAdapter;

// Helper to create a database adapter
async function findDatabaseAdapter(runtime: IAgentRuntime) {
const { adapters } = runtime;
let adapter;

// Default to sqlite if no adapter found
if (adapters.length === 0) {
const sqliteAdapter = await import('@elizaos-plugins/sqlite');
adapter = sqliteAdapter.default.adapters[0];
if (!adapter) {
throw new Error("No database adapter found in default sqlite plugin");
}
} else if (adapters.length === 1) {
adapter = adapters[0];
} else {
throw new Error("Multiple database adapters found. Ensure only one database adapter plugin is loaded.");
}

return adapter.init(runtime);
}

// Initialize the runtime with default character
beforeAll(async () => {
try {
// Setup character
const character = { ...defaultCharacter };
character.id = stringToUuid(character.name);
character.username = character.name;

// Create runtime
runtime = new AgentRuntime({
character,
fetch: async (url: string, options: any) => {
logger.debug(`Test fetch: ${url}`);
return fetch(url, options);
}
});

// Initialize database
db = await findDatabaseAdapter(runtime);
runtime.databaseAdapter = db;

// Initialize cache
const cache = new CacheManager(new DbCacheAdapter(db, character.id));
runtime.cacheManager = cache;

// Initialize runtime (loads plugins, etc)
await runtime.initialize();

logger.info(`Test runtime initialized for ${character.name}`);
} catch (error) {
logger.error("Failed to initialize test runtime:", error);
throw error;
}
});

// Cleanup after all tests
afterAll(async () => {
try {
if (runtime) {
// await runtime.shutdown();
}
if (db) {
await db.close();
}
} catch (error) {
logger.error("Error during cleanup:", error);
throw error;
}
});

// Main test suite that runs all plugin tests
describe('Plugin Tests', async () => {
it('should run all plugin tests', async () => {
const plugins = runtime.plugins;

// Track test statistics
const stats = {
total: 0,
passed: 0,
failed: 0,
skipped: 0
};

// Run tests for each plugin
for (const plugin of plugins) {
if (typeof plugin.tests !== 'function') {
logger.info(`Plugin ${plugin.name} has no tests`);
continue;
}

try {
logger.info(`Running tests for plugin: ${plugin.name}`);
const tests = plugin.tests;
const suites = (Array.isArray(tests) ? tests : [tests]) as TestSuite[];

for (const suite of suites) {
logger.info(`\nTest suite: ${suite.name}`);
for (const test of suite.tests) {
stats.total++;
const startTime = performance.now();

try {
await test.fn();
stats.passed++;
const duration = performance.now() - startTime;
logger.info(`✓ ${test.name} (${Math.round(duration)}ms)`);
} catch (error) {
stats.failed++;
logger.error(`✗ ${test.name}`);
logger.error(error);
throw error;
}
}
}
} catch (error) {
logger.error(`Error in plugin ${plugin.name}:`, error);
throw error;
}
}

// Log final statistics
logger.info('\nTest Summary:');
logger.info(`Total: ${stats.total}`);
logger.info(`Passed: ${stats.passed}`);
logger.info(`Failed: ${stats.failed}`);
logger.info(`Skipped: ${stats.skipped}`);
});
});
Loading

0 comments on commit e421d93

Please sign in to comment.