From d6c44a03d9e7fe2c4c5afb30783353dd3845b5f6 Mon Sep 17 00:00:00 2001 From: moon Date: Tue, 13 Feb 2024 18:21:56 -0800 Subject: [PATCH] Add concat and evaluation test --- scripts/concat.mjs | 2 +- src/lib/__tests__/evaluation.test.ts | 87 +++++++++++++++++++++++++++- 2 files changed, 85 insertions(+), 4 deletions(-) diff --git a/scripts/concat.mjs b/scripts/concat.mjs index cc95044..118d86f 100644 --- a/scripts/concat.mjs +++ b/scripts/concat.mjs @@ -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'] diff --git a/src/lib/__tests__/evaluation.test.ts b/src/lib/__tests__/evaluation.test.ts index f87c04d..de8bbb7 100644 --- a/src/lib/__tests__/evaluation.test.ts +++ b/src/lib/__tests__/evaluation.test.ts @@ -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); + 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'); + }); +});