Skip to content

Commit d1a3a68

Browse files
committed
fixing tests
Signed-off-by: MarcoMandar <malicemandar@gmail.com>
1 parent 1eb89a4 commit d1a3a68

13 files changed

+137
-27
lines changed

core/tests/browser.test.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import dotenv from "dotenv";
2-
import { createRuntime } from "../test_resources/createRuntime.ts";
3-
import { BrowserService } from "./browser.ts";
2+
import { createRuntime } from "../src/test_resources/createRuntime.ts";
3+
import { BrowserService } from "../src/services/browser.ts";
4+
import { IAgentRuntime } from "../src/core/types.ts";
45

56
dotenv.config();
67

@@ -12,7 +13,10 @@ describe("BrowserService", () => {
1213
env: process.env as Record<string, string>,
1314
actions: [],
1415
});
15-
browserService = BrowserService.getInstance(runtime);
16+
if (runtime.llamaService === null) {
17+
throw new Error("llamaService cannot be null");
18+
}
19+
browserService = BrowserService.getInstance(runtime as IAgentRuntime);
1620
await browserService.initialize();
1721
});
1822

@@ -25,7 +29,9 @@ describe("BrowserService", () => {
2529
env: process.env as Record<string, string>,
2630
actions: [],
2731
});
28-
const newBrowserService = BrowserService.getInstance(runtime);
32+
const newBrowserService = BrowserService.getInstance(
33+
runtime as IAgentRuntime
34+
);
2935
await expect(newBrowserService.initialize()).resolves.not.toThrow();
3036
await expect(newBrowserService.closeBrowser()).resolves.not.toThrow();
3137
});

core/tests/continue.test.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import { getOrCreateRelationship } from "../src/test_resources/getOrCreateRelati
1212
import { populateMemories } from "../src/test_resources/populateMemories.ts";
1313
import { runAiTest } from "../src/test_resources/runAiTest.ts";
1414
import { type User } from "../src/test_resources/types.ts";
15-
import action from "../src/actions/continue.ts";
16-
import ignore from "../src/actions/ignore.ts";
15+
import { continueAction as action } from "../src/actions/continue.ts";
16+
import { ignore } from "../src/actions/ignore.ts";
1717

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

@@ -56,7 +56,10 @@ describe("User Profile", () => {
5656
actions: [action, ignore],
5757
});
5858
user = setup.session.user;
59-
runtime = setup.runtime;
59+
if (setup.runtime.llamaService === null) {
60+
throw new Error("llamaService cannot be null");
61+
}
62+
runtime = setup.runtime as IAgentRuntime;
6063

6164
const data = await getOrCreateRelationship({
6265
runtime,
@@ -86,6 +89,7 @@ describe("User Profile", () => {
8689
userId: user.id as UUID,
8790
content: { text: "Hello" },
8891
roomId: roomId as UUID,
92+
agentId: runtime.agentId,
8993
};
9094

9195
const validate = action.validate!;
@@ -104,6 +108,7 @@ describe("User Profile", () => {
104108
action: "CONTINUE",
105109
},
106110
roomId: roomId as UUID,
111+
agentId: runtime.agentId,
107112
};
108113

109114
const result2 = await validate(runtime, message2);
@@ -121,6 +126,7 @@ describe("User Profile", () => {
121126
action: "CONTINUE",
122127
},
123128
roomId,
129+
agentId: runtime.agentId,
124130
};
125131

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

150157
const initialMessageCount =
@@ -196,6 +203,7 @@ describe("User Profile", () => {
196203
text: "Tell me more about your favorite food.",
197204
},
198205
roomId: roomId as UUID,
206+
agentId: runtime.agentId,
199207
};
200208

201209
const initialMessageCount =
@@ -216,6 +224,7 @@ describe("User Profile", () => {
216224
userId: user?.id as UUID,
217225
content: { text: "Bye" },
218226
roomId: roomId as UUID,
227+
agentId: runtime.agentId,
219228
};
220229

221230
const handler = action.handler!;

core/tests/evaluation.test.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ describe("Evaluation Process", () => {
2525
env: process.env as Record<string, string>,
2626
evaluators: [TEST_EVALUATOR, TEST_EVALUATOR_FAIL],
2727
});
28-
runtime = setup.runtime;
28+
if (setup.runtime.llamaService === null) {
29+
throw new Error("llamaService cannot be null");
30+
}
31+
runtime = setup.runtime as IAgentRuntime;
2932
user = setup.session.user;
3033

3134
const data = await getOrCreateRelationship({
@@ -61,6 +64,7 @@ describe("Evaluation Process", () => {
6164
userId: user.id as UUID,
6265
content: { text: "Test message for evaluation" },
6366
roomId,
67+
agentId: runtime.agentId,
6468
};
6569

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

8489
const result = await TEST_EVALUATOR.handler(runtime, message);
@@ -93,6 +98,7 @@ describe("Evaluation Process", () => {
9398
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",
9499
},
95100
roomId,
101+
agentId: runtime.agentId,
96102
};
97103

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

118125
const state = await runtime.composeState(message);

core/tests/fact.test.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ describe("Facts Evaluator", () => {
3333
actions: defaultActions,
3434
});
3535
user = setup.session.user;
36-
runtime = setup.runtime;
36+
if (setup.runtime.llamaService === null) {
37+
throw new Error("llamaService cannot be null");
38+
}
39+
runtime = setup.runtime as IAgentRuntime;
3740

3841
if (!user.id) {
3942
throw new Error("User ID is undefined");
@@ -66,6 +69,7 @@ describe("Facts Evaluator", () => {
6669
userId: user.id as UUID,
6770
content: { text: "" },
6871
roomId,
72+
agentId: runtime.agentId,
6973
};
7074

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

96101
const result = await evaluator.handler(runtime, message);
@@ -124,6 +129,7 @@ async function addFacts(
124129
content: { text: fact },
125130
roomId: roomId,
126131
embedding: existingEmbedding,
132+
agentId: runtime.agentId,
127133
});
128134
await runtime.factManager.createMemory(bakedMemory);
129135
if (!existingEmbedding) {

core/tests/goal.test.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ describe("Goals Evaluator", () => {
3232
actions: defaultActions,
3333
});
3434
user = setup.session.user;
35-
runtime = setup.runtime;
35+
if (setup.runtime.llamaService === null) {
36+
throw new Error("llamaService cannot be null");
37+
}
38+
runtime = setup.runtime as IAgentRuntime;
3639

3740
const data = await getOrCreateRelationship({
3841
runtime,
@@ -108,6 +111,7 @@ describe("Goals Evaluator", () => {
108111
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.",
109112
},
110113
roomId,
114+
agentId: runtime.agentId,
111115
};
112116

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

182187
await evaluator.handler(runtime, message, {} as State, {

core/tests/goals.test.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ describe("Goals", () => {
1818
const result = await createRuntime({
1919
env: process.env as Record<string, string>,
2020
});
21-
runtime = result.runtime;
21+
22+
if (result.runtime.llamaService === null) {
23+
throw new Error("llamaService cannot be null");
24+
}
25+
runtime = result.runtime as IAgentRuntime;
2226
user = result.session.user;
2327
await runtime.databaseAdapter.removeAllGoals(zeroUuid);
2428
});

core/tests/ignore.test.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { populateMemories } from "../src/test_resources/populateMemories.ts";
2121
import { runAiTest } from "../src/test_resources/runAiTest.ts";
2222
import { messageHandlerTemplate } from "../src/test_resources/templates.ts";
2323
import { type User } from "../src/test_resources/types.ts";
24-
import action from "../src/actions/ignore.ts";
24+
import { ignore as action } from "../src/actions/ignore.ts";
2525
import { generateMessageResponse } from "../src/core/generation.ts";
2626

2727
async function handleMessage(
@@ -42,6 +42,7 @@ async function handleMessage(
4242
},
4343
roomId,
4444
embedding: embeddingZeroVector,
45+
agentId: runtime.agentId,
4546
});
4647
}
4748
};
@@ -76,6 +77,7 @@ async function handleMessage(
7677
content: response,
7778
roomId,
7879
embedding: embeddingZeroVector,
80+
agentId: runtime.agentId,
7981
};
8082

8183
if (responseMessage.content.text?.trim()) {
@@ -107,7 +109,10 @@ describe("Ignore action tests", () => {
107109
actions: [action],
108110
});
109111
user = setup.session.user;
110-
runtime = setup.runtime;
112+
if (setup.runtime.llamaService === null) {
113+
throw new Error("llamaService cannot be null");
114+
}
115+
runtime = setup.runtime as IAgentRuntime;
111116

112117
const data = await getOrCreateRelationship({
113118
runtime,
@@ -139,6 +144,7 @@ describe("Ignore action tests", () => {
139144
userId: user?.id as UUID,
140145
content: { text: "Never talk to me again" },
141146
roomId: roomId as UUID,
147+
agentId: runtime.agentId,
142148
};
143149

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

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

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

212221
await populateMemories(runtime, user, roomId, [Goodbye1]);

0 commit comments

Comments
 (0)