Skip to content

Commit

Permalink
fixing tests
Browse files Browse the repository at this point in the history
Signed-off-by: MarcoMandar <[email protected]>
  • Loading branch information
MarcoMandar committed Nov 5, 2024
1 parent 1eb89a4 commit d1a3a68
Show file tree
Hide file tree
Showing 13 changed files with 137 additions and 27 deletions.
14 changes: 10 additions & 4 deletions core/tests/browser.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import dotenv from "dotenv";
import { createRuntime } from "../test_resources/createRuntime.ts";
import { BrowserService } from "./browser.ts";
import { createRuntime } from "../src/test_resources/createRuntime.ts";
import { BrowserService } from "../src/services/browser.ts";
import { IAgentRuntime } from "../src/core/types.ts";

dotenv.config();

Expand All @@ -12,7 +13,10 @@ describe("BrowserService", () => {
env: process.env as Record<string, string>,
actions: [],
});
browserService = BrowserService.getInstance(runtime);
if (runtime.llamaService === null) {
throw new Error("llamaService cannot be null");
}
browserService = BrowserService.getInstance(runtime as IAgentRuntime);
await browserService.initialize();
});

Expand All @@ -25,7 +29,9 @@ describe("BrowserService", () => {
env: process.env as Record<string, string>,
actions: [],
});
const newBrowserService = BrowserService.getInstance(runtime);
const newBrowserService = BrowserService.getInstance(
runtime as IAgentRuntime
);
await expect(newBrowserService.initialize()).resolves.not.toThrow();
await expect(newBrowserService.closeBrowser()).resolves.not.toThrow();
});
Expand Down
15 changes: 12 additions & 3 deletions core/tests/continue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { getOrCreateRelationship } from "../src/test_resources/getOrCreateRelati
import { populateMemories } from "../src/test_resources/populateMemories.ts";
import { runAiTest } from "../src/test_resources/runAiTest.ts";
import { type User } from "../src/test_resources/types.ts";
import action from "../src/actions/continue.ts";
import ignore from "../src/actions/ignore.ts";
import { continueAction as action } from "../src/actions/continue.ts";
import { ignore } from "../src/actions/ignore.ts";

dotenv.config({ path: ".dev.vars" });

Expand Down Expand Up @@ -56,7 +56,10 @@ describe("User Profile", () => {
actions: [action, ignore],
});
user = setup.session.user;
runtime = setup.runtime;
if (setup.runtime.llamaService === null) {
throw new Error("llamaService cannot be null");
}
runtime = setup.runtime as IAgentRuntime;

const data = await getOrCreateRelationship({
runtime,
Expand Down Expand Up @@ -86,6 +89,7 @@ describe("User Profile", () => {
userId: user.id as UUID,
content: { text: "Hello" },
roomId: roomId as UUID,
agentId: runtime.agentId,
};

const validate = action.validate!;
Expand All @@ -104,6 +108,7 @@ describe("User Profile", () => {
action: "CONTINUE",
},
roomId: roomId as UUID,
agentId: runtime.agentId,
};

const result2 = await validate(runtime, message2);
Expand All @@ -121,6 +126,7 @@ describe("User Profile", () => {
action: "CONTINUE",
},
roomId,
agentId: runtime.agentId,
};

const handler = action.handler!;
Expand All @@ -145,6 +151,7 @@ describe("User Profile", () => {
text: "Write a short story in three parts, using the CONTINUE action for each part.",
},
roomId: roomId,
agentId: runtime.agentId,
};

const initialMessageCount =
Expand Down Expand Up @@ -196,6 +203,7 @@ describe("User Profile", () => {
text: "Tell me more about your favorite food.",
},
roomId: roomId as UUID,
agentId: runtime.agentId,
};

const initialMessageCount =
Expand All @@ -216,6 +224,7 @@ describe("User Profile", () => {
userId: user?.id as UUID,
content: { text: "Bye" },
roomId: roomId as UUID,
agentId: runtime.agentId,
};

const handler = action.handler!;
Expand Down
9 changes: 8 additions & 1 deletion core/tests/evaluation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ describe("Evaluation Process", () => {
env: process.env as Record<string, string>,
evaluators: [TEST_EVALUATOR, TEST_EVALUATOR_FAIL],
});
runtime = setup.runtime;
if (setup.runtime.llamaService === null) {
throw new Error("llamaService cannot be null");
}
runtime = setup.runtime as IAgentRuntime;
user = setup.session.user;

const data = await getOrCreateRelationship({
Expand Down Expand Up @@ -61,6 +64,7 @@ describe("Evaluation Process", () => {
userId: user.id as UUID,
content: { text: "Test message for evaluation" },
roomId,
agentId: runtime.agentId,
};

const state = await runtime.composeState(message);
Expand All @@ -79,6 +83,7 @@ describe("Evaluation Process", () => {
userId: user.id as UUID,
content: { text: "Run TEST_EVALUATOR handler" },
roomId,
agentId: runtime.agentId,
};

const result = await TEST_EVALUATOR.handler(runtime, message);
Expand All @@ -93,6 +98,7 @@ describe("Evaluation Process", () => {
text: "We are in testing mode. We want to make sure that the test passes by replying with the evaluator TEST_EVALUATOR in the array of evaluators that are returned. Please run the TEST_EVALUATOR",
},
roomId,
agentId: runtime.agentId,
};

const state = await runtime.composeState(message);
Expand All @@ -113,6 +119,7 @@ describe("Evaluation Process", () => {
userId: user.id as UUID,
content: { text: "Test message for evaluation" },
roomId,
agentId: runtime.agentId,
};

const state = await runtime.composeState(message);
Expand Down
8 changes: 7 additions & 1 deletion core/tests/fact.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ describe("Facts Evaluator", () => {
actions: defaultActions,
});
user = setup.session.user;
runtime = setup.runtime;
if (setup.runtime.llamaService === null) {
throw new Error("llamaService cannot be null");
}
runtime = setup.runtime as IAgentRuntime;

if (!user.id) {
throw new Error("User ID is undefined");
Expand Down Expand Up @@ -66,6 +69,7 @@ describe("Facts Evaluator", () => {
userId: user.id as UUID,
content: { text: "" },
roomId,
agentId: runtime.agentId,
};

const result = await evaluator.handler(runtime, message);
Expand All @@ -91,6 +95,7 @@ describe("Facts Evaluator", () => {
userId: user.id as UUID,
content: { text: "" },
roomId,
agentId: runtime.agentId,
};

const result = await evaluator.handler(runtime, message);
Expand Down Expand Up @@ -124,6 +129,7 @@ async function addFacts(
content: { text: fact },
roomId: roomId,
embedding: existingEmbedding,
agentId: runtime.agentId,
});
await runtime.factManager.createMemory(bakedMemory);
if (!existingEmbedding) {
Expand Down
7 changes: 6 additions & 1 deletion core/tests/goal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ describe("Goals Evaluator", () => {
actions: defaultActions,
});
user = setup.session.user;
runtime = setup.runtime;
if (setup.runtime.llamaService === null) {
throw new Error("llamaService cannot be null");
}
runtime = setup.runtime as IAgentRuntime;

const data = await getOrCreateRelationship({
runtime,
Expand Down Expand Up @@ -108,6 +111,7 @@ describe("Goals Evaluator", () => {
text: "I've completed task 1 and task 2 for the Test Goal. Both are finished. Everything is done and I'm ready for the next goal.",
},
roomId,
agentId: runtime.agentId,
};

// Process the message with the goal evaluator
Expand Down Expand Up @@ -177,6 +181,7 @@ describe("Goals Evaluator", () => {
userId: user.id as UUID,
content: { text: "I've decided to mark Goal Y as failed." },
roomId,
agentId: runtime.agentId,
};

await evaluator.handler(runtime, message, {} as State, {
Expand Down
6 changes: 5 additions & 1 deletion core/tests/goals.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ describe("Goals", () => {
const result = await createRuntime({
env: process.env as Record<string, string>,
});
runtime = result.runtime;

if (result.runtime.llamaService === null) {
throw new Error("llamaService cannot be null");
}
runtime = result.runtime as IAgentRuntime;
user = result.session.user;
await runtime.databaseAdapter.removeAllGoals(zeroUuid);
});
Expand Down
13 changes: 11 additions & 2 deletions core/tests/ignore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { populateMemories } from "../src/test_resources/populateMemories.ts";
import { runAiTest } from "../src/test_resources/runAiTest.ts";
import { messageHandlerTemplate } from "../src/test_resources/templates.ts";
import { type User } from "../src/test_resources/types.ts";
import action from "../src/actions/ignore.ts";
import { ignore as action } from "../src/actions/ignore.ts";
import { generateMessageResponse } from "../src/core/generation.ts";

async function handleMessage(
Expand All @@ -42,6 +42,7 @@ async function handleMessage(
},
roomId,
embedding: embeddingZeroVector,
agentId: runtime.agentId,
});
}
};
Expand Down Expand Up @@ -76,6 +77,7 @@ async function handleMessage(
content: response,
roomId,
embedding: embeddingZeroVector,
agentId: runtime.agentId,
};

if (responseMessage.content.text?.trim()) {
Expand Down Expand Up @@ -107,7 +109,10 @@ describe("Ignore action tests", () => {
actions: [action],
});
user = setup.session.user;
runtime = setup.runtime;
if (setup.runtime.llamaService === null) {
throw new Error("llamaService cannot be null");
}
runtime = setup.runtime as IAgentRuntime;

const data = await getOrCreateRelationship({
runtime,
Expand Down Expand Up @@ -139,6 +144,7 @@ describe("Ignore action tests", () => {
userId: user?.id as UUID,
content: { text: "Never talk to me again" },
roomId: roomId as UUID,
agentId: runtime.agentId,
};

await populateMemories(runtime, user, roomId, [
Expand All @@ -159,6 +165,7 @@ describe("Ignore action tests", () => {
userId: user.id as UUID,
content: { text: "", action: "IGNORE" },
roomId: roomId as UUID,
agentId: runtime.agentId,
};

await populateMemories(runtime, user, roomId, [
Expand All @@ -184,6 +191,7 @@ describe("Ignore action tests", () => {
userId: user.id as UUID,
content: { text: "", action: "IGNORE" },
roomId: roomId as UUID,
agentId: runtime.agentId,
};

await populateMemories(runtime, user, roomId, [
Expand All @@ -207,6 +215,7 @@ describe("Ignore action tests", () => {
userId: user.id as UUID,
content: { text: "Bye" },
roomId: roomId as UUID,
agentId: runtime.agentId,
};

await populateMemories(runtime, user, roomId, [Goodbye1]);
Expand Down
Loading

0 comments on commit d1a3a68

Please sign in to comment.