From 46062f04950f42854025b651e8311e887a78ef03 Mon Sep 17 00:00:00 2001 From: ai16z-demirix Date: Thu, 30 Jan 2025 22:25:35 +0100 Subject: [PATCH 01/16] plugin-bootstrap: package json --- packages/plugin-bootstrap/package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/plugin-bootstrap/package.json b/packages/plugin-bootstrap/package.json index a952d27a92b..90881289790 100644 --- a/packages/plugin-bootstrap/package.json +++ b/packages/plugin-bootstrap/package.json @@ -24,7 +24,8 @@ }, "scripts": { "build": "tsup --format esm --dts", - "dev": "tsup --format esm --dts --watch" + "dev": "tsup --format esm --dts --watch", + "test": "vitest run" }, "peerDependencies": { "whatwg-url": "7.1.0" From b407f925c68e470a0958aee3e6bbe1d79f05560d Mon Sep 17 00:00:00 2001 From: ai16z-demirix Date: Thu, 30 Jan 2025 22:25:47 +0100 Subject: [PATCH 02/16] plugin-bootstrap: vitest config --- packages/plugin-bootstrap/vitest.config.ts | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 packages/plugin-bootstrap/vitest.config.ts diff --git a/packages/plugin-bootstrap/vitest.config.ts b/packages/plugin-bootstrap/vitest.config.ts new file mode 100644 index 00000000000..adbf7255380 --- /dev/null +++ b/packages/plugin-bootstrap/vitest.config.ts @@ -0,0 +1,8 @@ +import { defineConfig } from 'vitest/config'; + +export default defineConfig({ + test: { + globals: true, + environment: 'node', + }, +}); From 3450d1f8938f6466cbf2aab64f4b4dd42fd46656 Mon Sep 17 00:00:00 2001 From: ai16z-demirix Date: Thu, 30 Jan 2025 22:37:30 +0100 Subject: [PATCH 03/16] plugin-bootstrap: continue tests --- .../__tests__/actions/continue.test.ts | 218 ++++++++++++++++++ 1 file changed, 218 insertions(+) create mode 100644 packages/plugin-bootstrap/__tests__/actions/continue.test.ts diff --git a/packages/plugin-bootstrap/__tests__/actions/continue.test.ts b/packages/plugin-bootstrap/__tests__/actions/continue.test.ts new file mode 100644 index 00000000000..b8c4e2ffb44 --- /dev/null +++ b/packages/plugin-bootstrap/__tests__/actions/continue.test.ts @@ -0,0 +1,218 @@ +import { describe, expect, it, vi, beforeEach } from 'vitest'; +import { continueAction } from '../../src/actions/continue'; +import { composeContext, generateMessageResponse, generateTrueOrFalse, ModelClass } from '@elizaos/core'; + +vi.mock('@elizaos/core', () => ({ + composeContext: vi.fn(), + generateMessageResponse: vi.fn(), + generateTrueOrFalse: vi.fn(), + elizaLogger: { + info: vi.fn(), + error: vi.fn(), + debug: vi.fn(), + log: vi.fn() + }, + messageCompletionFooter: '\nResponse format:\n```\n{"content": {"text": string}}\n```', + booleanFooter: '\nResponse format: YES or NO', + ModelClass: { + SMALL: 'small', + LARGE: 'large' + } +})); + +describe('continueAction', () => { + let mockRuntime; + let mockMessage; + let mockState; + let mockCallback; + + beforeEach(() => { + mockRuntime = { + character: { + settings: {}, + name: 'TestBot', + bio: 'A test bot', + lore: 'Test lore', + knowledge: 'Test knowledge', + templates: { + messageHandlerTemplate: 'Test template {{agentName}}' + } + }, + messageManager: { + getLastMessageInRoom: vi.fn().mockResolvedValue({ + userId: 'test-user', + content: { text: 'Hello' } + }), + getMemories: vi.fn().mockResolvedValue([{ + userId: 'test-agent', + content: { + text: 'Previous bot message', + action: 'CONTINUE' + } + }]) + }, + composeState: vi.fn().mockResolvedValue({ + agentId: 'test-agent', + roomId: 'test-room' + }), + updateRecentMessageState: vi.fn().mockImplementation(state => Promise.resolve({ + ...state, + recentMessagesData: [{ + userId: 'test-agent', + content: { + text: 'Previous bot message', + action: 'CONTINUE' + } + }] + })), + agentId: 'test-agent', + databaseAdapter: { + log: vi.fn().mockResolvedValue(true) + } + }; + + mockMessage = { + id: 'test-message-1', + content: { + text: 'Hello, how are you' // No question mark to avoid early return + }, + roomId: 'test-room', + userId: 'test-user', + createdAt: Date.now() + }; + + mockState = { + agentId: 'test-agent', + roomId: 'test-room', + recentMessagesData: [{ + id: 'test-message-2', + userId: 'test-agent', + content: { + text: 'Previous bot message', + action: 'NONE', + inReplyTo: 'different-message-id' // Different ID to avoid early return + }, + createdAt: Date.now() - 1000 + }] + }; + + mockCallback = vi.fn(); + + // Reset all mocks + vi.clearAllMocks(); + }); + + describe('validation', () => { + it('should validate successfully when conditions are met', async () => { + mockRuntime.messageManager.getMemories.mockResolvedValueOnce([{ + userId: 'test-agent', + content: { + text: 'Previous bot message', + action: 'NONE' + } + }]); + + const result = await continueAction.validate(mockRuntime, mockMessage); + expect(result).toBe(true); + }); + + it('should fail validation when too many continues in a row', async () => { + mockRuntime.messageManager.getMemories.mockResolvedValueOnce([ + { + userId: 'test-agent', + content: { + text: 'Message 1', + action: 'CONTINUE' + } + }, + { + userId: 'test-agent', + content: { + text: 'Message 2', + action: 'CONTINUE' + } + }, + { + userId: 'test-agent', + content: { + text: 'Message 3', + action: 'CONTINUE' + } + } + ]); + + const result = await continueAction.validate(mockRuntime, mockMessage); + expect(result).toBe(false); + }); + }); + + describe('action properties', () => { + it('should have correct action properties', () => { + expect(continueAction.name).toBe('CONTINUE'); + expect(continueAction.description).toBeDefined(); + expect(continueAction.examples).toBeDefined(); + expect(Array.isArray(continueAction.examples)).toBe(true); + }); + + it('should have valid examples', () => { + continueAction.examples.forEach(example => { + expect(Array.isArray(example)).toBe(true); + example.forEach(interaction => { + expect(interaction).toHaveProperty('user'); + expect(interaction).toHaveProperty('content'); + }); + }); + }); + }); + + describe('message generation', () => { + it('should generate continuation message', async () => { + const mockResponse = { + content: { + text: 'This is a continuation message', + action: 'CONTINUE', + inReplyTo: 'test-message-1' + } + }; + + const mockStateWithContext = { + ...mockState, + actionExamples: [], + bio: mockRuntime.character.bio, + lore: mockRuntime.character.lore, + knowledge: mockRuntime.character.knowledge, + agentName: mockRuntime.character.name, + messageDirections: 'Test directions', + recentMessages: 'Test recent messages', + actions: 'Test actions', + providers: [], + attachments: [] + }; + + mockRuntime.messageManager.getMemories.mockResolvedValueOnce([{ + id: 'test-message-2', + userId: 'test-agent', + content: { + text: 'Previous bot message', + action: 'NONE', + inReplyTo: 'different-message-id' + }, + createdAt: Date.now() - 1000 + }]); + + mockRuntime.updateRecentMessageState.mockResolvedValueOnce(mockStateWithContext); + + vi.mocked(composeContext).mockReturnValue('mock-context'); + vi.mocked(generateTrueOrFalse).mockResolvedValue(true); + vi.mocked(generateMessageResponse).mockResolvedValue(mockResponse); + + await continueAction.handler(mockRuntime, mockMessage, mockStateWithContext, {}, mockCallback); + + expect(composeContext).toHaveBeenCalled(); + expect(generateTrueOrFalse).toHaveBeenCalled(); + expect(generateMessageResponse).toHaveBeenCalled(); + expect(mockCallback).toHaveBeenCalledWith(mockResponse); + expect(mockRuntime.databaseAdapter.log).toHaveBeenCalled(); + }); + }); +}); From df5590bfeb432d866e48463e0bdc9ccb97e86a3e Mon Sep 17 00:00:00 2001 From: ai16z-demirix Date: Thu, 30 Jan 2025 22:37:48 +0100 Subject: [PATCH 04/16] plugin-bootstrap: fact tests --- .../__tests__/evaluators/fact.test.ts | 113 ++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 packages/plugin-bootstrap/__tests__/evaluators/fact.test.ts diff --git a/packages/plugin-bootstrap/__tests__/evaluators/fact.test.ts b/packages/plugin-bootstrap/__tests__/evaluators/fact.test.ts new file mode 100644 index 00000000000..ad4cbeb3710 --- /dev/null +++ b/packages/plugin-bootstrap/__tests__/evaluators/fact.test.ts @@ -0,0 +1,113 @@ +import { describe, expect, it, vi, beforeEach } from 'vitest'; +import { factEvaluator } from '../../src/evaluators/fact'; +import { composeContext, generateObjectArray, MemoryManager } from '@elizaos/core'; + +vi.mock('@elizaos/core', () => ({ + composeContext: vi.fn(), + generateObjectArray: vi.fn(), + MemoryManager: vi.fn().mockImplementation((config: any) => ({ + getMemoriesByEvaluator: vi.fn().mockResolvedValue([]), + addMemory: vi.fn().mockResolvedValue(true), + addEmbeddingToMemory: vi.fn().mockResolvedValue({ + id: 'test-memory-id', + content: { + text: 'Test memory content' + } + }), + createMemory: vi.fn().mockResolvedValue({ + id: 'test-memory-id', + content: { + text: 'Test memory content' + } + }) + })), + ModelClass: { + SMALL: 'small' + } +})); + +describe('factEvaluator', () => { + let mockRuntime; + let mockMessage; + + beforeEach(() => { + mockRuntime = { + character: { + settings: {} + }, + messageManager: { + countMemories: vi.fn().mockResolvedValue(5) + }, + composeState: vi.fn().mockResolvedValue({ + agentId: 'test-agent', + roomId: 'test-room' + }), + getConversationLength: vi.fn().mockReturnValue(10) + }; + + mockMessage = { + content: { + text: 'I live in New York and work as a software engineer.' + }, + roomId: 'test-room' + }; + + // Reset all mocks + vi.clearAllMocks(); + }); + + describe('validation', () => { + it('should validate successfully', async () => { + const result = await factEvaluator.validate(mockRuntime, mockMessage); + expect(result).toBe(true); + expect(mockRuntime.messageManager.countMemories).toHaveBeenCalledWith('test-room'); + expect(mockRuntime.getConversationLength).toHaveBeenCalled(); + }); + }); + + describe('evaluator properties', () => { + it('should have correct evaluator properties', () => { + expect(factEvaluator.name).toBe('GET_FACTS'); + expect(factEvaluator.similes).toContain('GET_CLAIMS'); + expect(factEvaluator.description).toBeDefined(); + expect(factEvaluator.description).toContain('Extract factual information'); + expect(factEvaluator.examples).toBeDefined(); + expect(Array.isArray(factEvaluator.examples)).toBe(true); + }); + + it('should have valid examples', () => { + factEvaluator.examples.forEach(example => { + expect(example).toBeDefined(); + // Add more specific example validations based on the example structure + }); + }); + }); + + describe('fact extraction', () => { + it('should handle fact extraction', async () => { + const mockFacts = [ + { + claim: 'User lives in New York', + type: 'fact', + in_bio: false, + already_known: false + }, + { + claim: 'User works as a software engineer', + type: 'fact', + in_bio: false, + already_known: false + } + ]; + + vi.mocked(composeContext).mockReturnValue('mock-context'); + vi.mocked(generateObjectArray).mockResolvedValue(mockFacts); + + const result = await factEvaluator.handler(mockRuntime, mockMessage); + + expect(composeContext).toHaveBeenCalled(); + expect(generateObjectArray).toHaveBeenCalled(); + expect(result).toBeDefined(); + }); + }); +}); From 19bce8107ba95910433f21b66a1c0d951db6647f Mon Sep 17 00:00:00 2001 From: ai16z-demirix Date: Thu, 30 Jan 2025 22:38:11 +0100 Subject: [PATCH 05/16] plugin-bootstrap: goal tests --- .../__tests__/evaluators/goal.test.ts | 140 ++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 packages/plugin-bootstrap/__tests__/evaluators/goal.test.ts diff --git a/packages/plugin-bootstrap/__tests__/evaluators/goal.test.ts b/packages/plugin-bootstrap/__tests__/evaluators/goal.test.ts new file mode 100644 index 00000000000..39cbe23fa55 --- /dev/null +++ b/packages/plugin-bootstrap/__tests__/evaluators/goal.test.ts @@ -0,0 +1,140 @@ +import { describe, expect, it, vi, beforeEach } from 'vitest'; +import { goalEvaluator } from '../../src/evaluators/goal'; +import { composeContext, generateText, getGoals, parseJsonArrayFromText } from '@elizaos/core'; + +vi.mock('@elizaos/core', () => ({ + composeContext: vi.fn(), + generateText: vi.fn(), + getGoals: vi.fn(), + parseJsonArrayFromText: vi.fn(), + ModelClass: { + SMALL: 'small' + } +})); + +describe('goalEvaluator', () => { + let mockRuntime; + let mockMessage; + + beforeEach(() => { + mockRuntime = { + character: { + settings: {} + }, + messageManager: { + countMemories: vi.fn().mockResolvedValue(5) + }, + composeState: vi.fn().mockResolvedValue({ + agentId: 'test-agent', + roomId: 'test-room', + goals: [{ id: 'test-goal', name: 'Test Goal' }] + }), + getConversationLength: vi.fn().mockReturnValue(10), + databaseAdapter: { + updateGoal: vi.fn().mockResolvedValue(true) + } + }; + + mockMessage = { + content: { + text: 'I have completed the project documentation.' + }, + roomId: 'test-room' + }; + + // Reset all mocks + vi.clearAllMocks(); + }); + + describe('validation', () => { + it('should validate successfully', async () => { + // Mock the getGoals function to return an active goal + vi.mocked(getGoals).mockImplementation(async ({ runtime, roomId, onlyInProgress }) => { + expect(runtime).toBe(mockRuntime); + expect(roomId).toBe('test-room'); + expect(onlyInProgress).toBe(true); + return [{ id: 'test-goal', name: 'Test Goal', status: 'IN_PROGRESS' }]; + }); + + const result = await goalEvaluator.validate(mockRuntime, mockMessage); + expect(result).toBe(true); + expect(getGoals).toHaveBeenCalledWith({ + runtime: mockRuntime, + count: 1, + onlyInProgress: true, + roomId: 'test-room' + }); + }); + }); + + describe('evaluator properties', () => { + it('should have correct evaluator properties', () => { + expect(goalEvaluator.name).toBe('UPDATE_GOAL'); + expect(goalEvaluator.similes).toContain('UPDATE_GOALS'); + expect(goalEvaluator.description).toBeDefined(); + expect(goalEvaluator.description).toContain('Analyze the conversation'); + expect(goalEvaluator.examples).toBeDefined(); + expect(Array.isArray(goalEvaluator.examples)).toBe(true); + }); + + it('should have valid examples', () => { + goalEvaluator.examples.forEach(example => { + expect(example).toBeDefined(); + // Add more specific example validations based on the example structure + }); + }); + }); + + describe('goal updates', () => { + it('should handle goal updates', async () => { + const mockGoals = [ + { + id: 'goal-1', + name: 'Complete Project Documentation', + status: 'IN_PROGRESS', + objectives: [ + { + description: 'Write project overview', + completed: true + }, + { + description: 'Document API endpoints', + completed: false + } + ] + } + ]; + + const mockUpdatedGoals = [ + { + id: 'goal-1', + status: 'DONE', + objectives: [ + { + description: 'Write project overview', + completed: true + }, + { + description: 'Document API endpoints', + completed: true + } + ] + } + ]; + + vi.mocked(composeContext).mockReturnValue('mock-context'); + vi.mocked(getGoals).mockResolvedValue(mockGoals); + vi.mocked(generateText).mockResolvedValue(JSON.stringify(mockUpdatedGoals)); + vi.mocked(parseJsonArrayFromText).mockReturnValue(mockUpdatedGoals); + + const result = await goalEvaluator.handler(mockRuntime, mockMessage); + + expect(composeContext).toHaveBeenCalled(); + expect(getGoals).toHaveBeenCalled(); + expect(generateText).toHaveBeenCalled(); + expect(parseJsonArrayFromText).toHaveBeenCalled(); + expect(mockRuntime.databaseAdapter.updateGoal).toHaveBeenCalled(); + expect(result).toBeDefined(); + }); + }); +}); From 7aaeb001c557c956ea821274642b1c262a2e8521 Mon Sep 17 00:00:00 2001 From: ai16z-demirix Date: Thu, 30 Jan 2025 22:54:15 +0100 Subject: [PATCH 06/16] plugin-chainbase: package json --- packages/plugin-chainbase/package.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/plugin-chainbase/package.json b/packages/plugin-chainbase/package.json index bc8589f2eb1..c12bae6387a 100644 --- a/packages/plugin-chainbase/package.json +++ b/packages/plugin-chainbase/package.json @@ -7,9 +7,13 @@ "dependencies": { "@elizaos/core": "workspace:*" }, + "devDependencies": { + "vitest": "^2.1.5" + }, "scripts": { "build": "tsup --format esm --dts", "dev": "tsup --format esm --dts --watch", - "lint": "eslint --fix --cache ." + "lint": "eslint --fix --cache .", + "test": "vitest run" } } From 989344bb4acca60d44c628166206ff8572b1cc86 Mon Sep 17 00:00:00 2001 From: ai16z-demirix Date: Thu, 30 Jan 2025 22:54:28 +0100 Subject: [PATCH 07/16] plugin-chainbase: vitest config --- packages/plugin-chainbase/vitest.config.ts | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 packages/plugin-chainbase/vitest.config.ts diff --git a/packages/plugin-chainbase/vitest.config.ts b/packages/plugin-chainbase/vitest.config.ts new file mode 100644 index 00000000000..2af7cfb6cd9 --- /dev/null +++ b/packages/plugin-chainbase/vitest.config.ts @@ -0,0 +1,8 @@ +import { defineConfig } from 'vitest/config'; + +export default defineConfig({ + test: { + globals: true, + environment: 'node' + } +}); From dad22af0993efbe815dbbab6875db6e4e888136a Mon Sep 17 00:00:00 2001 From: ai16z-demirix Date: Thu, 30 Jan 2025 22:54:45 +0100 Subject: [PATCH 08/16] plugin-chainbase: query data tests --- .../__tests__/actions/queryData.test.ts | 146 ++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 packages/plugin-chainbase/__tests__/actions/queryData.test.ts diff --git a/packages/plugin-chainbase/__tests__/actions/queryData.test.ts b/packages/plugin-chainbase/__tests__/actions/queryData.test.ts new file mode 100644 index 00000000000..6c34b97d97b --- /dev/null +++ b/packages/plugin-chainbase/__tests__/actions/queryData.test.ts @@ -0,0 +1,146 @@ +import { describe, expect, it, vi, beforeEach } from 'vitest'; +import { queryBlockChainData } from '../../src/actions/queryData'; +import { generateSQL, executeQuery } from '../../src/libs/chainbase'; +import { ModelClass, generateText } from '@elizaos/core'; + +// Mock external dependencies +vi.mock('@elizaos/core', () => ({ + elizaLogger: { + log: vi.fn(), + error: vi.fn() + }, + generateText: vi.fn(), + ModelClass: { + SMALL: 'small', + LARGE: 'large' + } +})); + +vi.mock('../../src/libs/chainbase', () => ({ + generateSQL: vi.fn(), + executeQuery: vi.fn() +})); + +describe('queryBlockChainData', () => { + let mockRuntime; + let mockMessage; + let mockCallback; + + beforeEach(() => { + mockRuntime = { + character: { + settings: { + secrets: { + CHAINBASE_API_KEY: 'test-api-key' + } + } + } + }; + + mockMessage = { + content: { + text: 'query onchain data: Get the latest block number' + } + }; + + mockCallback = vi.fn(); + + // Reset all mocks + vi.clearAllMocks(); + }); + + describe('validation', () => { + it('should validate successfully when API key is present', async () => { + const result = await queryBlockChainData.validate(mockRuntime, mockMessage); + expect(result).toBe(true); + }); + + it('should fail validation when API key is missing', async () => { + const runtimeWithoutKey = { + character: { + settings: { + secrets: {} + } + } + }; + const result = await queryBlockChainData.validate(runtimeWithoutKey, mockMessage); + expect(result).toBe(false); + }); + }); + + describe('handler', () => { + it('should handle valid query and return formatted response', async () => { + const mockSQL = 'SELECT block_number FROM ethereum.blocks ORDER BY block_number DESC LIMIT 1'; + const mockQueryResult = { + columns: ['block_number'], + data: [[12345678]], + totalRows: 1 + }; + const mockFormattedResponse = 'The latest block number is 12345678'; + + vi.mocked(generateSQL).mockResolvedValue(mockSQL); + vi.mocked(executeQuery).mockResolvedValue(mockQueryResult); + vi.mocked(generateText).mockResolvedValue(mockFormattedResponse); + + await queryBlockChainData.handler(mockRuntime, mockMessage, undefined, undefined, mockCallback); + + expect(generateSQL).toHaveBeenCalledWith('Get the latest block number'); + expect(executeQuery).toHaveBeenCalledWith(mockSQL); + expect(generateText).toHaveBeenCalled(); + expect(mockCallback).toHaveBeenCalledWith({ + text: mockFormattedResponse + }); + }); + + it('should handle missing query prefix', async () => { + const messageWithoutPrefix = { + content: { + text: 'Get the latest block number' + } + }; + + await queryBlockChainData.handler(mockRuntime, messageWithoutPrefix, undefined, undefined, mockCallback); + + expect(mockCallback).toHaveBeenCalledWith({ + text: expect.stringContaining('Please use the format: query onchain data:') + }); + expect(generateSQL).not.toHaveBeenCalled(); + }); + + it('should handle empty query', async () => { + const messageWithEmptyQuery = { + content: { + text: 'query onchain data: ' + } + }; + + await queryBlockChainData.handler(mockRuntime, messageWithEmptyQuery, undefined, undefined, mockCallback); + + expect(mockCallback).toHaveBeenCalledWith({ + text: expect.stringContaining('Please provide a specific query') + }); + expect(generateSQL).not.toHaveBeenCalled(); + }); + + it('should handle API errors gracefully', async () => { + vi.mocked(generateSQL).mockRejectedValue(new Error('API Error')); + + await queryBlockChainData.handler(mockRuntime, mockMessage, undefined, undefined, mockCallback); + + expect(mockCallback).toHaveBeenCalledWith({ + text: expect.stringContaining('An error occurred') + }); + }); + }); + + describe('action properties', () => { + it('should have correct action properties', () => { + expect(queryBlockChainData.name).toBe('QUERY_BLOCKCHAIN_DATA'); + expect(queryBlockChainData.description).toBeDefined(); + expect(queryBlockChainData.similes).toBeDefined(); + expect(Array.isArray(queryBlockChainData.similes)).toBe(true); + expect(queryBlockChainData.examples).toBeDefined(); + expect(Array.isArray(queryBlockChainData.examples)).toBe(true); + }); + }); +}); From 30a3d9c78644fbd83b108808697d49b7579a6411 Mon Sep 17 00:00:00 2001 From: ai16z-demirix Date: Thu, 30 Jan 2025 22:55:09 +0100 Subject: [PATCH 09/16] plugin-chainbase: retrieve token balance tests --- .../actions/retrieveTokenBalance.test.ts | 213 ++++++++++++++++++ 1 file changed, 213 insertions(+) create mode 100644 packages/plugin-chainbase/__tests__/actions/retrieveTokenBalance.test.ts diff --git a/packages/plugin-chainbase/__tests__/actions/retrieveTokenBalance.test.ts b/packages/plugin-chainbase/__tests__/actions/retrieveTokenBalance.test.ts new file mode 100644 index 00000000000..c460867ebe5 --- /dev/null +++ b/packages/plugin-chainbase/__tests__/actions/retrieveTokenBalance.test.ts @@ -0,0 +1,213 @@ +import { describe, expect, it, vi, beforeEach } from 'vitest'; +import { retrieveTokenBalance } from '../../src/actions/retrieveTokenBalance'; +import { getTokenBalances } from '../../src/libs/chainbase'; +import { ModelClass, composeContext, generateObject, generateText } from '@elizaos/core'; + +// Mock external dependencies +vi.mock('@elizaos/core', () => ({ + elizaLogger: { + log: vi.fn(), + error: vi.fn() + }, + composeContext: vi.fn(), + generateObject: vi.fn(), + generateText: vi.fn(), + ModelClass: { + SMALL: 'small', + LARGE: 'large' + } +})); + +vi.mock('../../src/libs/chainbase', () => ({ + getTokenBalances: vi.fn() +})); + +describe('retrieveTokenBalance', () => { + let mockRuntime; + let mockMessage; + let mockState; + let mockCallback; + + beforeEach(() => { + mockRuntime = { + character: { + settings: { + secrets: { + CHAINBASE_API_KEY: 'test-api-key' + } + } + }, + composeState: vi.fn().mockResolvedValue({ + agentId: 'test-agent', + roomId: 'test-room' + }), + updateRecentMessageState: vi.fn().mockImplementation(state => Promise.resolve(state)) + }; + + mockMessage = { + content: { + text: 'Get token balances for address 0x123' + } + }; + + mockState = { + agentId: 'test-agent', + roomId: 'test-room' + }; + + mockCallback = vi.fn(); + + // Reset all mocks + vi.clearAllMocks(); + }); + + describe('validation', () => { + it('should validate successfully when API key is present', async () => { + const result = await retrieveTokenBalance.validate(mockRuntime, mockMessage); + expect(result).toBe(true); + }); + + it('should fail validation when API key is missing', async () => { + const runtimeWithoutKey = { + character: { + settings: { + secrets: {} + } + } + }; + const result = await retrieveTokenBalance.validate(runtimeWithoutKey, mockMessage); + expect(result).toBe(false); + }); + }); + + describe('handler', () => { + it('should handle valid token balance request', async () => { + const mockQueryParams = { + object: { + chain_id: '1', + address: '0x1234567890123456789012345678901234567890', + contract_address: '0x4567890123456789012345678901234567890123' + } + }; + + const mockTokens = [{ + name: 'Test Token', + symbol: 'TEST', + balance: '0x0de0b6b3a7640000', // 1 ETH in hex + decimals: 18, + contract_address: '0x456' + }]; + + const mockFormattedResponse = 'Test Token balance: 1.0 TEST'; + + vi.mocked(composeContext).mockReturnValue('mock-context'); + vi.mocked(generateObject).mockResolvedValue(mockQueryParams); + vi.mocked(getTokenBalances).mockResolvedValue(mockTokens); + vi.mocked(generateText).mockResolvedValue(mockFormattedResponse); + + await retrieveTokenBalance.handler(mockRuntime, mockMessage, mockState, undefined, mockCallback); + + expect(composeContext).toHaveBeenCalled(); + expect(generateObject).toHaveBeenCalled(); + expect(getTokenBalances).toHaveBeenCalledWith({ + chain_id: 1, + address: '0x1234567890123456789012345678901234567890', + contract_address: '0x4567890123456789012345678901234567890123' + }); + expect(mockCallback).toHaveBeenCalledWith({ + text: mockFormattedResponse + }); + }); + + it('should handle invalid query parameters', async () => { + const mockInvalidQueryParams = { + object: { + // Missing required fields + } + }; + + vi.mocked(composeContext).mockReturnValue('mock-context'); + vi.mocked(generateObject).mockResolvedValue(mockInvalidQueryParams); + + await retrieveTokenBalance.handler(mockRuntime, mockMessage, mockState, undefined, mockCallback); + + expect(mockCallback).toHaveBeenCalledWith( + { + text: 'Invalid query params. Please check the inputs.' + }, + [] + ); + expect(getTokenBalances).not.toHaveBeenCalled(); + }); + + it('should handle API errors gracefully', async () => { + const mockQueryParams = { + object: { + chain_id: '1', + address: '0x1234567890123456789012345678901234567890', + contract_address: '0x4567890123456789012345678901234567890123' + } + }; + + vi.mocked(composeContext).mockReturnValue('mock-context'); + vi.mocked(generateObject).mockResolvedValue(mockQueryParams); + vi.mocked(getTokenBalances).mockRejectedValue(new Error('API Error')); + + await retrieveTokenBalance.handler(mockRuntime, mockMessage, mockState, undefined, mockCallback); + + expect(mockCallback).toHaveBeenCalledWith({ + text: '❌ An error occurred while retrieving token balances. Please try again later.' + }); + }); + + it('should correctly format token balances', async () => { + const mockQueryParams = { + object: { + chain_id: '1', + address: '0x1234567890123456789012345678901234567890' + } + }; + + const mockTokens = [ + { + name: 'Token1', + symbol: 'TK1', + balance: '0x0de0b6b3a7640000', // 1 ETH in hex + decimals: 18, + contract_address: '0x456' + }, + { + name: 'Token2', + symbol: 'TK2', + balance: '0x0de0b6b3a7640000', // 1 ETH in hex + decimals: 6, + contract_address: '0x789' + } + ]; + + const mockFormattedResponse = 'Token balances: 1.0 TK1, 1000000.0 TK2'; + + vi.mocked(composeContext).mockReturnValue('mock-context'); + vi.mocked(generateObject).mockResolvedValue(mockQueryParams); + vi.mocked(getTokenBalances).mockResolvedValue(mockTokens); + vi.mocked(generateText).mockResolvedValue(mockFormattedResponse); + + await retrieveTokenBalance.handler(mockRuntime, mockMessage, mockState, undefined, mockCallback); + + expect(mockCallback).toHaveBeenCalledWith({ + text: mockFormattedResponse + }); + }); + }); + + describe('action properties', () => { + it('should have correct action properties', () => { + expect(retrieveTokenBalance.name).toBe('RETRIEVE_TOKEN_BALANCE'); + expect(retrieveTokenBalance.description).toBeDefined(); + expect(retrieveTokenBalance.similes).toBeDefined(); + expect(Array.isArray(retrieveTokenBalance.similes)).toBe(true); + expect(retrieveTokenBalance.examples).toBeDefined(); + expect(Array.isArray(retrieveTokenBalance.examples)).toBe(true); + }); + }); +}); From 20a0f1049e3dcdad7aceb1f6c553fba73f362ead Mon Sep 17 00:00:00 2001 From: ai16z-demirix Date: Thu, 30 Jan 2025 22:55:35 +0100 Subject: [PATCH 10/16] plugin-chainbase: libs/chainbase tests --- .../__tests__/libs/chainbase.test.ts | 220 ++++++++++++++++++ 1 file changed, 220 insertions(+) create mode 100644 packages/plugin-chainbase/__tests__/libs/chainbase.test.ts diff --git a/packages/plugin-chainbase/__tests__/libs/chainbase.test.ts b/packages/plugin-chainbase/__tests__/libs/chainbase.test.ts new file mode 100644 index 00000000000..066652d7d9f --- /dev/null +++ b/packages/plugin-chainbase/__tests__/libs/chainbase.test.ts @@ -0,0 +1,220 @@ +import { describe, expect, it, vi, beforeEach } from 'vitest'; +import { generateSQL, executeQuery, getTokenBalances } from '../../src/libs/chainbase'; +import { CHAINBASE_API_URL_ENDPOINT } from '../../src/constants'; + +// Mock fetch +const mockFetch = vi.fn(); +global.fetch = mockFetch; + +// Mock environment variables +process.env.CHAINBASE_API_KEY = 'test-api-key'; + +describe('chainbase library', () => { + beforeEach(() => { + mockFetch.mockReset(); + }); + + describe('generateSQL', () => { + it('should generate SQL from natural language prompt', async () => { + const mockResponse = { + sql: 'SELECT block_number FROM ethereum.blocks LIMIT 1' + }; + mockFetch.mockResolvedValueOnce({ + json: () => Promise.resolve(mockResponse) + }); + + const result = await generateSQL('Get the latest block number'); + + expect(mockFetch).toHaveBeenCalledWith( + `${CHAINBASE_API_URL_ENDPOINT}/api/v1/text2sql`, + expect.objectContaining({ + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: expect.any(String) + }) + ); + expect(result).toBe(mockResponse.sql); + }); + + it('should handle API errors', async () => { + mockFetch.mockRejectedValueOnce(new Error('API Error')); + + await expect(generateSQL('Invalid query')).rejects.toThrow('API Error'); + }); + }); + + describe('executeQuery', () => { + it('should execute SQL query and return results', async () => { + const mockExecuteResponse = { + data: [{ + executionId: 'test-execution-id' + }] + }; + + const mockPollResponse = { + data: { + status: 'FINISHED', + columns: ['block_number'], + data: [[12345678]], + total_row_count: 1 + } + }; + + vi.mocked(fetch) + .mockResolvedValueOnce({ + json: () => Promise.resolve(mockExecuteResponse) + } as Response) + .mockResolvedValueOnce({ + json: () => Promise.resolve(mockPollResponse) + } as Response); + + const result = await executeQuery('SELECT block_number FROM ethereum.blocks LIMIT 1'); + expect(result).toEqual({ + columns: ['block_number'], + data: [[12345678]], + totalRows: 1 + }); + }); + + it('should handle missing execution ID', async () => { + const mockExecuteResponse = { + data: [{}] // No executionId + }; + + mockFetch.mockResolvedValueOnce({ + json: () => Promise.resolve(mockExecuteResponse) + }); + + await expect(executeQuery('SELECT * FROM invalid.table')) + .rejects.toThrow('Failed to get execution_id'); + }); + + it('should handle query execution errors', async () => { + const mockExecuteResponse = { + data: [{ + executionId: 'test-execution-id' + }] + }; + + const mockPollResponse = { + data: { + status: 'FAILED', + message: 'Query execution failed' + } + }; + + vi.mocked(fetch) + .mockResolvedValueOnce({ + json: () => Promise.resolve(mockExecuteResponse) + } as Response) + .mockResolvedValueOnce({ + json: () => Promise.resolve(mockPollResponse) + } as Response); + + await expect(executeQuery('SELECT * FROM invalid.table')) + .rejects.toThrow('Query execution failed'); + }); + + it('should handle timeout after max retries', async () => { + // Mock a shorter MAX_RETRIES value for testing + const originalMaxRetries = process.env.MAX_RETRIES; + process.env.MAX_RETRIES = '2'; + + const mockExecuteResponse = { + data: [{ + executionId: 'test-execution-id' + }] + }; + + const mockPollResponse = { + data: { + status: 'RUNNING' + } + }; + + vi.mocked(fetch) + .mockResolvedValueOnce({ + json: () => Promise.resolve(mockExecuteResponse) + } as Response) + .mockResolvedValue({ + json: () => Promise.resolve(mockPollResponse) + } as Response); + + // Mock setTimeout to resolve immediately + vi.spyOn(global, 'setTimeout').mockImplementation((callback: any) => { + callback(); + return 0 as any; + }); + + await expect(executeQuery('SELECT * FROM large.table')) + .rejects.toThrow('Query timeout after 180 seconds'); + + // Restore original MAX_RETRIES value + process.env.MAX_RETRIES = originalMaxRetries; + }); + }); + + describe('getTokenBalances', () => { + it('should retrieve token balances for an address', async () => { + const mockResponse = { + data: [{ + name: 'Test Token', + symbol: 'TEST', + balance: '0x0de0b6b3a7640000', + decimals: 18, + contract_address: '0x123' + }] + }; + + vi.mocked(fetch).mockResolvedValueOnce({ + json: () => Promise.resolve(mockResponse) + } as Response); + + const result = await getTokenBalances({ + chain_id: 1, + address: '0x123', + contract_address: '0x456' + }); + + expect(fetch).toHaveBeenCalledWith( + expect.stringContaining('/v1/account/tokens'), + expect.objectContaining({ + headers: { + 'x-api-key': 'test-api-key' + }, + method: 'GET' + }) + ); + + expect(result).toEqual(mockResponse.data); + }); + + it('should handle API errors', async () => { + mockFetch.mockRejectedValueOnce(new Error('API Error')); + + await expect(getTokenBalances({ + chain_id: 1, + address: '0x123' + })).rejects.toThrow('API Error'); + }); + + it('should handle empty response', async () => { + const mockResponse = { + data: [] + }; + + mockFetch.mockResolvedValueOnce({ + json: () => Promise.resolve(mockResponse) + }); + + const result = await getTokenBalances({ + chain_id: 1, + address: '0x123' + }); + + expect(result).toEqual([]); + }); + }); +}); From 3d7add80dc4ab6bab94ec139a861536aa7f5bb56 Mon Sep 17 00:00:00 2001 From: ai16z-demirix Date: Thu, 30 Jan 2025 23:01:46 +0100 Subject: [PATCH 11/16] Revert "plugin-bootstrap: goal tests" This reverts commit 19bce8107ba95910433f21b66a1c0d951db6647f. --- .../__tests__/evaluators/goal.test.ts | 140 ------------------ 1 file changed, 140 deletions(-) delete mode 100644 packages/plugin-bootstrap/__tests__/evaluators/goal.test.ts diff --git a/packages/plugin-bootstrap/__tests__/evaluators/goal.test.ts b/packages/plugin-bootstrap/__tests__/evaluators/goal.test.ts deleted file mode 100644 index 39cbe23fa55..00000000000 --- a/packages/plugin-bootstrap/__tests__/evaluators/goal.test.ts +++ /dev/null @@ -1,140 +0,0 @@ -import { describe, expect, it, vi, beforeEach } from 'vitest'; -import { goalEvaluator } from '../../src/evaluators/goal'; -import { composeContext, generateText, getGoals, parseJsonArrayFromText } from '@elizaos/core'; - -vi.mock('@elizaos/core', () => ({ - composeContext: vi.fn(), - generateText: vi.fn(), - getGoals: vi.fn(), - parseJsonArrayFromText: vi.fn(), - ModelClass: { - SMALL: 'small' - } -})); - -describe('goalEvaluator', () => { - let mockRuntime; - let mockMessage; - - beforeEach(() => { - mockRuntime = { - character: { - settings: {} - }, - messageManager: { - countMemories: vi.fn().mockResolvedValue(5) - }, - composeState: vi.fn().mockResolvedValue({ - agentId: 'test-agent', - roomId: 'test-room', - goals: [{ id: 'test-goal', name: 'Test Goal' }] - }), - getConversationLength: vi.fn().mockReturnValue(10), - databaseAdapter: { - updateGoal: vi.fn().mockResolvedValue(true) - } - }; - - mockMessage = { - content: { - text: 'I have completed the project documentation.' - }, - roomId: 'test-room' - }; - - // Reset all mocks - vi.clearAllMocks(); - }); - - describe('validation', () => { - it('should validate successfully', async () => { - // Mock the getGoals function to return an active goal - vi.mocked(getGoals).mockImplementation(async ({ runtime, roomId, onlyInProgress }) => { - expect(runtime).toBe(mockRuntime); - expect(roomId).toBe('test-room'); - expect(onlyInProgress).toBe(true); - return [{ id: 'test-goal', name: 'Test Goal', status: 'IN_PROGRESS' }]; - }); - - const result = await goalEvaluator.validate(mockRuntime, mockMessage); - expect(result).toBe(true); - expect(getGoals).toHaveBeenCalledWith({ - runtime: mockRuntime, - count: 1, - onlyInProgress: true, - roomId: 'test-room' - }); - }); - }); - - describe('evaluator properties', () => { - it('should have correct evaluator properties', () => { - expect(goalEvaluator.name).toBe('UPDATE_GOAL'); - expect(goalEvaluator.similes).toContain('UPDATE_GOALS'); - expect(goalEvaluator.description).toBeDefined(); - expect(goalEvaluator.description).toContain('Analyze the conversation'); - expect(goalEvaluator.examples).toBeDefined(); - expect(Array.isArray(goalEvaluator.examples)).toBe(true); - }); - - it('should have valid examples', () => { - goalEvaluator.examples.forEach(example => { - expect(example).toBeDefined(); - // Add more specific example validations based on the example structure - }); - }); - }); - - describe('goal updates', () => { - it('should handle goal updates', async () => { - const mockGoals = [ - { - id: 'goal-1', - name: 'Complete Project Documentation', - status: 'IN_PROGRESS', - objectives: [ - { - description: 'Write project overview', - completed: true - }, - { - description: 'Document API endpoints', - completed: false - } - ] - } - ]; - - const mockUpdatedGoals = [ - { - id: 'goal-1', - status: 'DONE', - objectives: [ - { - description: 'Write project overview', - completed: true - }, - { - description: 'Document API endpoints', - completed: true - } - ] - } - ]; - - vi.mocked(composeContext).mockReturnValue('mock-context'); - vi.mocked(getGoals).mockResolvedValue(mockGoals); - vi.mocked(generateText).mockResolvedValue(JSON.stringify(mockUpdatedGoals)); - vi.mocked(parseJsonArrayFromText).mockReturnValue(mockUpdatedGoals); - - const result = await goalEvaluator.handler(mockRuntime, mockMessage); - - expect(composeContext).toHaveBeenCalled(); - expect(getGoals).toHaveBeenCalled(); - expect(generateText).toHaveBeenCalled(); - expect(parseJsonArrayFromText).toHaveBeenCalled(); - expect(mockRuntime.databaseAdapter.updateGoal).toHaveBeenCalled(); - expect(result).toBeDefined(); - }); - }); -}); From ae391308061cb8cbb9fadb3621957f3f13579f30 Mon Sep 17 00:00:00 2001 From: ai16z-demirix Date: Thu, 30 Jan 2025 23:02:21 +0100 Subject: [PATCH 12/16] Revert "plugin-bootstrap: continue tests" This reverts commit 3450d1f8938f6466cbf2aab64f4b4dd42fd46656. --- .../__tests__/actions/continue.test.ts | 218 ------------------ 1 file changed, 218 deletions(-) delete mode 100644 packages/plugin-bootstrap/__tests__/actions/continue.test.ts diff --git a/packages/plugin-bootstrap/__tests__/actions/continue.test.ts b/packages/plugin-bootstrap/__tests__/actions/continue.test.ts deleted file mode 100644 index b8c4e2ffb44..00000000000 --- a/packages/plugin-bootstrap/__tests__/actions/continue.test.ts +++ /dev/null @@ -1,218 +0,0 @@ -import { describe, expect, it, vi, beforeEach } from 'vitest'; -import { continueAction } from '../../src/actions/continue'; -import { composeContext, generateMessageResponse, generateTrueOrFalse, ModelClass } from '@elizaos/core'; - -vi.mock('@elizaos/core', () => ({ - composeContext: vi.fn(), - generateMessageResponse: vi.fn(), - generateTrueOrFalse: vi.fn(), - elizaLogger: { - info: vi.fn(), - error: vi.fn(), - debug: vi.fn(), - log: vi.fn() - }, - messageCompletionFooter: '\nResponse format:\n```\n{"content": {"text": string}}\n```', - booleanFooter: '\nResponse format: YES or NO', - ModelClass: { - SMALL: 'small', - LARGE: 'large' - } -})); - -describe('continueAction', () => { - let mockRuntime; - let mockMessage; - let mockState; - let mockCallback; - - beforeEach(() => { - mockRuntime = { - character: { - settings: {}, - name: 'TestBot', - bio: 'A test bot', - lore: 'Test lore', - knowledge: 'Test knowledge', - templates: { - messageHandlerTemplate: 'Test template {{agentName}}' - } - }, - messageManager: { - getLastMessageInRoom: vi.fn().mockResolvedValue({ - userId: 'test-user', - content: { text: 'Hello' } - }), - getMemories: vi.fn().mockResolvedValue([{ - userId: 'test-agent', - content: { - text: 'Previous bot message', - action: 'CONTINUE' - } - }]) - }, - composeState: vi.fn().mockResolvedValue({ - agentId: 'test-agent', - roomId: 'test-room' - }), - updateRecentMessageState: vi.fn().mockImplementation(state => Promise.resolve({ - ...state, - recentMessagesData: [{ - userId: 'test-agent', - content: { - text: 'Previous bot message', - action: 'CONTINUE' - } - }] - })), - agentId: 'test-agent', - databaseAdapter: { - log: vi.fn().mockResolvedValue(true) - } - }; - - mockMessage = { - id: 'test-message-1', - content: { - text: 'Hello, how are you' // No question mark to avoid early return - }, - roomId: 'test-room', - userId: 'test-user', - createdAt: Date.now() - }; - - mockState = { - agentId: 'test-agent', - roomId: 'test-room', - recentMessagesData: [{ - id: 'test-message-2', - userId: 'test-agent', - content: { - text: 'Previous bot message', - action: 'NONE', - inReplyTo: 'different-message-id' // Different ID to avoid early return - }, - createdAt: Date.now() - 1000 - }] - }; - - mockCallback = vi.fn(); - - // Reset all mocks - vi.clearAllMocks(); - }); - - describe('validation', () => { - it('should validate successfully when conditions are met', async () => { - mockRuntime.messageManager.getMemories.mockResolvedValueOnce([{ - userId: 'test-agent', - content: { - text: 'Previous bot message', - action: 'NONE' - } - }]); - - const result = await continueAction.validate(mockRuntime, mockMessage); - expect(result).toBe(true); - }); - - it('should fail validation when too many continues in a row', async () => { - mockRuntime.messageManager.getMemories.mockResolvedValueOnce([ - { - userId: 'test-agent', - content: { - text: 'Message 1', - action: 'CONTINUE' - } - }, - { - userId: 'test-agent', - content: { - text: 'Message 2', - action: 'CONTINUE' - } - }, - { - userId: 'test-agent', - content: { - text: 'Message 3', - action: 'CONTINUE' - } - } - ]); - - const result = await continueAction.validate(mockRuntime, mockMessage); - expect(result).toBe(false); - }); - }); - - describe('action properties', () => { - it('should have correct action properties', () => { - expect(continueAction.name).toBe('CONTINUE'); - expect(continueAction.description).toBeDefined(); - expect(continueAction.examples).toBeDefined(); - expect(Array.isArray(continueAction.examples)).toBe(true); - }); - - it('should have valid examples', () => { - continueAction.examples.forEach(example => { - expect(Array.isArray(example)).toBe(true); - example.forEach(interaction => { - expect(interaction).toHaveProperty('user'); - expect(interaction).toHaveProperty('content'); - }); - }); - }); - }); - - describe('message generation', () => { - it('should generate continuation message', async () => { - const mockResponse = { - content: { - text: 'This is a continuation message', - action: 'CONTINUE', - inReplyTo: 'test-message-1' - } - }; - - const mockStateWithContext = { - ...mockState, - actionExamples: [], - bio: mockRuntime.character.bio, - lore: mockRuntime.character.lore, - knowledge: mockRuntime.character.knowledge, - agentName: mockRuntime.character.name, - messageDirections: 'Test directions', - recentMessages: 'Test recent messages', - actions: 'Test actions', - providers: [], - attachments: [] - }; - - mockRuntime.messageManager.getMemories.mockResolvedValueOnce([{ - id: 'test-message-2', - userId: 'test-agent', - content: { - text: 'Previous bot message', - action: 'NONE', - inReplyTo: 'different-message-id' - }, - createdAt: Date.now() - 1000 - }]); - - mockRuntime.updateRecentMessageState.mockResolvedValueOnce(mockStateWithContext); - - vi.mocked(composeContext).mockReturnValue('mock-context'); - vi.mocked(generateTrueOrFalse).mockResolvedValue(true); - vi.mocked(generateMessageResponse).mockResolvedValue(mockResponse); - - await continueAction.handler(mockRuntime, mockMessage, mockStateWithContext, {}, mockCallback); - - expect(composeContext).toHaveBeenCalled(); - expect(generateTrueOrFalse).toHaveBeenCalled(); - expect(generateMessageResponse).toHaveBeenCalled(); - expect(mockCallback).toHaveBeenCalledWith(mockResponse); - expect(mockRuntime.databaseAdapter.log).toHaveBeenCalled(); - }); - }); -}); From 8a230aeb52d8a6302c01ae35100e5722e05327b6 Mon Sep 17 00:00:00 2001 From: ai16z-demirix Date: Thu, 30 Jan 2025 23:03:09 +0100 Subject: [PATCH 13/16] Revert "plugin-bootstrap: fact tests" This reverts commit df5590bfeb432d866e48463e0bdc9ccb97e86a3e. --- .../__tests__/evaluators/fact.test.ts | 113 ------------------ 1 file changed, 113 deletions(-) delete mode 100644 packages/plugin-bootstrap/__tests__/evaluators/fact.test.ts diff --git a/packages/plugin-bootstrap/__tests__/evaluators/fact.test.ts b/packages/plugin-bootstrap/__tests__/evaluators/fact.test.ts deleted file mode 100644 index ad4cbeb3710..00000000000 --- a/packages/plugin-bootstrap/__tests__/evaluators/fact.test.ts +++ /dev/null @@ -1,113 +0,0 @@ -import { describe, expect, it, vi, beforeEach } from 'vitest'; -import { factEvaluator } from '../../src/evaluators/fact'; -import { composeContext, generateObjectArray, MemoryManager } from '@elizaos/core'; - -vi.mock('@elizaos/core', () => ({ - composeContext: vi.fn(), - generateObjectArray: vi.fn(), - MemoryManager: vi.fn().mockImplementation((config: any) => ({ - getMemoriesByEvaluator: vi.fn().mockResolvedValue([]), - addMemory: vi.fn().mockResolvedValue(true), - addEmbeddingToMemory: vi.fn().mockResolvedValue({ - id: 'test-memory-id', - content: { - text: 'Test memory content' - } - }), - createMemory: vi.fn().mockResolvedValue({ - id: 'test-memory-id', - content: { - text: 'Test memory content' - } - }) - })), - ModelClass: { - SMALL: 'small' - } -})); - -describe('factEvaluator', () => { - let mockRuntime; - let mockMessage; - - beforeEach(() => { - mockRuntime = { - character: { - settings: {} - }, - messageManager: { - countMemories: vi.fn().mockResolvedValue(5) - }, - composeState: vi.fn().mockResolvedValue({ - agentId: 'test-agent', - roomId: 'test-room' - }), - getConversationLength: vi.fn().mockReturnValue(10) - }; - - mockMessage = { - content: { - text: 'I live in New York and work as a software engineer.' - }, - roomId: 'test-room' - }; - - // Reset all mocks - vi.clearAllMocks(); - }); - - describe('validation', () => { - it('should validate successfully', async () => { - const result = await factEvaluator.validate(mockRuntime, mockMessage); - expect(result).toBe(true); - expect(mockRuntime.messageManager.countMemories).toHaveBeenCalledWith('test-room'); - expect(mockRuntime.getConversationLength).toHaveBeenCalled(); - }); - }); - - describe('evaluator properties', () => { - it('should have correct evaluator properties', () => { - expect(factEvaluator.name).toBe('GET_FACTS'); - expect(factEvaluator.similes).toContain('GET_CLAIMS'); - expect(factEvaluator.description).toBeDefined(); - expect(factEvaluator.description).toContain('Extract factual information'); - expect(factEvaluator.examples).toBeDefined(); - expect(Array.isArray(factEvaluator.examples)).toBe(true); - }); - - it('should have valid examples', () => { - factEvaluator.examples.forEach(example => { - expect(example).toBeDefined(); - // Add more specific example validations based on the example structure - }); - }); - }); - - describe('fact extraction', () => { - it('should handle fact extraction', async () => { - const mockFacts = [ - { - claim: 'User lives in New York', - type: 'fact', - in_bio: false, - already_known: false - }, - { - claim: 'User works as a software engineer', - type: 'fact', - in_bio: false, - already_known: false - } - ]; - - vi.mocked(composeContext).mockReturnValue('mock-context'); - vi.mocked(generateObjectArray).mockResolvedValue(mockFacts); - - const result = await factEvaluator.handler(mockRuntime, mockMessage); - - expect(composeContext).toHaveBeenCalled(); - expect(generateObjectArray).toHaveBeenCalled(); - expect(result).toBeDefined(); - }); - }); -}); From ebe7609d28908737bc3b3b5636c39c91fe2912fc Mon Sep 17 00:00:00 2001 From: ai16z-demirix Date: Thu, 30 Jan 2025 23:04:25 +0100 Subject: [PATCH 14/16] Revert "plugin-bootstrap: package json" This reverts commit 46062f04950f42854025b651e8311e887a78ef03. --- packages/plugin-bootstrap/package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/plugin-bootstrap/package.json b/packages/plugin-bootstrap/package.json index 90881289790..a952d27a92b 100644 --- a/packages/plugin-bootstrap/package.json +++ b/packages/plugin-bootstrap/package.json @@ -24,8 +24,7 @@ }, "scripts": { "build": "tsup --format esm --dts", - "dev": "tsup --format esm --dts --watch", - "test": "vitest run" + "dev": "tsup --format esm --dts --watch" }, "peerDependencies": { "whatwg-url": "7.1.0" From bb4fa8bff864d513f31c97ba6e80e770d53e1166 Mon Sep 17 00:00:00 2001 From: ai16z-demirix Date: Thu, 30 Jan 2025 23:04:34 +0100 Subject: [PATCH 15/16] Revert "plugin-bootstrap: vitest config" This reverts commit b407f925c68e470a0958aee3e6bbe1d79f05560d. --- packages/plugin-bootstrap/vitest.config.ts | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 packages/plugin-bootstrap/vitest.config.ts diff --git a/packages/plugin-bootstrap/vitest.config.ts b/packages/plugin-bootstrap/vitest.config.ts deleted file mode 100644 index adbf7255380..00000000000 --- a/packages/plugin-bootstrap/vitest.config.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { defineConfig } from 'vitest/config'; - -export default defineConfig({ - test: { - globals: true, - environment: 'node', - }, -}); From 96ab0fd368dc1e992dac24819d55680532f92064 Mon Sep 17 00:00:00 2001 From: Demirix Date: Fri, 31 Jan 2025 17:51:30 +0100 Subject: [PATCH 16/16] Update package.json --- packages/plugin-chainbase/package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/plugin-chainbase/package.json b/packages/plugin-chainbase/package.json index f69c9a571c4..1c900dbb715 100644 --- a/packages/plugin-chainbase/package.json +++ b/packages/plugin-chainbase/package.json @@ -14,8 +14,7 @@ "scripts": { "build": "tsup --format esm --dts", "dev": "tsup --format esm --dts --watch", - "lint": "eslint --fix --cache .", - "test": "vitest run" + "test": "vitest run", "clean": "rm -rf dist", "lint": "biome lint .", "lint:fix": "biome check --apply .",