Skip to content

Commit

Permalink
Merge branch 'develop' into rest-upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
odilitime authored Dec 18, 2024
2 parents 22974cc + 855c029 commit 9b1382b
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 6 deletions.
10 changes: 5 additions & 5 deletions docs/docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ We believe in the power of the OODA Loop - a decision-making framework that emph

3. Fork the repo and create your branch from `main`.
1. The name of the branch should start with the issue number and be descriptive of the changes you are making.
1. eg. 40--add-test-for-bug-123
4. If you've added code that should be tested, add tests.
5. Ensure the test suite passes.
6. Make sure your code lints.
7. Issue that pull request!
2. Example: 9999--add-test-for-bug-123
3. If you've added code that should be tested, add tests.
4. Ensure the test suite passes.
5. Make sure your code lints.
6. Issue that pull request!

## Styleguides

Expand Down
2 changes: 1 addition & 1 deletion packages/core/README-TESTS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Core Package Tests

This package contains a test suite for evaluating functionalities using **Jest**.
This package contains a test suite for evaluating functionalities using **Vitest**.

## Prerequisites

Expand Down
139 changes: 139 additions & 0 deletions packages/core/src/tests/runtime.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import { describe, it, expect, beforeEach, vi } from "vitest";
import { AgentRuntime } from "../runtime";
import {
IDatabaseAdapter,
ModelProviderName,
Action,
Memory,
UUID,
} from "../types";
import { defaultCharacter } from "../defaultCharacter";

// Mock dependencies with minimal implementations
const mockDatabaseAdapter: IDatabaseAdapter = {
db: {},
init: vi.fn().mockResolvedValue(undefined),
close: vi.fn().mockResolvedValue(undefined),
getAccountById: vi.fn().mockResolvedValue(null),
createAccount: vi.fn().mockResolvedValue(true),
getMemories: vi.fn().mockResolvedValue([]),
getMemoryById: vi.fn().mockResolvedValue(null),
getMemoriesByRoomIds: vi.fn().mockResolvedValue([]),
getCachedEmbeddings: vi.fn().mockResolvedValue([]),
log: vi.fn().mockResolvedValue(undefined),
getActorDetails: vi.fn().mockResolvedValue([]),
searchMemories: vi.fn().mockResolvedValue([]),
updateGoalStatus: vi.fn().mockResolvedValue(undefined),
searchMemoriesByEmbedding: vi.fn().mockResolvedValue([]),
createMemory: vi.fn().mockResolvedValue(undefined),
removeMemory: vi.fn().mockResolvedValue(undefined),
removeAllMemories: vi.fn().mockResolvedValue(undefined),
countMemories: vi.fn().mockResolvedValue(0),
getGoals: vi.fn().mockResolvedValue([]),
updateGoal: vi.fn().mockResolvedValue(undefined),
createGoal: vi.fn().mockResolvedValue(undefined),
removeGoal: vi.fn().mockResolvedValue(undefined),
removeAllGoals: vi.fn().mockResolvedValue(undefined),
getRoom: vi.fn().mockResolvedValue(null),
createRoom: vi.fn().mockResolvedValue("test-room-id" as UUID),
removeRoom: vi.fn().mockResolvedValue(undefined),
getRoomsForParticipant: vi.fn().mockResolvedValue([]),
getRoomsForParticipants: vi.fn().mockResolvedValue([]),
addParticipant: vi.fn().mockResolvedValue(true),
removeParticipant: vi.fn().mockResolvedValue(true),
getParticipantsForAccount: vi.fn().mockResolvedValue([]),
getParticipantsForRoom: vi.fn().mockResolvedValue([]),
getParticipantUserState: vi.fn().mockResolvedValue(null),
setParticipantUserState: vi.fn().mockResolvedValue(undefined),
createRelationship: vi.fn().mockResolvedValue(true),
getRelationship: vi.fn().mockResolvedValue(null),
getRelationships: vi.fn().mockResolvedValue([])
};

const mockCacheManager = {
get: vi.fn().mockResolvedValue(null),
set: vi.fn().mockResolvedValue(undefined),
delete: vi.fn().mockResolvedValue(undefined),
};

// Mock action creator
const createMockAction = (name: string): Action => ({
name,
description: `Test action ${name}`,
similes: [`like ${name}`],
examples: [],
handler: vi.fn().mockResolvedValue(undefined),
validate: vi.fn().mockImplementation(async () => true),
});

describe("AgentRuntime", () => {
let runtime: AgentRuntime;

beforeEach(() => {
vi.clearAllMocks();
runtime = new AgentRuntime({
token: "test-token",
character: defaultCharacter,
databaseAdapter: mockDatabaseAdapter,
cacheManager: mockCacheManager,
modelProvider: ModelProviderName.OPENAI,
});
});

describe("action management", () => {
it("should register an action", () => {
const action = createMockAction("testAction");
runtime.registerAction(action);
expect(runtime.actions).toContain(action);
});

it("should allow registering multiple actions", () => {
const action1 = createMockAction("testAction1");
const action2 = createMockAction("testAction2");
runtime.registerAction(action1);
runtime.registerAction(action2);
expect(runtime.actions).toContain(action1);
expect(runtime.actions).toContain(action2);
});

it("should process registered actions", async () => {
const action = createMockAction("testAction");
runtime.registerAction(action);

const message: Memory = {
id: "123e4567-e89b-12d3-a456-426614174003",
userId: "123e4567-e89b-12d3-a456-426614174004",
agentId: "123e4567-e89b-12d3-a456-426614174005",
roomId: "123e4567-e89b-12d3-a456-426614174003",
content: { type: "text", text: "test message" },
};

const response: Memory = {
id: "123e4567-e89b-12d3-a456-426614174006",
userId: "123e4567-e89b-12d3-a456-426614174005",
agentId: "123e4567-e89b-12d3-a456-426614174005",
roomId: "123e4567-e89b-12d3-a456-426614174003",
content: { type: "text", text: "test response", action: "testAction" },
};

await runtime.processActions(message, [response], {
bio: "Test agent bio",
lore: "Test agent lore and background",
messageDirections: "How to respond to messages",
postDirections: "How to create posts",
roomId: "123e4567-e89b-12d3-a456-426614174003",
actors: "List of actors in conversation",
recentMessages: "Recent conversation history",
recentMessagesData: [],
goals: "Current conversation goals",
goalsData: [],
actionsData: [],
knowledgeData: [],
recentInteractionsData: [],
});

expect(action.handler).toBeDefined();
expect(action.validate).toBeDefined();
});
});
});

0 comments on commit 9b1382b

Please sign in to comment.