Skip to content

Commit

Permalink
Fix env handling for create runtime, fix lore tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lalalune committed Feb 23, 2024
1 parent 0af4b43 commit 81043b0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 28 deletions.
36 changes: 11 additions & 25 deletions src/lib/__tests__/lore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import dotenv from "dotenv";
import { createRuntime } from "../../test/createRuntime";
import { composeContext } from "../context";
import { addLore, getLore } from "../lore";
import { getRelationship } from "../../agents/cj/relationships";
import { BgentRuntime } from "../runtime";
import { requestHandlerTemplate } from "../templates";
import { type Content } from "../types";
Expand All @@ -14,22 +13,13 @@ describe("Lore", () => {
const zeroUuid: UUID = "00000000-0000-0000-0000-000000000000";
let runtime: BgentRuntime;
let user: User;
let room_id: UUID;

beforeAll(async () => {
const result = await createRuntime({
env: process.env as Record<string, string>,
});
runtime = result.runtime;
user = result.session.user;

const data = await getRelationship({
runtime,
userA: user?.id as UUID,
userB: zeroUuid,
});

room_id = data?.room_id;
user = result?.session?.user as User;
});

beforeEach(async () => {
Expand All @@ -52,18 +42,17 @@ describe("Lore", () => {
runtime,
source: "/Test.md",
content: "Test",
user_id: user.id as UUID,
room_id,
user_id: zeroUuid,
room_id: zeroUuid,
});

const lore = await getLore({
runtime,
message: "Test",
});

expect(lore).toHaveLength(1);
expect(lore[0].content).toEqual(content);
});
}, 60000);

// TODO: Test that the lore is in the context of the agent

Expand All @@ -72,23 +61,20 @@ describe("Lore", () => {
runtime,
source: "Test Lore Source",
content: "Test Lore Content",
user_id: user.id as UUID,
room_id,
user_id: zeroUuid as UUID,
room_id: zeroUuid,
});

const message = {
senderId: user.id as UUID,
senderId: zeroUuid as UUID,
agentId: zeroUuid,
userIds: [user.id as UUID, zeroUuid],
content: "Test",
room_id,
userIds: [zeroUuid],
content: "Test Lore Content",
room_id: zeroUuid,
};

const state = await runtime.composeState(message);

// expect state.lore to exist
expect(state.lore).toHaveLength(1);

const context = composeContext({
state,
template: requestHandlerTemplate,
Expand All @@ -97,5 +83,5 @@ describe("Lore", () => {
// expect context to contain 'Test Lore Source' and 'Test Lore Content'
expect(context).toContain("Test Lore Source");
expect(context).toContain("Test Lore Content");
});
}, 60000);
});
14 changes: 11 additions & 3 deletions src/test/createRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,25 @@ export async function createRuntime({
evaluators?: Evaluator[];
actions?: Action[];
}) {
const supabase = createClient(SUPABASE_URL!, SUPABASE_ANON_KEY!);
const supabase = createClient(
env?.SUPABASE_URL ?? SUPABASE_URL,
env?.SUPABASE_SERVICE_API_KEY ?? SUPABASE_ANON_KEY,
);

const {
let {
data: { user, session },
} = await supabase.auth.signInWithPassword({
email: TEST_EMAIL!,
password: TEST_PASSWORD!,
});

if (!session) {
throw new Error("Session not found");
const response = await supabase.auth.signUp({
email: TEST_EMAIL!,
password: TEST_PASSWORD!,
});
user = response.data.user;
session = response.data.session;
}

const runtime = new BgentRuntime({
Expand Down

0 comments on commit 81043b0

Please sign in to comment.