|
1 | 1 | import dotenv from "dotenv";
|
| 2 | +import { describe, test, expect, beforeAll, afterAll } from "vitest"; |
2 | 3 | import { createRuntime } from "../test_resources/createRuntime.js";
|
3 | 4 | import { getOrCreateRelationship } from "../test_resources/getOrCreateRelationship.js";
|
4 | 5 | import { runAiTest } from "../test_resources/runAiTest.js";
|
5 | 6 | import { messageHandlerTemplate } from "../test_resources/templates.js";
|
6 | 7 | import { TEST_ACTION, TEST_ACTION_FAIL } from "../test_resources/testAction.js";
|
7 |
| -import { type User } from "../test_resources/types.js"; |
| 8 | +import { User } from "../test_resources/types.js"; |
8 | 9 | import {
|
9 | 10 | MemoryManager,
|
10 | 11 | Content,
|
11 | 12 | IAgentRuntime,
|
12 | 13 | ModelClass,
|
13 | 14 | State,
|
14 |
| - type Memory, |
15 |
| - type UUID, |
| 15 | + Memory, |
| 16 | + UUID, |
16 | 17 | stringToUuid,
|
17 | 18 | composeContext,
|
18 | 19 | generateMessageResponse,
|
@@ -220,46 +221,57 @@ describe("Actions", () => {
|
220 | 221 | });
|
221 | 222 |
|
222 | 223 | // Validate that TEST_ACTION is in the state
|
223 |
| - test("Validate that TEST_ACTION is in the state", async () => { |
224 |
| - await runAiTest("Validate TEST_ACTION is in the state", async () => { |
225 |
| - const message: Memory = { |
226 |
| - agentId: runtime.agentId, |
227 |
| - userId: user.id as UUID, |
228 |
| - content: { |
229 |
| - text: "Please respond with the message 'ok' and the action TEST_ACTION", |
230 |
| - }, |
231 |
| - roomId, |
232 |
| - }; |
233 |
| - |
234 |
| - const response = await handleMessage(runtime, message); |
235 |
| - return response.action === "TEST_ACTION"; // Return true if the expected action matches |
236 |
| - }); |
237 |
| - }, 60000); |
| 224 | + test( |
| 225 | + "Validate that TEST_ACTION is in the state", |
| 226 | + async () => { |
| 227 | + await runAiTest( |
| 228 | + "Validate TEST_ACTION is in the state", |
| 229 | + async () => { |
| 230 | + const message: Memory = { |
| 231 | + agentId: runtime.agentId, |
| 232 | + userId: user.id as UUID, |
| 233 | + content: { |
| 234 | + text: "Please respond with the message 'ok' and the action TEST_ACTION", |
| 235 | + }, |
| 236 | + roomId, |
| 237 | + }; |
| 238 | + |
| 239 | + const response = await handleMessage(runtime, message); |
| 240 | + return response.action === "TEST_ACTION"; // Return true if the expected action matches |
| 241 | + } |
| 242 | + ); |
| 243 | + }, |
| 244 | + { timeout: 60000 } |
| 245 | + ); |
238 | 246 |
|
239 | 247 | // Test that TEST_ACTION action handler is called properly
|
240 |
| - test("Test action handler is called", async () => { |
241 |
| - await runAiTest("Test action handler is called", async () => { |
242 |
| - const testAction = runtime.actions.find( |
243 |
| - (action) => action.name === "TEST_ACTION" |
244 |
| - ); |
245 |
| - if (!testAction || !testAction.handler) { |
246 |
| - console.error( |
247 |
| - "Continue action or its handler function is undefined" |
| 248 | + test( |
| 249 | + "Test action handler is called", |
| 250 | + async () => { |
| 251 | + await runAiTest("Test action handler is called", async () => { |
| 252 | + const testAction = runtime.actions.find( |
| 253 | + (action) => action.name === "TEST_ACTION" |
248 | 254 | );
|
249 |
| - return false; // Return false to indicate the test setup failed |
250 |
| - } |
251 |
| - |
252 |
| - const mockMessage: Memory = { |
253 |
| - userId: user.id as UUID, |
254 |
| - agentId: runtime.agentId, |
255 |
| - content: { |
256 |
| - text: "Test message for TEST action", |
257 |
| - }, |
258 |
| - roomId, |
259 |
| - }; |
260 |
| - |
261 |
| - const response = await testAction.handler(runtime, mockMessage); |
262 |
| - return response !== undefined; // Return true if the handler returns a defined response |
263 |
| - }); |
264 |
| - }, 60000); // You can adjust the timeout if needed |
| 255 | + if (!testAction || !testAction.handler) { |
| 256 | + console.error( |
| 257 | + "Continue action or its handler function is undefined" |
| 258 | + ); |
| 259 | + return false; // Return false to indicate the test setup failed |
| 260 | + } |
| 261 | + |
| 262 | + const mockMessage: Memory = { |
| 263 | + userId: user.id as UUID, |
| 264 | + agentId: runtime.agentId, |
| 265 | + content: { |
| 266 | + text: "Test message for TEST action", |
| 267 | + }, |
| 268 | + roomId, |
| 269 | + }; |
| 270 | + |
| 271 | + const response = await testAction.handler(runtime, mockMessage); |
| 272 | + return response !== undefined; // Return true if the handler returns a defined response |
| 273 | + }); |
| 274 | + }, |
| 275 | + { timeout: 60000 } |
| 276 | + ); // You can adjust the timeout if needed |
265 | 277 | });
|
0 commit comments