Skip to content

Commit

Permalink
Add concat and evaluation test
Browse files Browse the repository at this point in the history
  • Loading branch information
lalalune committed Feb 14, 2024
1 parent 8ecef82 commit d6c44a0
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 4 deletions.
2 changes: 1 addition & 1 deletion scripts/concat.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from 'fs'
import path, { dirname } from 'path'
import { fileURLToPath } from 'url'

const instructions = 'The above code was taken from the Cojourney codebase at https://github.com/lalalune/bgent. You are writing tests and documentation for the Cojourney codebase. Please use the above code as a reference. Tests should be written with Jest and Typescript. Do not use mocks or stubs. Keep it very simple and straightforward.'
const instructions = 'The above code was taken from my codebase at https://github.com/lalalune/bgent. You are writing tests and documentation for my codebase. Please use the above code as a reference. Tests should be written with Jest and Typescript. Do not use mocks or stubs. Keep it very simple and straightforward.'

// Patterns to ignore
const ignorePatterns = ['messageExamples.ts', 'goal', 'goals', 'utils', 'logger', 'index', 'data', 'constants', 'templates', 'worker']
Expand Down
87 changes: 84 additions & 3 deletions src/lib/__tests__/evaluation.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,84 @@
// test evaluation injection
// test evaluator *not* running if no evalauation handlers are true
// test evaluation handling and response
import { type User } from "@supabase/supabase-js";
import { BgentRuntime } from "../runtime";
import { type Message } from "../types";
import { createRuntime } from "../../test/createRuntime";
import { type UUID } from "crypto";

describe('Evaluation Process', () => {
let runtime: BgentRuntime;
let user: User;
const zeroUuid = '00000000-0000-0000-0000-000000000000';

beforeAll(async () => {
const setup = await createRuntime(process.env as Record<string, string>);
runtime = setup.runtime;
user = setup.user as User;

// Assuming the evaluator 'reflect' is already registered in the runtime setup
});

test('Evaluation Injection - Evaluator Creates Memory', async () => {
const message: Message = {
senderId: user.id as UUID,
agentId: zeroUuid,
userIds: [user?.id as UUID, zeroUuid],
content: 'Trigger evaluator content',
room_id: zeroUuid
};

await runtime.handleRequest(message);

// Assuming the 'reflect' evaluator tags the memories it creates with 'reflection'
const memories = await runtime.reflectionManager.getMemoriesByIds({
userIds: [user.id as UUID, zeroUuid],
count: 1
});

// Expect at least one memory to be created with the 'reflection' tag
expect(memories.length).toBeGreaterThan(0);
});

test('Evaluator Not Running if No Evaluation Handlers are True', async () => {
const message: Message = {
senderId: user?.id as UUID,
agentId: zeroUuid,
userIds: [user?.id as UUID, zeroUuid],
content: 'Non-triggering content',
room_id: zeroUuid
};

await runtime.handleRequest(message);

// Assuming the 'reflect' evaluator tags the memories it creates with 'reflection'
const memories = await runtime.reflectionManager.getMemoriesByIds({
userIds: [user.id as UUID, zeroUuid],
count: 10
});

// Assuming the previous test ran and created exactly one memory
// Expect the number of memories to remain unchanged
expect(memories.length).toBe(1);
});

test('Evaluation Handling and Response - Evaluator Updates Memory', async () => {
const message: Message = {
senderId: user.id as UUID,
agentId: zeroUuid,
userIds: [user.id as UUID, zeroUuid],
content: 'Content that leads to a specific evaluator response',
room_id: zeroUuid
};

await runtime.handleRequest(message);

// Assuming the 'reflect' evaluator updates the 'content' of memories it processes
// Fetch the updated memory
const memories = await runtime.reflectionManager.getMemoriesByIds({
userIds: [user.id as UUID, zeroUuid],
count: 1
});

// Expect the updated memory to contain specific content
expect(memories[0].content).toContain('specific content');
});
});

0 comments on commit d6c44a0

Please sign in to comment.