@elizaos/test-utils 1.4.4 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +289 -523
- package/dist/index.js.map +25 -1
- package/dist/src/DatabaseTestRegistry.d.ts +88 -0
- package/dist/src/DatabaseTestRegistry.d.ts.map +1 -0
- package/dist/src/TestInfrastructure.d.ts +64 -0
- package/dist/src/TestInfrastructure.d.ts.map +1 -0
- package/dist/src/factories.d.ts +141 -0
- package/dist/src/factories.d.ts.map +1 -0
- package/dist/src/index.d.ts +52 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/mocks/character.d.ts +65 -0
- package/dist/src/mocks/character.d.ts.map +1 -0
- package/dist/src/mocks/database.d.ts +40 -0
- package/dist/src/mocks/database.d.ts.map +1 -0
- package/dist/src/mocks/memory.d.ts +106 -0
- package/dist/src/mocks/memory.d.ts.map +1 -0
- package/dist/src/mocks/mockUtils.d.ts +17 -0
- package/dist/src/mocks/mockUtils.d.ts.map +1 -0
- package/dist/src/mocks/runtime.d.ts +34 -0
- package/dist/src/mocks/runtime.d.ts.map +1 -0
- package/dist/src/mocks/services.d.ts +99 -0
- package/dist/src/mocks/services.d.ts.map +1 -0
- package/dist/src/mocks/state.d.ts +100 -0
- package/dist/src/mocks/state.d.ts.map +1 -0
- package/dist/src/realRuntime.d.ts +85 -0
- package/dist/src/realRuntime.d.ts.map +1 -0
- package/dist/src/templates.d.ts +123 -0
- package/dist/src/templates.d.ts.map +1 -0
- package/dist/src/testDatabase.d.ts +44 -0
- package/dist/src/testDatabase.d.ts.map +1 -0
- package/dist/src/testModels.d.ts +105 -0
- package/dist/src/testModels.d.ts.map +1 -0
- package/dist/src/unifiedTestSuite.d.ts +40 -0
- package/dist/src/unifiedTestSuite.d.ts.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/package.json +6 -7
- package/dist/index.d.ts +0 -950
- package/tsup.config.ts +0 -20
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { AgentRuntime, logger as logger3, stringToUuid } from "@elizaos/core";
|
|
|
3
3
|
|
|
4
4
|
// ../../node_modules/uuid/dist/esm/stringify.js
|
|
5
5
|
var byteToHex = [];
|
|
6
|
-
for (let i = 0;
|
|
6
|
+
for (let i = 0;i < 256; ++i) {
|
|
7
7
|
byteToHex.push((i + 256).toString(16).slice(1));
|
|
8
8
|
}
|
|
9
9
|
function unsafeStringify(arr, offset = 0) {
|
|
@@ -43,7 +43,7 @@ function v4(options, buf, offset) {
|
|
|
43
43
|
if (offset < 0 || offset + 16 > buf.length) {
|
|
44
44
|
throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
|
|
45
45
|
}
|
|
46
|
-
for (let i = 0;
|
|
46
|
+
for (let i = 0;i < 16; ++i) {
|
|
47
47
|
buf[offset + i] = rnds[i];
|
|
48
48
|
}
|
|
49
49
|
return buf;
|
|
@@ -51,16 +51,11 @@ function v4(options, buf, offset) {
|
|
|
51
51
|
return unsafeStringify(rnds);
|
|
52
52
|
}
|
|
53
53
|
var v4_default = v4;
|
|
54
|
-
|
|
55
54
|
// src/testDatabase.ts
|
|
56
55
|
import { logger } from "@elizaos/core";
|
|
57
|
-
|
|
58
|
-
testDatabases =
|
|
59
|
-
tempPaths =
|
|
60
|
-
/**
|
|
61
|
-
* Creates an isolated database for testing
|
|
62
|
-
* Uses PostgreSQL for testing when available, falls back to mock database
|
|
63
|
-
*/
|
|
56
|
+
class TestDatabaseManager {
|
|
57
|
+
testDatabases = new Map;
|
|
58
|
+
tempPaths = new Set;
|
|
64
59
|
async createIsolatedDatabase(testId) {
|
|
65
60
|
try {
|
|
66
61
|
logger.debug(`Creating isolated test database for ${testId}`);
|
|
@@ -80,24 +75,17 @@ var TestDatabaseManager = class {
|
|
|
80
75
|
if (!postgresUrl) {
|
|
81
76
|
throw new Error("PostgreSQL URL not available - falling back to mock database");
|
|
82
77
|
}
|
|
83
|
-
adapter = await sqlPlugin.createDatabaseAdapter(
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
},
|
|
87
|
-
"11111111-2222-3333-4444-555555555555"
|
|
88
|
-
);
|
|
78
|
+
adapter = await sqlPlugin.createDatabaseAdapter({
|
|
79
|
+
postgresUrl
|
|
80
|
+
}, "11111111-2222-3333-4444-555555555555");
|
|
89
81
|
logger.debug(`Successfully created PostgreSQL adapter for ${testId}`);
|
|
90
82
|
} catch (importError) {
|
|
91
|
-
logger.warn(
|
|
92
|
-
`SQL plugin not available: ${importError instanceof Error ? importError.message : String(importError)} - falling back to mock database`
|
|
93
|
-
);
|
|
83
|
+
logger.warn(`SQL plugin not available: ${importError instanceof Error ? importError.message : String(importError)} - falling back to mock database`);
|
|
94
84
|
adapter = this.createMockDatabase(testId);
|
|
95
85
|
}
|
|
96
86
|
}
|
|
97
87
|
} catch (postgresError) {
|
|
98
|
-
logger.warn(
|
|
99
|
-
`Failed to create PostgreSQL database: ${postgresError instanceof Error ? postgresError.message : String(postgresError)} - falling back to mock database`
|
|
100
|
-
);
|
|
88
|
+
logger.warn(`Failed to create PostgreSQL database: ${postgresError instanceof Error ? postgresError.message : String(postgresError)} - falling back to mock database`);
|
|
101
89
|
adapter = this.createMockDatabase(testId);
|
|
102
90
|
}
|
|
103
91
|
await adapter.init();
|
|
@@ -105,42 +93,32 @@ var TestDatabaseManager = class {
|
|
|
105
93
|
logger.debug(`Successfully created isolated database for ${testId}`);
|
|
106
94
|
return adapter;
|
|
107
95
|
} catch (error) {
|
|
108
|
-
logger.error(
|
|
109
|
-
|
|
110
|
-
);
|
|
111
|
-
throw new Error(
|
|
112
|
-
`Test database creation failed: ${error instanceof Error ? error.message : String(error)}`
|
|
113
|
-
);
|
|
96
|
+
logger.error(`Failed to create test database for ${testId}: ${error instanceof Error ? error.message : String(error)}`);
|
|
97
|
+
throw new Error(`Test database creation failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
114
98
|
}
|
|
115
99
|
}
|
|
116
|
-
/**
|
|
117
|
-
* Creates a minimal mock database adapter for testing when real database unavailable
|
|
118
|
-
* This is a FUNCTIONAL mock that actually stores data in memory
|
|
119
|
-
*/
|
|
120
100
|
createMockDatabase(testId) {
|
|
121
101
|
const storage = {
|
|
122
|
-
agents:
|
|
123
|
-
entities:
|
|
124
|
-
memories:
|
|
125
|
-
relationships:
|
|
126
|
-
rooms:
|
|
127
|
-
participants:
|
|
128
|
-
cache:
|
|
129
|
-
worlds:
|
|
130
|
-
tasks:
|
|
131
|
-
logs:
|
|
102
|
+
agents: new Map,
|
|
103
|
+
entities: new Map,
|
|
104
|
+
memories: new Map,
|
|
105
|
+
relationships: new Map,
|
|
106
|
+
rooms: new Map,
|
|
107
|
+
participants: new Map,
|
|
108
|
+
cache: new Map,
|
|
109
|
+
worlds: new Map,
|
|
110
|
+
tasks: new Map,
|
|
111
|
+
logs: new Map
|
|
132
112
|
};
|
|
133
113
|
const adapter = {
|
|
134
114
|
db: null,
|
|
135
|
-
// Mock database instance
|
|
136
115
|
async initialize() {
|
|
137
116
|
logger.debug(`Initialized mock database for ${testId}`);
|
|
138
117
|
},
|
|
139
118
|
async init() {
|
|
140
119
|
logger.debug(`Initialized mock database for ${testId}`);
|
|
141
120
|
},
|
|
142
|
-
async runMigrations() {
|
|
143
|
-
},
|
|
121
|
+
async runMigrations() {},
|
|
144
122
|
async isReady() {
|
|
145
123
|
return true;
|
|
146
124
|
},
|
|
@@ -158,8 +136,7 @@ var TestDatabaseManager = class {
|
|
|
158
136
|
async getConnection() {
|
|
159
137
|
return null;
|
|
160
138
|
},
|
|
161
|
-
async ensureEmbeddingDimension() {
|
|
162
|
-
},
|
|
139
|
+
async ensureEmbeddingDimension() {},
|
|
163
140
|
async getAgent(agentId) {
|
|
164
141
|
return storage.agents.get(agentId) || null;
|
|
165
142
|
},
|
|
@@ -182,7 +159,6 @@ var TestDatabaseManager = class {
|
|
|
182
159
|
async deleteAgent(agentId) {
|
|
183
160
|
return storage.agents.delete(agentId);
|
|
184
161
|
},
|
|
185
|
-
// Entity operations
|
|
186
162
|
async createEntity(entity) {
|
|
187
163
|
const id = entity.id || v4_default();
|
|
188
164
|
const fullEntity = { ...entity, id };
|
|
@@ -207,9 +183,7 @@ var TestDatabaseManager = class {
|
|
|
207
183
|
storage.entities.set(entity.id, entity);
|
|
208
184
|
},
|
|
209
185
|
async getEntitiesForRoom(roomId) {
|
|
210
|
-
const participants = Array.from(storage.participants.values()).filter(
|
|
211
|
-
(p) => p.roomId === roomId
|
|
212
|
-
);
|
|
186
|
+
const participants = Array.from(storage.participants.values()).filter((p) => p.roomId === roomId);
|
|
213
187
|
const entities = [];
|
|
214
188
|
for (const participant of participants) {
|
|
215
189
|
const entity = storage.entities.get(participant.entityId);
|
|
@@ -219,7 +193,6 @@ var TestDatabaseManager = class {
|
|
|
219
193
|
}
|
|
220
194
|
return entities;
|
|
221
195
|
},
|
|
222
|
-
// Memory operations
|
|
223
196
|
async createMemory(memory, tableName = "messages", _unique = false) {
|
|
224
197
|
const id = memory.id || v4_default();
|
|
225
198
|
const fullMemory = {
|
|
@@ -228,7 +201,7 @@ var TestDatabaseManager = class {
|
|
|
228
201
|
createdAt: memory.createdAt || Date.now()
|
|
229
202
|
};
|
|
230
203
|
if (!storage.memories.has(tableName)) {
|
|
231
|
-
storage.memories.set(tableName,
|
|
204
|
+
storage.memories.set(tableName, new Map);
|
|
232
205
|
}
|
|
233
206
|
storage.memories.get(tableName).set(id, fullMemory);
|
|
234
207
|
return id;
|
|
@@ -263,9 +236,7 @@ var TestDatabaseManager = class {
|
|
|
263
236
|
memories = memories.filter((m) => m.roomId === params.roomId);
|
|
264
237
|
}
|
|
265
238
|
if (params.query) {
|
|
266
|
-
memories = memories.filter(
|
|
267
|
-
(m) => m.content?.text?.toLowerCase().includes(params.query.toLowerCase())
|
|
268
|
-
);
|
|
239
|
+
memories = memories.filter((m) => m.content?.text?.toLowerCase().includes(params.query.toLowerCase()));
|
|
269
240
|
}
|
|
270
241
|
return memories.slice(0, params.count || 10);
|
|
271
242
|
},
|
|
@@ -297,9 +268,7 @@ var TestDatabaseManager = class {
|
|
|
297
268
|
if (!tableData) {
|
|
298
269
|
return [];
|
|
299
270
|
}
|
|
300
|
-
let memories = Array.from(tableData.values()).filter(
|
|
301
|
-
(m) => params.roomIds.includes(m.roomId)
|
|
302
|
-
);
|
|
271
|
+
let memories = Array.from(tableData.values()).filter((m) => params.roomIds.includes(m.roomId));
|
|
303
272
|
if (params.limit) {
|
|
304
273
|
memories = memories.slice(0, params.limit);
|
|
305
274
|
}
|
|
@@ -310,13 +279,13 @@ var TestDatabaseManager = class {
|
|
|
310
279
|
},
|
|
311
280
|
async log(params) {
|
|
312
281
|
if (!storage.logs) {
|
|
313
|
-
storage.logs =
|
|
282
|
+
storage.logs = new Map;
|
|
314
283
|
}
|
|
315
284
|
const logId = v4_default();
|
|
316
285
|
storage.logs.set(logId, {
|
|
317
286
|
id: logId,
|
|
318
287
|
...params,
|
|
319
|
-
createdAt:
|
|
288
|
+
createdAt: new Date
|
|
320
289
|
});
|
|
321
290
|
},
|
|
322
291
|
async getLogs() {
|
|
@@ -332,7 +301,6 @@ var TestDatabaseManager = class {
|
|
|
332
301
|
}
|
|
333
302
|
return false;
|
|
334
303
|
},
|
|
335
|
-
// Room operations
|
|
336
304
|
async createRoom(room) {
|
|
337
305
|
const id = room.id || v4_default();
|
|
338
306
|
const fullRoom = { ...room, id };
|
|
@@ -342,11 +310,8 @@ var TestDatabaseManager = class {
|
|
|
342
310
|
return storage.rooms.get(roomId) || null;
|
|
343
311
|
},
|
|
344
312
|
async getRooms(worldId) {
|
|
345
|
-
return Array.from(storage.rooms.values()).filter(
|
|
346
|
-
(room) => !worldId || room.worldId === worldId
|
|
347
|
-
);
|
|
313
|
+
return Array.from(storage.rooms.values()).filter((room) => !worldId || room.worldId === worldId);
|
|
348
314
|
},
|
|
349
|
-
// Participant operations
|
|
350
315
|
async addParticipant(entityId, roomId) {
|
|
351
316
|
const participantId = `${entityId}-${roomId}`;
|
|
352
317
|
storage.participants.set(participantId, { entityId, roomId });
|
|
@@ -359,7 +324,6 @@ var TestDatabaseManager = class {
|
|
|
359
324
|
async getParticipantsForRoom(roomId) {
|
|
360
325
|
return Array.from(storage.participants.values()).filter((p) => p.roomId === roomId).map((p) => p.entityId);
|
|
361
326
|
},
|
|
362
|
-
// Cache operations
|
|
363
327
|
async setCache(key, value) {
|
|
364
328
|
storage.cache.set(key, {
|
|
365
329
|
value,
|
|
@@ -374,7 +338,6 @@ var TestDatabaseManager = class {
|
|
|
374
338
|
async deleteCache(key) {
|
|
375
339
|
return storage.cache.delete(key);
|
|
376
340
|
},
|
|
377
|
-
// World operations
|
|
378
341
|
async createWorld(world) {
|
|
379
342
|
const id = world.id || v4_default();
|
|
380
343
|
const fullWorld = { ...world, id };
|
|
@@ -387,7 +350,6 @@ var TestDatabaseManager = class {
|
|
|
387
350
|
async getAllWorlds() {
|
|
388
351
|
return Array.from(storage.worlds.values());
|
|
389
352
|
},
|
|
390
|
-
// Task operations
|
|
391
353
|
async createTask(task) {
|
|
392
354
|
const id = task.id || v4_default();
|
|
393
355
|
const fullTask = {
|
|
@@ -404,16 +366,13 @@ var TestDatabaseManager = class {
|
|
|
404
366
|
tasks = tasks.filter((task) => task.roomId === params.roomId);
|
|
405
367
|
}
|
|
406
368
|
if (params.tags) {
|
|
407
|
-
tasks = tasks.filter(
|
|
408
|
-
(task) => params.tags.some((tag) => task.tags.includes(tag))
|
|
409
|
-
);
|
|
369
|
+
tasks = tasks.filter((task) => params.tags.some((tag) => task.tags.includes(tag)));
|
|
410
370
|
}
|
|
411
371
|
return tasks;
|
|
412
372
|
},
|
|
413
373
|
async deleteTask(taskId) {
|
|
414
374
|
storage.tasks.delete(taskId);
|
|
415
375
|
},
|
|
416
|
-
// Relationship operations
|
|
417
376
|
async createRelationship(relationship) {
|
|
418
377
|
const id = v4_default();
|
|
419
378
|
const fullRelationship = { ...relationship, id };
|
|
@@ -423,9 +382,7 @@ var TestDatabaseManager = class {
|
|
|
423
382
|
async getRelationships(params) {
|
|
424
383
|
let relationships = Array.from(storage.relationships.values());
|
|
425
384
|
if (params.entityId) {
|
|
426
|
-
relationships = relationships.filter(
|
|
427
|
-
(rel) => rel.sourceEntityId === params.entityId || rel.targetEntityId === params.entityId
|
|
428
|
-
);
|
|
385
|
+
relationships = relationships.filter((rel) => rel.sourceEntityId === params.entityId || rel.targetEntityId === params.entityId);
|
|
429
386
|
}
|
|
430
387
|
return relationships;
|
|
431
388
|
},
|
|
@@ -584,20 +541,16 @@ var TestDatabaseManager = class {
|
|
|
584
541
|
if (!entity?.components) {
|
|
585
542
|
return null;
|
|
586
543
|
}
|
|
587
|
-
return entity.components.find(
|
|
588
|
-
(c) => c.type === type && (!worldId || c.worldId === worldId) && (!sourceEntityId || c.sourceEntityId === sourceEntityId)
|
|
589
|
-
) || null;
|
|
544
|
+
return entity.components.find((c) => c.type === type && (!worldId || c.worldId === worldId) && (!sourceEntityId || c.sourceEntityId === sourceEntityId)) || null;
|
|
590
545
|
},
|
|
591
546
|
async getParticipantsForEntity(entityId) {
|
|
592
|
-
return Array.from(storage.participants.values()).filter(
|
|
593
|
-
(p) => p.entityId === entityId
|
|
594
|
-
);
|
|
547
|
+
return Array.from(storage.participants.values()).filter((p) => p.entityId === entityId);
|
|
595
548
|
},
|
|
596
549
|
async getRoomsForParticipant(entityId) {
|
|
597
550
|
return Array.from(storage.participants.values()).filter((p) => p.entityId === entityId).map((p) => p.roomId);
|
|
598
551
|
},
|
|
599
552
|
async getRoomsForParticipants(userIds) {
|
|
600
|
-
const roomIds =
|
|
553
|
+
const roomIds = new Set;
|
|
601
554
|
for (const participant of storage.participants.values()) {
|
|
602
555
|
if (userIds.includes(participant.entityId)) {
|
|
603
556
|
roomIds.add(participant.roomId);
|
|
@@ -608,13 +561,10 @@ var TestDatabaseManager = class {
|
|
|
608
561
|
async getParticipantUserState(_roomId, _entityId) {
|
|
609
562
|
return null;
|
|
610
563
|
},
|
|
611
|
-
async setParticipantUserState(_roomId, _entityId, _state) {
|
|
612
|
-
},
|
|
564
|
+
async setParticipantUserState(_roomId, _entityId, _state) {},
|
|
613
565
|
async getRelationship(params) {
|
|
614
566
|
const relationships = Array.from(storage.relationships.values());
|
|
615
|
-
return relationships.find(
|
|
616
|
-
(r) => r.sourceEntityId === params.sourceEntityId && r.targetEntityId === params.targetEntityId
|
|
617
|
-
) || null;
|
|
567
|
+
return relationships.find((r) => r.sourceEntityId === params.sourceEntityId && r.targetEntityId === params.targetEntityId) || null;
|
|
618
568
|
},
|
|
619
569
|
async updateRelationship(relationship) {
|
|
620
570
|
if (!relationship.id || !storage.relationships.has(relationship.id)) {
|
|
@@ -647,9 +597,7 @@ var TestDatabaseManager = class {
|
|
|
647
597
|
if (!tableData) {
|
|
648
598
|
return [];
|
|
649
599
|
}
|
|
650
|
-
let memories = Array.from(tableData.values()).filter(
|
|
651
|
-
(m) => m.worldId === params.worldId
|
|
652
|
-
);
|
|
600
|
+
let memories = Array.from(tableData.values()).filter((m) => m.worldId === params.worldId);
|
|
653
601
|
if (params.count) {
|
|
654
602
|
memories = memories.slice(0, params.count);
|
|
655
603
|
}
|
|
@@ -687,9 +635,6 @@ var TestDatabaseManager = class {
|
|
|
687
635
|
};
|
|
688
636
|
return adapter;
|
|
689
637
|
}
|
|
690
|
-
/**
|
|
691
|
-
* Cleanup a specific test database
|
|
692
|
-
*/
|
|
693
638
|
async cleanupDatabase(testId) {
|
|
694
639
|
try {
|
|
695
640
|
const adapter = this.testDatabases.get(testId);
|
|
@@ -699,27 +644,17 @@ var TestDatabaseManager = class {
|
|
|
699
644
|
logger.debug(`Cleaned up database for ${testId}`);
|
|
700
645
|
}
|
|
701
646
|
} catch (error) {
|
|
702
|
-
logger.warn(
|
|
703
|
-
`Error cleaning up database ${testId}: ${error instanceof Error ? error.message : String(error)}`
|
|
704
|
-
);
|
|
647
|
+
logger.warn(`Error cleaning up database ${testId}: ${error instanceof Error ? error.message : String(error)}`);
|
|
705
648
|
}
|
|
706
649
|
}
|
|
707
|
-
/**
|
|
708
|
-
* Cleanup all test databases
|
|
709
|
-
*/
|
|
710
650
|
async cleanup() {
|
|
711
651
|
logger.debug("Cleaning up all test databases");
|
|
712
|
-
const cleanupPromises = Array.from(this.testDatabases.keys()).map(
|
|
713
|
-
(testId) => this.cleanupDatabase(testId)
|
|
714
|
-
);
|
|
652
|
+
const cleanupPromises = Array.from(this.testDatabases.keys()).map((testId) => this.cleanupDatabase(testId));
|
|
715
653
|
await Promise.all(cleanupPromises);
|
|
716
654
|
this.tempPaths.clear();
|
|
717
655
|
this.testDatabases.clear();
|
|
718
656
|
logger.debug("Successfully cleaned up all test databases");
|
|
719
657
|
}
|
|
720
|
-
/**
|
|
721
|
-
* Get statistics about test databases
|
|
722
|
-
*/
|
|
723
658
|
getStats() {
|
|
724
659
|
return {
|
|
725
660
|
activeDatabases: this.testDatabases.size,
|
|
@@ -727,18 +662,19 @@ var TestDatabaseManager = class {
|
|
|
727
662
|
memoryUsage: `${Math.round(process.memoryUsage().heapUsed / 1024 / 1024)}MB`
|
|
728
663
|
};
|
|
729
664
|
}
|
|
730
|
-
}
|
|
665
|
+
}
|
|
731
666
|
async function createTestDatabase(testId) {
|
|
732
667
|
const actualTestId = testId || `test-${v4_default().slice(0, 8)}`;
|
|
733
|
-
const manager = new TestDatabaseManager
|
|
668
|
+
const manager = new TestDatabaseManager;
|
|
734
669
|
const adapter = await manager.createIsolatedDatabase(actualTestId);
|
|
735
670
|
return { adapter, manager, testId: actualTestId };
|
|
736
671
|
}
|
|
737
672
|
|
|
738
673
|
// src/testModels.ts
|
|
739
674
|
import { logger as logger2 } from "@elizaos/core";
|
|
740
|
-
|
|
741
|
-
|
|
675
|
+
|
|
676
|
+
class TestModelProvider {
|
|
677
|
+
responses = new Map;
|
|
742
678
|
patterns = [];
|
|
743
679
|
defaultResponse;
|
|
744
680
|
contextHistory = [];
|
|
@@ -746,12 +682,8 @@ var TestModelProvider = class {
|
|
|
746
682
|
this.defaultResponse = defaultResponse;
|
|
747
683
|
this.addDefaultPatterns();
|
|
748
684
|
}
|
|
749
|
-
/**
|
|
750
|
-
* Add realistic default response patterns
|
|
751
|
-
*/
|
|
752
685
|
addDefaultPatterns() {
|
|
753
686
|
const defaultPatterns = [
|
|
754
|
-
// Greeting patterns
|
|
755
687
|
{
|
|
756
688
|
pattern: /^(hello|hi|hey|greetings)/i,
|
|
757
689
|
response: "Hello! How can I help you today?"
|
|
@@ -760,7 +692,6 @@ var TestModelProvider = class {
|
|
|
760
692
|
pattern: /(good morning|good afternoon|good evening)/i,
|
|
761
693
|
response: "Good day! What can I assist you with?"
|
|
762
694
|
},
|
|
763
|
-
// Task creation patterns
|
|
764
695
|
{
|
|
765
696
|
pattern: /(create|add|make).*?(todo|task|reminder)/i,
|
|
766
697
|
response: "I'll create that task for you right away. Let me add it to your todo list."
|
|
@@ -769,7 +700,6 @@ var TestModelProvider = class {
|
|
|
769
700
|
pattern: /(schedule|plan|organize)/i,
|
|
770
701
|
response: "I'll help you schedule that. Let me organize this for you."
|
|
771
702
|
},
|
|
772
|
-
// Information requests
|
|
773
703
|
{
|
|
774
704
|
pattern: /(search|find|look|query).*?(for|about)/i,
|
|
775
705
|
response: "Let me search for that information. I'll look into it right away."
|
|
@@ -778,7 +708,6 @@ var TestModelProvider = class {
|
|
|
778
708
|
pattern: /(what|how|when|where|why)/i,
|
|
779
709
|
response: "Let me find that information for you. I'll provide a detailed answer."
|
|
780
710
|
},
|
|
781
|
-
// Analysis and review
|
|
782
711
|
{
|
|
783
712
|
pattern: /(analyze|review|examine|check)/i,
|
|
784
713
|
response: "I'll analyze this carefully and provide my assessment with detailed insights."
|
|
@@ -787,7 +716,6 @@ var TestModelProvider = class {
|
|
|
787
716
|
pattern: /(explain|describe|tell me about)/i,
|
|
788
717
|
response: "I'll explain that in detail for you. Here's what you need to know."
|
|
789
718
|
},
|
|
790
|
-
// Action requests
|
|
791
719
|
{
|
|
792
720
|
pattern: /(send|email|message|notify)/i,
|
|
793
721
|
response: "I'll send that message for you. Let me take care of the communication."
|
|
@@ -796,7 +724,6 @@ var TestModelProvider = class {
|
|
|
796
724
|
pattern: /(delete|remove|cancel)/i,
|
|
797
725
|
response: "I'll remove that for you. Let me handle the deletion safely."
|
|
798
726
|
},
|
|
799
|
-
// File and data operations
|
|
800
727
|
{
|
|
801
728
|
pattern: /(save|store|backup)/i,
|
|
802
729
|
response: "I'll save that information securely. Your data will be stored properly."
|
|
@@ -805,7 +732,6 @@ var TestModelProvider = class {
|
|
|
805
732
|
pattern: /(load|open|access)/i,
|
|
806
733
|
response: "I'll access that resource for you. Let me retrieve the information."
|
|
807
734
|
},
|
|
808
|
-
// Problem solving
|
|
809
735
|
{
|
|
810
736
|
pattern: /(fix|repair|solve|troubleshoot)/i,
|
|
811
737
|
response: "I'll help troubleshoot this issue. Let me analyze the problem and find a solution."
|
|
@@ -814,7 +740,6 @@ var TestModelProvider = class {
|
|
|
814
740
|
pattern: /(help|assist|support)/i,
|
|
815
741
|
response: "I'm here to help! Let me assist you with whatever you need."
|
|
816
742
|
},
|
|
817
|
-
// Decision making
|
|
818
743
|
{
|
|
819
744
|
pattern: /(should|recommend|suggest|advise)/i,
|
|
820
745
|
response: "Based on the information provided, I'd recommend the following approach."
|
|
@@ -823,7 +748,6 @@ var TestModelProvider = class {
|
|
|
823
748
|
pattern: /(choose|select|decide)/i,
|
|
824
749
|
response: "Let me help you make that decision. Here are the key factors to consider."
|
|
825
750
|
},
|
|
826
|
-
// Confirmation and acknowledgment
|
|
827
751
|
{
|
|
828
752
|
pattern: /(yes|ok|okay|sure|agreed)/i,
|
|
829
753
|
response: "Understood! I'll proceed with that as requested."
|
|
@@ -832,7 +756,6 @@ var TestModelProvider = class {
|
|
|
832
756
|
pattern: /(no|stop|cancel|abort)/i,
|
|
833
757
|
response: "Alright, I'll stop that process. Is there anything else I can help with?"
|
|
834
758
|
},
|
|
835
|
-
// Complex reasoning patterns
|
|
836
759
|
{
|
|
837
760
|
pattern: /(if.*then|because|therefore|since)/i,
|
|
838
761
|
response: "I understand the logic. Let me work through this step by step."
|
|
@@ -841,7 +764,6 @@ var TestModelProvider = class {
|
|
|
841
764
|
pattern: /(compare|contrast|difference|similar)/i,
|
|
842
765
|
response: "I'll compare these options and highlight the key differences and similarities."
|
|
843
766
|
},
|
|
844
|
-
// Error handling
|
|
845
767
|
{
|
|
846
768
|
pattern: /(error|problem|issue|broken|failed)/i,
|
|
847
769
|
response: "I see there's an issue. Let me investigate the problem and find a solution."
|
|
@@ -849,9 +771,6 @@ var TestModelProvider = class {
|
|
|
849
771
|
];
|
|
850
772
|
this.patterns.push(...defaultPatterns);
|
|
851
773
|
}
|
|
852
|
-
/**
|
|
853
|
-
* Generate text response based on prompt
|
|
854
|
-
*/
|
|
855
774
|
async generateText(params) {
|
|
856
775
|
const prompt = params.prompt;
|
|
857
776
|
try {
|
|
@@ -871,28 +790,20 @@ var TestModelProvider = class {
|
|
|
871
790
|
this.addToHistory(prompt, intelligentResponse);
|
|
872
791
|
return intelligentResponse;
|
|
873
792
|
} catch (error) {
|
|
874
|
-
logger2.warn(
|
|
875
|
-
`Error in test model provider: ${error instanceof Error ? error.message : String(error)}`
|
|
876
|
-
);
|
|
793
|
+
logger2.warn(`Error in test model provider: ${error instanceof Error ? error.message : String(error)}`);
|
|
877
794
|
return this.defaultResponse;
|
|
878
795
|
}
|
|
879
796
|
}
|
|
880
|
-
/**
|
|
881
|
-
* Generate embeddings for text (mock implementation with consistent vectors)
|
|
882
|
-
*/
|
|
883
797
|
async generateEmbedding(params) {
|
|
884
798
|
const text = params.text;
|
|
885
799
|
const hash = this.simpleHash(text);
|
|
886
800
|
const embedding = [];
|
|
887
|
-
for (let i = 0;
|
|
801
|
+
for (let i = 0;i < 1536; i++) {
|
|
888
802
|
const value = Math.sin(hash + i) * 0.5;
|
|
889
803
|
embedding.push(value);
|
|
890
804
|
}
|
|
891
805
|
return embedding;
|
|
892
806
|
}
|
|
893
|
-
/**
|
|
894
|
-
* Generate object-structured responses
|
|
895
|
-
*/
|
|
896
807
|
async generateObject(params) {
|
|
897
808
|
const prompt = params.prompt;
|
|
898
809
|
if (prompt.includes("thought") || prompt.includes("reasoning")) {
|
|
@@ -925,23 +836,14 @@ var TestModelProvider = class {
|
|
|
925
836
|
}
|
|
926
837
|
};
|
|
927
838
|
}
|
|
928
|
-
/**
|
|
929
|
-
* Make response more contextual based on prompt content
|
|
930
|
-
*/
|
|
931
839
|
makeContextual(response, prompt) {
|
|
932
840
|
const keyTerms = this.extractKeyTerms(prompt);
|
|
933
841
|
if (keyTerms.length > 0) {
|
|
934
842
|
const term = keyTerms[0];
|
|
935
|
-
return response.replace(
|
|
936
|
-
/that|this|it/g,
|
|
937
|
-
term.length > 20 ? `that ${term.substring(0, 20)}...` : `that ${term}`
|
|
938
|
-
);
|
|
843
|
+
return response.replace(/that|this|it/g, term.length > 20 ? `that ${term.substring(0, 20)}...` : `that ${term}`);
|
|
939
844
|
}
|
|
940
845
|
return response;
|
|
941
846
|
}
|
|
942
|
-
/**
|
|
943
|
-
* Generate intelligent default response based on prompt analysis
|
|
944
|
-
*/
|
|
945
847
|
generateIntelligentDefault(prompt) {
|
|
946
848
|
const lowerPrompt = prompt.toLowerCase();
|
|
947
849
|
if (lowerPrompt.includes("?")) {
|
|
@@ -958,11 +860,8 @@ var TestModelProvider = class {
|
|
|
958
860
|
}
|
|
959
861
|
return this.defaultResponse;
|
|
960
862
|
}
|
|
961
|
-
/**
|
|
962
|
-
* Extract key terms from prompt for contextualization
|
|
963
|
-
*/
|
|
964
863
|
extractKeyTerms(prompt) {
|
|
965
|
-
const commonWords =
|
|
864
|
+
const commonWords = new Set([
|
|
966
865
|
"the",
|
|
967
866
|
"a",
|
|
968
867
|
"an",
|
|
@@ -1013,64 +912,43 @@ var TestModelProvider = class {
|
|
|
1013
912
|
const words = prompt.toLowerCase().replace(/[^\w\s]/g, " ").split(/\s+/).filter((word) => word.length > 2 && !commonWords.has(word));
|
|
1014
913
|
return [...new Set(words)].slice(0, 3);
|
|
1015
914
|
}
|
|
1016
|
-
/**
|
|
1017
|
-
* Simple hash function for deterministic embeddings
|
|
1018
|
-
*/
|
|
1019
915
|
simpleHash(str) {
|
|
1020
916
|
let hash = 0;
|
|
1021
|
-
for (let i = 0;
|
|
917
|
+
for (let i = 0;i < str.length; i++) {
|
|
1022
918
|
const char = str.charCodeAt(i);
|
|
1023
919
|
hash = (hash << 5) - hash + char;
|
|
1024
920
|
hash = hash & hash;
|
|
1025
921
|
}
|
|
1026
922
|
return Math.abs(hash);
|
|
1027
923
|
}
|
|
1028
|
-
/**
|
|
1029
|
-
* Add interaction to context history
|
|
1030
|
-
*/
|
|
1031
924
|
addToHistory(prompt, response) {
|
|
1032
925
|
this.contextHistory.push({ prompt, response });
|
|
1033
926
|
if (this.contextHistory.length > 10) {
|
|
1034
927
|
this.contextHistory.shift();
|
|
1035
928
|
}
|
|
1036
929
|
}
|
|
1037
|
-
/**
|
|
1038
|
-
* Set a specific response for a prompt
|
|
1039
|
-
*/
|
|
1040
930
|
setResponse(prompt, response) {
|
|
1041
931
|
this.responses.set(prompt, response);
|
|
1042
932
|
}
|
|
1043
|
-
/**
|
|
1044
|
-
* Add a pattern-based response
|
|
1045
|
-
*/
|
|
1046
933
|
addPattern(pattern, response) {
|
|
1047
934
|
this.patterns.unshift({ pattern, response });
|
|
1048
935
|
}
|
|
1049
|
-
/**
|
|
1050
|
-
* Set the default response
|
|
1051
|
-
*/
|
|
1052
936
|
setDefaultResponse(response) {
|
|
1053
937
|
this.defaultResponse = response;
|
|
1054
938
|
}
|
|
1055
|
-
/**
|
|
1056
|
-
* Clear all custom responses and patterns
|
|
1057
|
-
*/
|
|
1058
939
|
clear() {
|
|
1059
940
|
this.responses.clear();
|
|
1060
941
|
this.patterns.length = 0;
|
|
1061
942
|
this.contextHistory.length = 0;
|
|
1062
943
|
this.addDefaultPatterns();
|
|
1063
944
|
}
|
|
1064
|
-
/**
|
|
1065
|
-
* Get conversation history
|
|
1066
|
-
*/
|
|
1067
945
|
getHistory() {
|
|
1068
946
|
return [...this.contextHistory];
|
|
1069
947
|
}
|
|
1070
|
-
}
|
|
1071
|
-
function createTestModelProvider(
|
|
948
|
+
}
|
|
949
|
+
function createTestModelProvider(scenarios = [], defaultResponse) {
|
|
1072
950
|
const provider = new TestModelProvider(defaultResponse);
|
|
1073
|
-
for (const scenario of
|
|
951
|
+
for (const scenario of scenarios) {
|
|
1074
952
|
if (scenario.prompt instanceof RegExp) {
|
|
1075
953
|
provider.addPattern(scenario.prompt, scenario.response);
|
|
1076
954
|
} else {
|
|
@@ -1080,31 +958,19 @@ function createTestModelProvider(scenarios2 = [], defaultResponse) {
|
|
|
1080
958
|
return provider;
|
|
1081
959
|
}
|
|
1082
960
|
function createSpecializedModelProvider(type) {
|
|
1083
|
-
const provider = new TestModelProvider
|
|
961
|
+
const provider = new TestModelProvider;
|
|
1084
962
|
switch (type) {
|
|
1085
963
|
case "conversational":
|
|
1086
|
-
provider.addPattern(
|
|
1087
|
-
/.*/,
|
|
1088
|
-
"That's interesting! Let me respond thoughtfully to what you've shared."
|
|
1089
|
-
);
|
|
964
|
+
provider.addPattern(/.*/, "That's interesting! Let me respond thoughtfully to what you've shared.");
|
|
1090
965
|
break;
|
|
1091
966
|
case "analytical":
|
|
1092
|
-
provider.addPattern(
|
|
1093
|
-
/.*/,
|
|
1094
|
-
"Let me analyze this systematically. Based on the data and context provided, here's my assessment."
|
|
1095
|
-
);
|
|
967
|
+
provider.addPattern(/.*/, "Let me analyze this systematically. Based on the data and context provided, here's my assessment.");
|
|
1096
968
|
break;
|
|
1097
969
|
case "creative":
|
|
1098
|
-
provider.addPattern(
|
|
1099
|
-
/.*/,
|
|
1100
|
-
"What a creative challenge! Let me think outside the box and explore innovative possibilities."
|
|
1101
|
-
);
|
|
970
|
+
provider.addPattern(/.*/, "What a creative challenge! Let me think outside the box and explore innovative possibilities.");
|
|
1102
971
|
break;
|
|
1103
972
|
case "factual":
|
|
1104
|
-
provider.addPattern(
|
|
1105
|
-
/.*/,
|
|
1106
|
-
"Based on factual information and established knowledge, here's an accurate response."
|
|
1107
|
-
);
|
|
973
|
+
provider.addPattern(/.*/, "Based on factual information and established knowledge, here's an accurate response.");
|
|
1108
974
|
break;
|
|
1109
975
|
}
|
|
1110
976
|
return provider;
|
|
@@ -1126,7 +992,8 @@ function createModelHandler(provider) {
|
|
|
1126
992
|
}
|
|
1127
993
|
};
|
|
1128
994
|
}
|
|
1129
|
-
|
|
995
|
+
|
|
996
|
+
class TestScenarioBuilder {
|
|
1130
997
|
scenarios = [];
|
|
1131
998
|
addGreeting(response = "Hello! How can I help you?") {
|
|
1132
999
|
this.scenarios.push({
|
|
@@ -1156,30 +1023,24 @@ var TestScenarioBuilder = class {
|
|
|
1156
1023
|
build(defaultResponse) {
|
|
1157
1024
|
return createTestModelProvider(this.scenarios, defaultResponse);
|
|
1158
1025
|
}
|
|
1159
|
-
}
|
|
1026
|
+
}
|
|
1160
1027
|
function scenarios() {
|
|
1161
|
-
return new TestScenarioBuilder
|
|
1028
|
+
return new TestScenarioBuilder;
|
|
1162
1029
|
}
|
|
1163
1030
|
|
|
1164
1031
|
// src/realRuntime.ts
|
|
1165
|
-
|
|
1166
|
-
runtimes =
|
|
1032
|
+
class RuntimeTestHarness {
|
|
1033
|
+
runtimes = new Map;
|
|
1167
1034
|
databaseManager;
|
|
1168
1035
|
testId;
|
|
1169
1036
|
constructor(testId) {
|
|
1170
1037
|
this.testId = testId || `test-${v4_default().slice(0, 8)}`;
|
|
1171
|
-
this.databaseManager = new TestDatabaseManager
|
|
1038
|
+
this.databaseManager = new TestDatabaseManager;
|
|
1172
1039
|
}
|
|
1173
|
-
/**
|
|
1174
|
-
* Creates an AgentRuntime instance for testing
|
|
1175
|
-
* This uses the standard AgentRuntime - it will actually execute all functionality
|
|
1176
|
-
*/
|
|
1177
1040
|
async createTestRuntime(config) {
|
|
1178
1041
|
try {
|
|
1179
1042
|
logger3.info(`Creating real test runtime for ${this.testId}`);
|
|
1180
|
-
const databaseAdapter = await this.databaseManager.createIsolatedDatabase(
|
|
1181
|
-
`${this.testId}-${Date.now()}`
|
|
1182
|
-
);
|
|
1043
|
+
const databaseAdapter = await this.databaseManager.createIsolatedDatabase(`${this.testId}-${Date.now()}`);
|
|
1183
1044
|
const runtime = new AgentRuntime({
|
|
1184
1045
|
character: config.character,
|
|
1185
1046
|
adapter: databaseAdapter
|
|
@@ -1197,18 +1058,10 @@ var RuntimeTestHarness = class {
|
|
|
1197
1058
|
logger3.info(`Successfully created real runtime ${runtime.agentId}`);
|
|
1198
1059
|
return runtime;
|
|
1199
1060
|
} catch (error) {
|
|
1200
|
-
logger3.error(
|
|
1201
|
-
|
|
1202
|
-
);
|
|
1203
|
-
throw new Error(
|
|
1204
|
-
`Test runtime creation failed: ${error instanceof Error ? error.message : String(error)}`
|
|
1205
|
-
);
|
|
1061
|
+
logger3.error(`Failed to create test runtime: ${error instanceof Error ? error.message : String(error)}`);
|
|
1062
|
+
throw new Error(`Test runtime creation failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
1206
1063
|
}
|
|
1207
1064
|
}
|
|
1208
|
-
/**
|
|
1209
|
-
* Loads a plugin by name from the ElizaOS ecosystem
|
|
1210
|
-
* Uses dynamic imports to avoid circular dependencies during build
|
|
1211
|
-
*/
|
|
1212
1065
|
async loadPlugin(pluginName) {
|
|
1213
1066
|
try {
|
|
1214
1067
|
logger3.info(`Attempting to load plugin: ${pluginName}`);
|
|
@@ -1216,9 +1069,7 @@ var RuntimeTestHarness = class {
|
|
|
1216
1069
|
try {
|
|
1217
1070
|
pluginModule = await import(pluginName);
|
|
1218
1071
|
} catch (importError) {
|
|
1219
|
-
logger3.warn(
|
|
1220
|
-
`Could not import ${pluginName}: ${importError instanceof Error ? importError.message : String(importError)}`
|
|
1221
|
-
);
|
|
1072
|
+
logger3.warn(`Could not import ${pluginName}: ${importError instanceof Error ? importError.message : String(importError)}`);
|
|
1222
1073
|
throw importError;
|
|
1223
1074
|
}
|
|
1224
1075
|
const plugin = pluginModule.default || pluginModule[Object.keys(pluginModule)[0]];
|
|
@@ -1228,17 +1079,10 @@ var RuntimeTestHarness = class {
|
|
|
1228
1079
|
logger3.info(`Successfully loaded plugin: ${pluginName}`);
|
|
1229
1080
|
return plugin;
|
|
1230
1081
|
} catch (error) {
|
|
1231
|
-
logger3.error(
|
|
1232
|
-
|
|
1233
|
-
);
|
|
1234
|
-
throw new Error(
|
|
1235
|
-
`Plugin ${pluginName} must be available for testing. Install it before running tests. Error: ${error instanceof Error ? error.message : String(error)}`
|
|
1236
|
-
);
|
|
1082
|
+
logger3.error(`Failed to load plugin ${pluginName}: ${error instanceof Error ? error.message : String(error)}`);
|
|
1083
|
+
throw new Error(`Plugin ${pluginName} must be available for testing. Install it before running tests. Error: ${error instanceof Error ? error.message : String(error)}`);
|
|
1237
1084
|
}
|
|
1238
1085
|
}
|
|
1239
|
-
/**
|
|
1240
|
-
* Creates a test model provider that gives realistic responses
|
|
1241
|
-
*/
|
|
1242
1086
|
createRealisticModelProvider(scenarios2) {
|
|
1243
1087
|
const defaultScenarios = [
|
|
1244
1088
|
{
|
|
@@ -1260,9 +1104,6 @@ var RuntimeTestHarness = class {
|
|
|
1260
1104
|
];
|
|
1261
1105
|
return createTestModelProvider(scenarios2 || defaultScenarios);
|
|
1262
1106
|
}
|
|
1263
|
-
/**
|
|
1264
|
-
* Executes a real message processing test
|
|
1265
|
-
*/
|
|
1266
1107
|
async processTestMessage(runtime, messageText, options = {}) {
|
|
1267
1108
|
const startTime = Date.now();
|
|
1268
1109
|
const roomId = options.roomId || stringToUuid(`test-room-${v4_default()}`);
|
|
@@ -1279,7 +1120,7 @@ var RuntimeTestHarness = class {
|
|
|
1279
1120
|
createdAt: Date.now()
|
|
1280
1121
|
};
|
|
1281
1122
|
const _messageId = await runtime.createMemory(memory, "messages");
|
|
1282
|
-
const responses = await runtime.processActions(memory, [],
|
|
1123
|
+
const responses = await runtime.processActions(memory, [], undefined, undefined);
|
|
1283
1124
|
const responseTime = Date.now() - startTime;
|
|
1284
1125
|
const result = {
|
|
1285
1126
|
scenarioName: `Process: "${messageText}"`,
|
|
@@ -1291,9 +1132,7 @@ var RuntimeTestHarness = class {
|
|
|
1291
1132
|
};
|
|
1292
1133
|
if (options.expectedActions && options.expectedActions.length > 0) {
|
|
1293
1134
|
const executedActions = await this.getExecutedActions(runtime, roomId);
|
|
1294
|
-
const missingActions = options.expectedActions.filter(
|
|
1295
|
-
(action) => !executedActions.includes(action)
|
|
1296
|
-
);
|
|
1135
|
+
const missingActions = options.expectedActions.filter((action) => !executedActions.includes(action));
|
|
1297
1136
|
if (missingActions.length > 0) {
|
|
1298
1137
|
result.passed = false;
|
|
1299
1138
|
result.errors.push(`Missing expected actions: ${missingActions.join(", ")}`);
|
|
@@ -1302,9 +1141,7 @@ var RuntimeTestHarness = class {
|
|
|
1302
1141
|
}
|
|
1303
1142
|
if (options.timeoutMs && responseTime > options.timeoutMs) {
|
|
1304
1143
|
result.passed = false;
|
|
1305
|
-
result.errors.push(
|
|
1306
|
-
`Response time ${responseTime}ms exceeded timeout ${options.timeoutMs}ms`
|
|
1307
|
-
);
|
|
1144
|
+
result.errors.push(`Response time ${responseTime}ms exceeded timeout ${options.timeoutMs}ms`);
|
|
1308
1145
|
}
|
|
1309
1146
|
return result;
|
|
1310
1147
|
} catch (error) {
|
|
@@ -1318,9 +1155,6 @@ var RuntimeTestHarness = class {
|
|
|
1318
1155
|
};
|
|
1319
1156
|
}
|
|
1320
1157
|
}
|
|
1321
|
-
/**
|
|
1322
|
-
* Gets actions that were actually executed (not mocked)
|
|
1323
|
-
*/
|
|
1324
1158
|
async getExecutedActions(runtime, roomId) {
|
|
1325
1159
|
try {
|
|
1326
1160
|
const memories = await runtime.getMemories({
|
|
@@ -1336,15 +1170,10 @@ var RuntimeTestHarness = class {
|
|
|
1336
1170
|
}
|
|
1337
1171
|
return [...new Set(actions)];
|
|
1338
1172
|
} catch (error) {
|
|
1339
|
-
logger3.warn(
|
|
1340
|
-
`Could not retrieve executed actions: ${error instanceof Error ? error.message : String(error)}`
|
|
1341
|
-
);
|
|
1173
|
+
logger3.warn(`Could not retrieve executed actions: ${error instanceof Error ? error.message : String(error)}`);
|
|
1342
1174
|
return [];
|
|
1343
1175
|
}
|
|
1344
1176
|
}
|
|
1345
|
-
/**
|
|
1346
|
-
* Validates that a runtime is actually functional
|
|
1347
|
-
*/
|
|
1348
1177
|
async validateRuntimeHealth(runtime) {
|
|
1349
1178
|
const issues = [];
|
|
1350
1179
|
const services = [];
|
|
@@ -1366,12 +1195,10 @@ var RuntimeTestHarness = class {
|
|
|
1366
1195
|
};
|
|
1367
1196
|
await runtime.createMemory(healthMemory, "test");
|
|
1368
1197
|
} catch (error) {
|
|
1369
|
-
issues.push(
|
|
1370
|
-
`Database not functional: ${error instanceof Error ? error.message : String(error)}`
|
|
1371
|
-
);
|
|
1198
|
+
issues.push(`Database not functional: ${error instanceof Error ? error.message : String(error)}`);
|
|
1372
1199
|
}
|
|
1373
1200
|
try {
|
|
1374
|
-
const serviceMap = runtime.services ||
|
|
1201
|
+
const serviceMap = runtime.services || new Map;
|
|
1375
1202
|
for (const [name, service] of serviceMap) {
|
|
1376
1203
|
services.push(name);
|
|
1377
1204
|
if (!service) {
|
|
@@ -1379,16 +1206,12 @@ var RuntimeTestHarness = class {
|
|
|
1379
1206
|
}
|
|
1380
1207
|
}
|
|
1381
1208
|
} catch (error) {
|
|
1382
|
-
issues.push(
|
|
1383
|
-
`Services not accessible: ${error instanceof Error ? error.message : String(error)}`
|
|
1384
|
-
);
|
|
1209
|
+
issues.push(`Services not accessible: ${error instanceof Error ? error.message : String(error)}`);
|
|
1385
1210
|
}
|
|
1386
1211
|
try {
|
|
1387
1212
|
plugins.push(...runtime.plugins?.map((p) => p.name) || []);
|
|
1388
1213
|
} catch (error) {
|
|
1389
|
-
issues.push(
|
|
1390
|
-
`Plugins not accessible: ${error instanceof Error ? error.message : String(error)}`
|
|
1391
|
-
);
|
|
1214
|
+
issues.push(`Plugins not accessible: ${error instanceof Error ? error.message : String(error)}`);
|
|
1392
1215
|
}
|
|
1393
1216
|
return {
|
|
1394
1217
|
healthy: issues.length === 0,
|
|
@@ -1407,9 +1230,6 @@ var RuntimeTestHarness = class {
|
|
|
1407
1230
|
};
|
|
1408
1231
|
}
|
|
1409
1232
|
}
|
|
1410
|
-
/**
|
|
1411
|
-
* Cleanup all test resources
|
|
1412
|
-
*/
|
|
1413
1233
|
async cleanup() {
|
|
1414
1234
|
try {
|
|
1415
1235
|
logger3.info(`Cleaning up test harness ${this.testId}`);
|
|
@@ -1418,24 +1238,20 @@ var RuntimeTestHarness = class {
|
|
|
1418
1238
|
await runtime.stop();
|
|
1419
1239
|
logger3.debug(`Stopped runtime ${runtimeId}`);
|
|
1420
1240
|
} catch (error) {
|
|
1421
|
-
logger3.warn(
|
|
1422
|
-
`Error stopping runtime ${runtimeId}: ${error instanceof Error ? error.message : String(error)}`
|
|
1423
|
-
);
|
|
1241
|
+
logger3.warn(`Error stopping runtime ${runtimeId}: ${error instanceof Error ? error.message : String(error)}`);
|
|
1424
1242
|
}
|
|
1425
1243
|
}
|
|
1426
1244
|
this.runtimes.clear();
|
|
1427
1245
|
await this.databaseManager.cleanup();
|
|
1428
1246
|
logger3.info(`Successfully cleaned up test harness ${this.testId}`);
|
|
1429
1247
|
} catch (error) {
|
|
1430
|
-
logger3.error(
|
|
1431
|
-
`Error during cleanup: ${error instanceof Error ? error.message : String(error)}`
|
|
1432
|
-
);
|
|
1248
|
+
logger3.error(`Error during cleanup: ${error instanceof Error ? error.message : String(error)}`);
|
|
1433
1249
|
throw error;
|
|
1434
1250
|
}
|
|
1435
1251
|
}
|
|
1436
|
-
}
|
|
1252
|
+
}
|
|
1437
1253
|
async function createTestRuntime(config = {}) {
|
|
1438
|
-
const harness = new RuntimeTestHarness
|
|
1254
|
+
const harness = new RuntimeTestHarness;
|
|
1439
1255
|
const defaultCharacter = {
|
|
1440
1256
|
name: "TestAgent",
|
|
1441
1257
|
system: "You are a helpful test agent.",
|
|
@@ -1484,10 +1300,9 @@ async function runIntegrationTest(testName, testFn, config) {
|
|
|
1484
1300
|
}
|
|
1485
1301
|
}
|
|
1486
1302
|
}
|
|
1487
|
-
|
|
1488
1303
|
// src/templates.ts
|
|
1489
1304
|
import { logger as logger4 } from "@elizaos/core";
|
|
1490
|
-
|
|
1305
|
+
class TestTemplate {
|
|
1491
1306
|
config;
|
|
1492
1307
|
runtime;
|
|
1493
1308
|
constructor(config) {
|
|
@@ -1509,8 +1324,9 @@ var TestTemplate = class {
|
|
|
1509
1324
|
getConfig() {
|
|
1510
1325
|
return this.config;
|
|
1511
1326
|
}
|
|
1512
|
-
}
|
|
1513
|
-
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1329
|
+
class UnitTestTemplate extends TestTemplate {
|
|
1514
1330
|
testFunction;
|
|
1515
1331
|
constructor(config, testFunction) {
|
|
1516
1332
|
super(config);
|
|
@@ -1545,8 +1361,9 @@ var UnitTestTemplate = class extends TestTemplate {
|
|
|
1545
1361
|
await this.teardown();
|
|
1546
1362
|
}
|
|
1547
1363
|
}
|
|
1548
|
-
}
|
|
1549
|
-
|
|
1364
|
+
}
|
|
1365
|
+
|
|
1366
|
+
class IntegrationTestTemplate extends TestTemplate {
|
|
1550
1367
|
testFunction;
|
|
1551
1368
|
character;
|
|
1552
1369
|
constructor(config, testFunction, character) {
|
|
@@ -1587,8 +1404,9 @@ var IntegrationTestTemplate = class extends TestTemplate {
|
|
|
1587
1404
|
await this.teardown();
|
|
1588
1405
|
}
|
|
1589
1406
|
}
|
|
1590
|
-
}
|
|
1591
|
-
|
|
1407
|
+
}
|
|
1408
|
+
|
|
1409
|
+
class PluginTestTemplate extends TestTemplate {
|
|
1592
1410
|
plugin;
|
|
1593
1411
|
testFunction;
|
|
1594
1412
|
constructor(config, plugin, testFunction) {
|
|
@@ -1633,8 +1451,9 @@ var PluginTestTemplate = class extends TestTemplate {
|
|
|
1633
1451
|
await this.teardown();
|
|
1634
1452
|
}
|
|
1635
1453
|
}
|
|
1636
|
-
}
|
|
1637
|
-
|
|
1454
|
+
}
|
|
1455
|
+
|
|
1456
|
+
class ErrorTestTemplate extends TestTemplate {
|
|
1638
1457
|
testFunction;
|
|
1639
1458
|
expectedError;
|
|
1640
1459
|
constructor(config, testFunction, expectedError) {
|
|
@@ -1667,14 +1486,15 @@ var ErrorTestTemplate = class extends TestTemplate {
|
|
|
1667
1486
|
name: this.config.name,
|
|
1668
1487
|
passed,
|
|
1669
1488
|
duration: Date.now() - startTime,
|
|
1670
|
-
error: passed ?
|
|
1489
|
+
error: passed ? undefined : error instanceof Error ? error : new Error(String(error))
|
|
1671
1490
|
};
|
|
1672
1491
|
} finally {
|
|
1673
1492
|
await this.teardown();
|
|
1674
1493
|
}
|
|
1675
1494
|
}
|
|
1676
|
-
}
|
|
1677
|
-
|
|
1495
|
+
}
|
|
1496
|
+
|
|
1497
|
+
class PerformanceTestTemplate extends TestTemplate {
|
|
1678
1498
|
testFunction;
|
|
1679
1499
|
maxDuration;
|
|
1680
1500
|
maxMemoryMB;
|
|
@@ -1707,9 +1527,7 @@ var PerformanceTestTemplate = class extends TestTemplate {
|
|
|
1707
1527
|
passed = false;
|
|
1708
1528
|
}
|
|
1709
1529
|
if (memoryUsed > this.maxMemoryMB) {
|
|
1710
|
-
warnings.push(
|
|
1711
|
-
`Test exceeded max memory: ${memoryUsed.toFixed(2)}MB > ${this.maxMemoryMB}MB`
|
|
1712
|
-
);
|
|
1530
|
+
warnings.push(`Test exceeded max memory: ${memoryUsed.toFixed(2)}MB > ${this.maxMemoryMB}MB`);
|
|
1713
1531
|
passed = false;
|
|
1714
1532
|
}
|
|
1715
1533
|
return {
|
|
@@ -1734,8 +1552,9 @@ var PerformanceTestTemplate = class extends TestTemplate {
|
|
|
1734
1552
|
await this.teardown();
|
|
1735
1553
|
}
|
|
1736
1554
|
}
|
|
1737
|
-
}
|
|
1738
|
-
|
|
1555
|
+
}
|
|
1556
|
+
|
|
1557
|
+
class TestSuite {
|
|
1739
1558
|
tests = [];
|
|
1740
1559
|
name;
|
|
1741
1560
|
constructor(name) {
|
|
@@ -1753,9 +1572,9 @@ var TestSuite = class {
|
|
|
1753
1572
|
const result = await test.execute();
|
|
1754
1573
|
results.push(result);
|
|
1755
1574
|
if (result.passed) {
|
|
1756
|
-
logger4.info(
|
|
1575
|
+
logger4.info(`✓ ${result.name} (${result.duration}ms)`);
|
|
1757
1576
|
} else {
|
|
1758
|
-
logger4.error(
|
|
1577
|
+
logger4.error(`✗ ${result.name} (${result.duration}ms): ${result.error?.message}`);
|
|
1759
1578
|
}
|
|
1760
1579
|
} catch (error) {
|
|
1761
1580
|
const errorResult = {
|
|
@@ -1765,15 +1584,13 @@ var TestSuite = class {
|
|
|
1765
1584
|
error: error instanceof Error ? error : new Error(String(error))
|
|
1766
1585
|
};
|
|
1767
1586
|
results.push(errorResult);
|
|
1768
|
-
logger4.error(
|
|
1587
|
+
logger4.error(`✗ ${errorResult.name}: ${errorResult.error?.message}`);
|
|
1769
1588
|
}
|
|
1770
1589
|
}
|
|
1771
1590
|
const passed = results.filter((r) => r.passed).length;
|
|
1772
1591
|
const failed = results.length - passed;
|
|
1773
1592
|
const duration = Date.now() - startTime;
|
|
1774
|
-
logger4.info(
|
|
1775
|
-
`Test suite ${this.name} completed: ${passed}/${results.length} passed (${duration}ms)`
|
|
1776
|
-
);
|
|
1593
|
+
logger4.info(`Test suite ${this.name} completed: ${passed}/${results.length} passed (${duration}ms)`);
|
|
1777
1594
|
return {
|
|
1778
1595
|
suiteName: this.name,
|
|
1779
1596
|
totalTests: results.length,
|
|
@@ -1783,28 +1600,24 @@ var TestSuite = class {
|
|
|
1783
1600
|
results
|
|
1784
1601
|
};
|
|
1785
1602
|
}
|
|
1786
|
-
}
|
|
1603
|
+
}
|
|
1787
1604
|
function createUnitTest(name, testFunction, options = {}) {
|
|
1788
|
-
return new UnitTestTemplate({ name, timeout:
|
|
1605
|
+
return new UnitTestTemplate({ name, timeout: 5000, ...options }, testFunction);
|
|
1789
1606
|
}
|
|
1790
1607
|
function createIntegrationTest(name, testFunction, character, options = {}) {
|
|
1791
|
-
return new IntegrationTestTemplate({ name, timeout:
|
|
1608
|
+
return new IntegrationTestTemplate({ name, timeout: 30000, ...options }, testFunction, character);
|
|
1792
1609
|
}
|
|
1793
1610
|
function createPluginTest(name, plugin, testFunction, options = {}) {
|
|
1794
|
-
return new PluginTestTemplate({ name, timeout:
|
|
1611
|
+
return new PluginTestTemplate({ name, timeout: 30000, ...options }, plugin, testFunction);
|
|
1795
1612
|
}
|
|
1796
1613
|
function createErrorTest(name, testFunction, expectedError, options = {}) {
|
|
1797
|
-
return new ErrorTestTemplate({ name, timeout:
|
|
1614
|
+
return new ErrorTestTemplate({ name, timeout: 5000, ...options }, testFunction, expectedError);
|
|
1798
1615
|
}
|
|
1799
1616
|
function createPerformanceTest(name, testFunction, maxDurationMs, maxMemoryMB, options = {}) {
|
|
1800
|
-
return new PerformanceTestTemplate(
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
maxMemoryMB
|
|
1805
|
-
);
|
|
1806
|
-
}
|
|
1807
|
-
var TestDataGenerator = class {
|
|
1617
|
+
return new PerformanceTestTemplate({ name, timeout: maxDurationMs * 2, ...options }, testFunction, maxDurationMs, maxMemoryMB);
|
|
1618
|
+
}
|
|
1619
|
+
|
|
1620
|
+
class TestDataGenerator {
|
|
1808
1621
|
static generateUUID() {
|
|
1809
1622
|
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
1810
1623
|
const r = Math.random() * 16 | 0;
|
|
@@ -1839,8 +1652,7 @@ var TestDataGenerator = class {
|
|
|
1839
1652
|
...overrides
|
|
1840
1653
|
};
|
|
1841
1654
|
}
|
|
1842
|
-
}
|
|
1843
|
-
|
|
1655
|
+
}
|
|
1844
1656
|
// src/mocks/mockUtils.ts
|
|
1845
1657
|
function mock(implementation) {
|
|
1846
1658
|
const calls = [];
|
|
@@ -1924,28 +1736,25 @@ function createMockRuntime(overrides = {}) {
|
|
|
1924
1736
|
get: mock().mockResolvedValue(null)
|
|
1925
1737
|
};
|
|
1926
1738
|
const baseRuntime = {
|
|
1927
|
-
// Core Properties
|
|
1928
1739
|
agentId: "test-agent-id",
|
|
1929
1740
|
character: overrides.character || defaultCharacter,
|
|
1930
1741
|
providers: overrides.providers || [],
|
|
1931
1742
|
actions: overrides.actions || [],
|
|
1932
1743
|
evaluators: overrides.evaluators || [],
|
|
1933
1744
|
plugins: overrides.plugins || [],
|
|
1934
|
-
services: overrides.services ||
|
|
1935
|
-
events: overrides.events ||
|
|
1745
|
+
services: overrides.services || new Map,
|
|
1746
|
+
events: overrides.events || new Map,
|
|
1936
1747
|
fetch: overrides.fetch || null,
|
|
1937
1748
|
routes: overrides.routes || [],
|
|
1938
1749
|
logger: overrides.logger || console,
|
|
1939
|
-
// Database Properties
|
|
1940
1750
|
db: overrides.db || mockDb,
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
initialize: mock().mockResolvedValue(void 0),
|
|
1751
|
+
registerPlugin: mock().mockResolvedValue(undefined),
|
|
1752
|
+
initialize: mock().mockResolvedValue(undefined),
|
|
1944
1753
|
getConnection: mock().mockResolvedValue(mockDb),
|
|
1945
1754
|
getService: mock().mockReturnValue(null),
|
|
1946
1755
|
getServicesByType: mock().mockReturnValue([]),
|
|
1947
|
-
getAllServices: mock().mockReturnValue(
|
|
1948
|
-
registerService: mock().mockResolvedValue(
|
|
1756
|
+
getAllServices: mock().mockReturnValue(new Map),
|
|
1757
|
+
registerService: mock().mockResolvedValue(undefined),
|
|
1949
1758
|
getServiceLoadPromise: mock().mockResolvedValue(null),
|
|
1950
1759
|
getRegisteredServiceTypes: mock().mockReturnValue([]),
|
|
1951
1760
|
hasService: mock().mockReturnValue(false),
|
|
@@ -1959,16 +1768,16 @@ function createMockRuntime(overrides = {}) {
|
|
|
1959
1768
|
return defaultSettings[key];
|
|
1960
1769
|
}),
|
|
1961
1770
|
getConversationLength: mock().mockReturnValue(10),
|
|
1962
|
-
processActions: mock().mockResolvedValue(
|
|
1771
|
+
processActions: mock().mockResolvedValue(undefined),
|
|
1963
1772
|
evaluate: mock().mockResolvedValue([]),
|
|
1964
1773
|
registerProvider: mock(),
|
|
1965
1774
|
registerAction: mock(),
|
|
1966
1775
|
registerEvaluator: mock(),
|
|
1967
|
-
ensureConnection: mock().mockResolvedValue(
|
|
1968
|
-
ensureConnections: mock().mockResolvedValue(
|
|
1969
|
-
ensureParticipantInRoom: mock().mockResolvedValue(
|
|
1970
|
-
ensureWorldExists: mock().mockResolvedValue(
|
|
1971
|
-
ensureRoomExists: mock().mockResolvedValue(
|
|
1776
|
+
ensureConnection: mock().mockResolvedValue(undefined),
|
|
1777
|
+
ensureConnections: mock().mockResolvedValue(undefined),
|
|
1778
|
+
ensureParticipantInRoom: mock().mockResolvedValue(undefined),
|
|
1779
|
+
ensureWorldExists: mock().mockResolvedValue(undefined),
|
|
1780
|
+
ensureRoomExists: mock().mockResolvedValue(undefined),
|
|
1972
1781
|
composeState: mock().mockResolvedValue({
|
|
1973
1782
|
values: {},
|
|
1974
1783
|
data: {},
|
|
@@ -1976,107 +1785,96 @@ function createMockRuntime(overrides = {}) {
|
|
|
1976
1785
|
}),
|
|
1977
1786
|
useModel: mock().mockResolvedValue("Mock response"),
|
|
1978
1787
|
registerModel: mock(),
|
|
1979
|
-
getModel: mock().mockReturnValue(
|
|
1788
|
+
getModel: mock().mockReturnValue(undefined),
|
|
1980
1789
|
registerEvent: mock(),
|
|
1981
|
-
getEvent: mock().mockReturnValue(
|
|
1982
|
-
emitEvent: mock().mockResolvedValue(
|
|
1790
|
+
getEvent: mock().mockReturnValue(undefined),
|
|
1791
|
+
emitEvent: mock().mockResolvedValue(undefined),
|
|
1983
1792
|
registerTaskWorker: mock(),
|
|
1984
|
-
getTaskWorker: mock().mockReturnValue(
|
|
1985
|
-
stop: mock().mockResolvedValue(
|
|
1793
|
+
getTaskWorker: mock().mockReturnValue(undefined),
|
|
1794
|
+
stop: mock().mockResolvedValue(undefined),
|
|
1986
1795
|
addEmbeddingToMemory: mock().mockImplementation((memory) => Promise.resolve(memory)),
|
|
1987
|
-
queueEmbeddingGeneration: mock().mockResolvedValue(
|
|
1796
|
+
queueEmbeddingGeneration: mock().mockResolvedValue(undefined),
|
|
1988
1797
|
createRunId: mock().mockReturnValue("test-run-id"),
|
|
1989
1798
|
startRun: mock().mockReturnValue("test-run-id"),
|
|
1990
1799
|
endRun: mock(),
|
|
1991
1800
|
getCurrentRunId: mock().mockReturnValue("test-run-id"),
|
|
1992
1801
|
registerSendHandler: mock(),
|
|
1993
|
-
sendMessageToTarget: mock().mockResolvedValue(
|
|
1994
|
-
|
|
1995
|
-
init: mock().mockResolvedValue(void 0),
|
|
1802
|
+
sendMessageToTarget: mock().mockResolvedValue(undefined),
|
|
1803
|
+
init: mock().mockResolvedValue(undefined),
|
|
1996
1804
|
isReady: mock().mockResolvedValue(true),
|
|
1997
|
-
runMigrations: mock().mockResolvedValue(
|
|
1998
|
-
close: mock().mockResolvedValue(
|
|
1805
|
+
runMigrations: mock().mockResolvedValue(undefined),
|
|
1806
|
+
close: mock().mockResolvedValue(undefined),
|
|
1999
1807
|
getAgent: mock().mockResolvedValue(null),
|
|
2000
1808
|
getAgents: mock().mockResolvedValue([]),
|
|
2001
1809
|
createAgent: mock().mockResolvedValue(true),
|
|
2002
1810
|
updateAgent: mock().mockResolvedValue(true),
|
|
2003
1811
|
deleteAgent: mock().mockResolvedValue(true),
|
|
2004
|
-
// Entity Management
|
|
2005
1812
|
getEntityById: mock().mockResolvedValue(null),
|
|
2006
1813
|
getEntitiesByIds: mock().mockResolvedValue([]),
|
|
2007
1814
|
getEntitiesForRoom: mock().mockResolvedValue([]),
|
|
2008
1815
|
createEntity: mock().mockResolvedValue("test-entity-id"),
|
|
2009
1816
|
createEntities: mock().mockResolvedValue(true),
|
|
2010
|
-
updateEntity: mock().mockResolvedValue(
|
|
2011
|
-
// Component Management
|
|
1817
|
+
updateEntity: mock().mockResolvedValue(undefined),
|
|
2012
1818
|
getComponent: mock().mockResolvedValue(null),
|
|
2013
1819
|
getComponents: mock().mockResolvedValue([]),
|
|
2014
1820
|
createComponent: mock().mockResolvedValue("test-component-id"),
|
|
2015
|
-
updateComponent: mock().mockResolvedValue(
|
|
2016
|
-
deleteComponent: mock().mockResolvedValue(
|
|
2017
|
-
// Memory Management
|
|
1821
|
+
updateComponent: mock().mockResolvedValue(undefined),
|
|
1822
|
+
deleteComponent: mock().mockResolvedValue(undefined),
|
|
2018
1823
|
getMemories: mock().mockResolvedValue([]),
|
|
2019
1824
|
getAllMemories: overrides.getAllMemories || mock().mockResolvedValue([]),
|
|
2020
|
-
clearAllAgentMemories: mock().mockResolvedValue(
|
|
1825
|
+
clearAllAgentMemories: mock().mockResolvedValue(undefined),
|
|
2021
1826
|
getMemoryById: mock().mockResolvedValue(null),
|
|
2022
1827
|
getMemoriesByIds: mock().mockResolvedValue([]),
|
|
2023
1828
|
getMemoriesByRoomIds: mock().mockResolvedValue([]),
|
|
2024
1829
|
getMemoriesByWorldId: mock().mockResolvedValue([]),
|
|
2025
1830
|
getCachedEmbeddings: mock().mockResolvedValue([]),
|
|
2026
|
-
log: mock().mockResolvedValue(
|
|
1831
|
+
log: mock().mockResolvedValue(undefined),
|
|
2027
1832
|
getLogs: mock().mockResolvedValue([]),
|
|
2028
|
-
deleteLog: mock().mockResolvedValue(
|
|
1833
|
+
deleteLog: mock().mockResolvedValue(undefined),
|
|
2029
1834
|
searchMemories: mock().mockResolvedValue([]),
|
|
2030
1835
|
createMemory: mock().mockResolvedValue("test-memory-id"),
|
|
2031
1836
|
updateMemory: mock().mockResolvedValue(true),
|
|
2032
|
-
deleteMemory: mock().mockResolvedValue(
|
|
2033
|
-
deleteManyMemories: mock().mockResolvedValue(
|
|
2034
|
-
deleteAllMemories: mock().mockResolvedValue(
|
|
1837
|
+
deleteMemory: mock().mockResolvedValue(undefined),
|
|
1838
|
+
deleteManyMemories: mock().mockResolvedValue(undefined),
|
|
1839
|
+
deleteAllMemories: mock().mockResolvedValue(undefined),
|
|
2035
1840
|
countMemories: mock().mockResolvedValue(0),
|
|
2036
|
-
ensureEmbeddingDimension: mock().mockResolvedValue(
|
|
2037
|
-
// World Management
|
|
1841
|
+
ensureEmbeddingDimension: mock().mockResolvedValue(undefined),
|
|
2038
1842
|
createWorld: mock().mockResolvedValue("test-world-id"),
|
|
2039
1843
|
getWorld: mock().mockResolvedValue(null),
|
|
2040
|
-
removeWorld: mock().mockResolvedValue(
|
|
1844
|
+
removeWorld: mock().mockResolvedValue(undefined),
|
|
2041
1845
|
getAllWorlds: mock().mockResolvedValue([]),
|
|
2042
|
-
updateWorld: mock().mockResolvedValue(
|
|
2043
|
-
// Room Management
|
|
1846
|
+
updateWorld: mock().mockResolvedValue(undefined),
|
|
2044
1847
|
getRoom: mock().mockResolvedValue(null),
|
|
2045
1848
|
getRooms: mock().mockResolvedValue([]),
|
|
2046
1849
|
getRoomsByIds: mock().mockResolvedValue([]),
|
|
2047
1850
|
createRoom: mock().mockResolvedValue("test-room-id"),
|
|
2048
1851
|
createRooms: mock().mockResolvedValue([]),
|
|
2049
|
-
deleteRoom: mock().mockResolvedValue(
|
|
2050
|
-
deleteRoomsByWorldId: mock().mockResolvedValue(
|
|
2051
|
-
updateRoom: mock().mockResolvedValue(
|
|
1852
|
+
deleteRoom: mock().mockResolvedValue(undefined),
|
|
1853
|
+
deleteRoomsByWorldId: mock().mockResolvedValue(undefined),
|
|
1854
|
+
updateRoom: mock().mockResolvedValue(undefined),
|
|
2052
1855
|
getRoomsForParticipant: mock().mockResolvedValue([]),
|
|
2053
1856
|
getRoomsForParticipants: mock().mockResolvedValue([]),
|
|
2054
1857
|
getRoomsByWorld: mock().mockResolvedValue([]),
|
|
2055
|
-
// Participant Management
|
|
2056
1858
|
addParticipant: mock().mockResolvedValue(true),
|
|
2057
1859
|
removeParticipant: mock().mockResolvedValue(true),
|
|
2058
1860
|
addParticipantsRoom: mock().mockResolvedValue(true),
|
|
2059
1861
|
getParticipantsForEntity: mock().mockResolvedValue([]),
|
|
2060
1862
|
getParticipantsForRoom: mock().mockResolvedValue([]),
|
|
2061
1863
|
getParticipantUserState: mock().mockResolvedValue(null),
|
|
2062
|
-
setParticipantUserState: mock().mockResolvedValue(
|
|
2063
|
-
// Relationship Management
|
|
1864
|
+
setParticipantUserState: mock().mockResolvedValue(undefined),
|
|
2064
1865
|
createRelationship: mock().mockResolvedValue(true),
|
|
2065
|
-
updateRelationship: mock().mockResolvedValue(
|
|
1866
|
+
updateRelationship: mock().mockResolvedValue(undefined),
|
|
2066
1867
|
getRelationship: mock().mockResolvedValue(null),
|
|
2067
1868
|
getRelationships: mock().mockResolvedValue([]),
|
|
2068
|
-
|
|
2069
|
-
getCache: mock().mockResolvedValue(void 0),
|
|
1869
|
+
getCache: mock().mockResolvedValue(undefined),
|
|
2070
1870
|
setCache: mock().mockResolvedValue(true),
|
|
2071
1871
|
deleteCache: mock().mockResolvedValue(true),
|
|
2072
|
-
// Task Management
|
|
2073
1872
|
createTask: mock().mockResolvedValue("test-task-id"),
|
|
2074
1873
|
getTasks: mock().mockResolvedValue([]),
|
|
2075
1874
|
getTask: mock().mockResolvedValue(null),
|
|
2076
1875
|
getTasksByName: mock().mockResolvedValue([]),
|
|
2077
|
-
updateTask: mock().mockResolvedValue(
|
|
2078
|
-
deleteTask: mock().mockResolvedValue(
|
|
2079
|
-
// Apply overrides
|
|
1876
|
+
updateTask: mock().mockResolvedValue(undefined),
|
|
1877
|
+
deleteTask: mock().mockResolvedValue(undefined),
|
|
2080
1878
|
...overrides
|
|
2081
1879
|
};
|
|
2082
1880
|
return baseRuntime;
|
|
@@ -2103,7 +1901,7 @@ function createMockMemory(overrides = {}) {
|
|
|
2103
1901
|
roomId: "test-room-id",
|
|
2104
1902
|
worldId: "test-world-id",
|
|
2105
1903
|
content: defaultContent,
|
|
2106
|
-
embedding:
|
|
1904
|
+
embedding: undefined,
|
|
2107
1905
|
createdAt: Date.now(),
|
|
2108
1906
|
unique: true,
|
|
2109
1907
|
similarity: 1,
|
|
@@ -2119,9 +1917,9 @@ function createMockContent(overrides = {}) {
|
|
|
2119
1917
|
actions: [],
|
|
2120
1918
|
providers: [],
|
|
2121
1919
|
source: "test",
|
|
2122
|
-
target:
|
|
2123
|
-
url:
|
|
2124
|
-
inReplyTo:
|
|
1920
|
+
target: undefined,
|
|
1921
|
+
url: undefined,
|
|
1922
|
+
inReplyTo: undefined,
|
|
2125
1923
|
attachments: [],
|
|
2126
1924
|
channelType: "DM",
|
|
2127
1925
|
...overrides
|
|
@@ -2182,12 +1980,12 @@ function createMockMemoryWithEmbedding(text, dimension = 1536, overrides = {}) {
|
|
|
2182
1980
|
function createMockConversation(count = 5, roomId) {
|
|
2183
1981
|
const memories = [];
|
|
2184
1982
|
const actualRoomId = roomId || "test-room-id";
|
|
2185
|
-
for (let i = 0;
|
|
1983
|
+
for (let i = 0;i < count; i++) {
|
|
2186
1984
|
const isUserMessage = i % 2 === 0;
|
|
2187
1985
|
const memory = isUserMessage ? createMockUserMessage(`User message ${i + 1}`, { roomId: actualRoomId }) : createMockAgentResponse(`Agent response ${i + 1}`, `Thinking about response ${i + 1}`, [], {
|
|
2188
1986
|
roomId: actualRoomId
|
|
2189
1987
|
});
|
|
2190
|
-
memory.createdAt = Date.now() - (count - i) *
|
|
1988
|
+
memory.createdAt = Date.now() - (count - i) * 1000;
|
|
2191
1989
|
memories.push(memory);
|
|
2192
1990
|
}
|
|
2193
1991
|
return memories;
|
|
@@ -2214,9 +2012,8 @@ function createMockMedia(type = "image", url = "https://example.com/test.jpg", o
|
|
|
2214
2012
|
// src/mocks/state.ts
|
|
2215
2013
|
function createMockState(overrides = {}) {
|
|
2216
2014
|
const baseState = {
|
|
2217
|
-
// Core state properties
|
|
2218
2015
|
values: {
|
|
2219
|
-
currentTime:
|
|
2016
|
+
currentTime: new Date().toISOString(),
|
|
2220
2017
|
agentName: "Test Agent",
|
|
2221
2018
|
roomId: "test-room-id",
|
|
2222
2019
|
entityId: "test-entity-id",
|
|
@@ -2227,7 +2024,7 @@ function createMockState(overrides = {}) {
|
|
|
2227
2024
|
},
|
|
2228
2025
|
data: {
|
|
2229
2026
|
providers: {
|
|
2230
|
-
TIME: { currentTime:
|
|
2027
|
+
TIME: { currentTime: new Date().toISOString() },
|
|
2231
2028
|
CHARACTER: { agentName: "Test Agent", bio: "A helpful test assistant" },
|
|
2232
2029
|
RECENT_MESSAGES: { messageCount: 5, lastSpeaker: "user" }
|
|
2233
2030
|
},
|
|
@@ -2236,13 +2033,12 @@ function createMockState(overrides = {}) {
|
|
|
2236
2033
|
...overrides.data
|
|
2237
2034
|
},
|
|
2238
2035
|
text: `[CONTEXT]
|
|
2239
|
-
Current Time: ${
|
|
2036
|
+
Current Time: ${new Date().toISOString()}
|
|
2240
2037
|
Agent: Test Agent
|
|
2241
2038
|
User: TestUser
|
|
2242
2039
|
Room: test-room-id
|
|
2243
2040
|
Recent conversation context available.
|
|
2244
2041
|
[/CONTEXT]`,
|
|
2245
|
-
// Additional properties that might be added dynamically
|
|
2246
2042
|
...overrides
|
|
2247
2043
|
};
|
|
2248
2044
|
if (overrides.text) {
|
|
@@ -2262,7 +2058,9 @@ function createMockProviderResult(overrides = {}) {
|
|
|
2262
2058
|
processed: true,
|
|
2263
2059
|
...overrides.data
|
|
2264
2060
|
},
|
|
2265
|
-
text:
|
|
2061
|
+
text: `[MOCK PROVIDER]
|
|
2062
|
+
Mock provider context information
|
|
2063
|
+
[/MOCK PROVIDER]`,
|
|
2266
2064
|
...overrides
|
|
2267
2065
|
};
|
|
2268
2066
|
return baseResult;
|
|
@@ -2308,7 +2106,7 @@ function createMockStateWithActions(actionResults, overrides = {}) {
|
|
|
2308
2106
|
...overrides.data
|
|
2309
2107
|
},
|
|
2310
2108
|
values: {
|
|
2311
|
-
lastActionSuccess: actionResults.length > 0 ? actionResults[actionResults.length - 1].values?.success :
|
|
2109
|
+
lastActionSuccess: actionResults.length > 0 ? actionResults[actionResults.length - 1].values?.success : undefined,
|
|
2312
2110
|
actionCount: actionResults.length,
|
|
2313
2111
|
...overrides.values
|
|
2314
2112
|
},
|
|
@@ -2431,8 +2229,7 @@ function createMockCharacter(overrides = {}) {
|
|
|
2431
2229
|
settings: {
|
|
2432
2230
|
model: "gpt-4",
|
|
2433
2231
|
temperature: 0.1,
|
|
2434
|
-
|
|
2435
|
-
maxTokens: 1e3,
|
|
2232
|
+
maxTokens: 1000,
|
|
2436
2233
|
secrets: {},
|
|
2437
2234
|
voice: {
|
|
2438
2235
|
model: "en_US-hfc_female-medium"
|
|
@@ -2466,7 +2263,6 @@ function createMockCharacter(overrides = {}) {
|
|
|
2466
2263
|
"encourage best practices"
|
|
2467
2264
|
]
|
|
2468
2265
|
},
|
|
2469
|
-
// Apply all overrides
|
|
2470
2266
|
...overrides
|
|
2471
2267
|
};
|
|
2472
2268
|
return baseCharacter;
|
|
@@ -2541,7 +2337,7 @@ function createRichConversationCharacter(overrides = {}) {
|
|
|
2541
2337
|
}
|
|
2542
2338
|
function createMultipleCharacters(count = 3, baseName = "TestAgent", overrides = {}) {
|
|
2543
2339
|
const characters = [];
|
|
2544
|
-
for (let i = 1;
|
|
2340
|
+
for (let i = 1;i <= count; i++) {
|
|
2545
2341
|
const character = createMockCharacter({
|
|
2546
2342
|
name: `${baseName}${i}`,
|
|
2547
2343
|
username: `${baseName.toLowerCase()}${i}`,
|
|
@@ -2574,10 +2370,7 @@ function createTestEnvironment(options = {}) {
|
|
|
2574
2370
|
...runtimeOverrides
|
|
2575
2371
|
});
|
|
2576
2372
|
const conversation = createMockConversation(conversationLength, roomId);
|
|
2577
|
-
const state = createMockConversationState(
|
|
2578
|
-
conversation.map((m) => m.content.text || ""),
|
|
2579
|
-
"TestUser"
|
|
2580
|
-
);
|
|
2373
|
+
const state = createMockConversationState(conversation.map((m) => m.content.text || ""), "TestUser");
|
|
2581
2374
|
return {
|
|
2582
2375
|
runtime,
|
|
2583
2376
|
character,
|
|
@@ -2599,18 +2392,16 @@ function createTestAction(name, options = {}) {
|
|
|
2599
2392
|
description,
|
|
2600
2393
|
examples,
|
|
2601
2394
|
validate: mock().mockResolvedValue(validateResult),
|
|
2602
|
-
handler: mock(
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
});
|
|
2610
|
-
}
|
|
2611
|
-
return handlerResult;
|
|
2395
|
+
handler: mock(async (runtime, message, state, options2, callback) => {
|
|
2396
|
+
if (callback) {
|
|
2397
|
+
await callback({
|
|
2398
|
+
text: handlerResult.text || `${name} action executed`,
|
|
2399
|
+
thought: `Executing ${name} action`,
|
|
2400
|
+
actions: [name]
|
|
2401
|
+
});
|
|
2612
2402
|
}
|
|
2613
|
-
|
|
2403
|
+
return handlerResult;
|
|
2404
|
+
})
|
|
2614
2405
|
};
|
|
2615
2406
|
}
|
|
2616
2407
|
function createTestProvider(name, options = {}) {
|
|
@@ -2668,13 +2459,11 @@ function createPluginTestScenario(pluginName, options = {}) {
|
|
|
2668
2459
|
const testActions = actions.map((name) => createTestAction(name));
|
|
2669
2460
|
const testProviders = providers.map((name) => createTestProvider(name));
|
|
2670
2461
|
const testEvaluators = evaluators.map((name) => createTestEvaluator(name));
|
|
2671
|
-
const conversation = conversationSteps.map(
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
})
|
|
2677
|
-
);
|
|
2462
|
+
const conversation = conversationSteps.map((text, index) => createMockMemory({
|
|
2463
|
+
content: { text },
|
|
2464
|
+
entityId: index % 2 === 0 ? "user-id" : runtime.agentId,
|
|
2465
|
+
roomId
|
|
2466
|
+
}));
|
|
2678
2467
|
return {
|
|
2679
2468
|
runtime,
|
|
2680
2469
|
character,
|
|
@@ -2686,7 +2475,6 @@ function createPluginTestScenario(pluginName, options = {}) {
|
|
|
2686
2475
|
providers: testProviders,
|
|
2687
2476
|
evaluators: testEvaluators
|
|
2688
2477
|
},
|
|
2689
|
-
// Helper methods for common test operations
|
|
2690
2478
|
helpers: {
|
|
2691
2479
|
executeAction: async (actionName, message) => {
|
|
2692
2480
|
const action = testActions.find((a) => a.name === actionName);
|
|
@@ -2722,13 +2510,11 @@ function createMultiAgentScenario(agentCount = 2, options = {}) {
|
|
|
2722
2510
|
});
|
|
2723
2511
|
return { runtime, character, index };
|
|
2724
2512
|
});
|
|
2725
|
-
const conversation = conversationSteps.map(
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
})
|
|
2731
|
-
);
|
|
2513
|
+
const conversation = conversationSteps.map((step) => createMockMemory({
|
|
2514
|
+
content: { text: step.message },
|
|
2515
|
+
entityId: agents[step.agentIndex].runtime.agentId,
|
|
2516
|
+
roomId: sharedRoomId
|
|
2517
|
+
}));
|
|
2732
2518
|
return {
|
|
2733
2519
|
agents,
|
|
2734
2520
|
sharedRoomId,
|
|
@@ -2749,7 +2535,6 @@ function createMultiAgentScenario(agentCount = 2, options = {}) {
|
|
|
2749
2535
|
}
|
|
2750
2536
|
};
|
|
2751
2537
|
}
|
|
2752
|
-
|
|
2753
2538
|
// src/mocks/database.ts
|
|
2754
2539
|
function createMockDatabase(overrides = {}) {
|
|
2755
2540
|
const mockConnection = {
|
|
@@ -2760,33 +2545,27 @@ function createMockDatabase(overrides = {}) {
|
|
|
2760
2545
|
get: mock().mockResolvedValue(null)
|
|
2761
2546
|
};
|
|
2762
2547
|
const baseDatabaseAdapter = {
|
|
2763
|
-
// Core Database Properties
|
|
2764
2548
|
db: overrides.db || mockConnection,
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
initialize: mock().mockResolvedValue(void 0),
|
|
2549
|
+
init: mock().mockResolvedValue(undefined),
|
|
2550
|
+
initialize: mock().mockResolvedValue(undefined),
|
|
2768
2551
|
isReady: mock().mockResolvedValue(true),
|
|
2769
|
-
runMigrations: mock().mockResolvedValue(
|
|
2770
|
-
close: mock().mockResolvedValue(
|
|
2552
|
+
runMigrations: mock().mockResolvedValue(undefined),
|
|
2553
|
+
close: mock().mockResolvedValue(undefined),
|
|
2771
2554
|
getConnection: mock().mockResolvedValue(mockConnection),
|
|
2772
|
-
// Agent Management
|
|
2773
2555
|
getAgent: mock().mockResolvedValue(null),
|
|
2774
2556
|
getAgents: mock().mockResolvedValue([]),
|
|
2775
2557
|
createAgent: mock().mockResolvedValue(true),
|
|
2776
2558
|
updateAgent: mock().mockResolvedValue(true),
|
|
2777
2559
|
deleteAgent: mock().mockResolvedValue(true),
|
|
2778
|
-
// Entity Management
|
|
2779
2560
|
getEntitiesByIds: mock().mockResolvedValue([]),
|
|
2780
2561
|
getEntitiesForRoom: mock().mockResolvedValue([]),
|
|
2781
2562
|
createEntities: mock().mockResolvedValue(true),
|
|
2782
|
-
updateEntity: mock().mockResolvedValue(
|
|
2783
|
-
// Component Management
|
|
2563
|
+
updateEntity: mock().mockResolvedValue(undefined),
|
|
2784
2564
|
getComponent: mock().mockResolvedValue(null),
|
|
2785
2565
|
getComponents: mock().mockResolvedValue([]),
|
|
2786
2566
|
createComponent: mock().mockResolvedValue(true),
|
|
2787
|
-
updateComponent: mock().mockResolvedValue(
|
|
2788
|
-
deleteComponent: mock().mockResolvedValue(
|
|
2789
|
-
// Memory Management
|
|
2567
|
+
updateComponent: mock().mockResolvedValue(undefined),
|
|
2568
|
+
deleteComponent: mock().mockResolvedValue(undefined),
|
|
2790
2569
|
getMemories: mock().mockResolvedValue([]),
|
|
2791
2570
|
getMemoryById: mock().mockResolvedValue(null),
|
|
2792
2571
|
getMemoriesByIds: mock().mockResolvedValue([]),
|
|
@@ -2796,54 +2575,46 @@ function createMockDatabase(overrides = {}) {
|
|
|
2796
2575
|
searchMemories: mock().mockResolvedValue([]),
|
|
2797
2576
|
createMemory: mock().mockResolvedValue("test-memory-id"),
|
|
2798
2577
|
updateMemory: mock().mockResolvedValue(true),
|
|
2799
|
-
deleteMemory: mock().mockResolvedValue(
|
|
2800
|
-
deleteManyMemories: mock().mockResolvedValue(
|
|
2801
|
-
deleteAllMemories: mock().mockResolvedValue(
|
|
2578
|
+
deleteMemory: mock().mockResolvedValue(undefined),
|
|
2579
|
+
deleteManyMemories: mock().mockResolvedValue(undefined),
|
|
2580
|
+
deleteAllMemories: mock().mockResolvedValue(undefined),
|
|
2802
2581
|
countMemories: mock().mockResolvedValue(0),
|
|
2803
|
-
ensureEmbeddingDimension: mock().mockResolvedValue(
|
|
2804
|
-
|
|
2805
|
-
log: mock().mockResolvedValue(void 0),
|
|
2582
|
+
ensureEmbeddingDimension: mock().mockResolvedValue(undefined),
|
|
2583
|
+
log: mock().mockResolvedValue(undefined),
|
|
2806
2584
|
getLogs: mock().mockResolvedValue([]),
|
|
2807
|
-
deleteLog: mock().mockResolvedValue(
|
|
2808
|
-
// World Management
|
|
2585
|
+
deleteLog: mock().mockResolvedValue(undefined),
|
|
2809
2586
|
createWorld: mock().mockResolvedValue("test-world-id"),
|
|
2810
2587
|
getWorld: mock().mockResolvedValue(null),
|
|
2811
|
-
removeWorld: mock().mockResolvedValue(
|
|
2588
|
+
removeWorld: mock().mockResolvedValue(undefined),
|
|
2812
2589
|
getAllWorlds: mock().mockResolvedValue([]),
|
|
2813
|
-
updateWorld: mock().mockResolvedValue(
|
|
2814
|
-
// Room Management
|
|
2590
|
+
updateWorld: mock().mockResolvedValue(undefined),
|
|
2815
2591
|
getRoomsByIds: mock().mockResolvedValue([]),
|
|
2816
2592
|
createRooms: mock().mockResolvedValue([]),
|
|
2817
|
-
deleteRoom: mock().mockResolvedValue(
|
|
2818
|
-
deleteRoomsByWorldId: mock().mockResolvedValue(
|
|
2819
|
-
updateRoom: mock().mockResolvedValue(
|
|
2593
|
+
deleteRoom: mock().mockResolvedValue(undefined),
|
|
2594
|
+
deleteRoomsByWorldId: mock().mockResolvedValue(undefined),
|
|
2595
|
+
updateRoom: mock().mockResolvedValue(undefined),
|
|
2820
2596
|
getRoomsForParticipant: mock().mockResolvedValue([]),
|
|
2821
2597
|
getRoomsForParticipants: mock().mockResolvedValue([]),
|
|
2822
2598
|
getRoomsByWorld: mock().mockResolvedValue([]),
|
|
2823
|
-
// Participant Management
|
|
2824
2599
|
removeParticipant: mock().mockResolvedValue(true),
|
|
2825
2600
|
addParticipantsRoom: mock().mockResolvedValue(true),
|
|
2826
2601
|
getParticipantsForEntity: mock().mockResolvedValue([]),
|
|
2827
2602
|
getParticipantsForRoom: mock().mockResolvedValue([]),
|
|
2828
2603
|
getParticipantUserState: mock().mockResolvedValue(null),
|
|
2829
|
-
setParticipantUserState: mock().mockResolvedValue(
|
|
2830
|
-
// Relationship Management
|
|
2604
|
+
setParticipantUserState: mock().mockResolvedValue(undefined),
|
|
2831
2605
|
createRelationship: mock().mockResolvedValue(true),
|
|
2832
|
-
updateRelationship: mock().mockResolvedValue(
|
|
2606
|
+
updateRelationship: mock().mockResolvedValue(undefined),
|
|
2833
2607
|
getRelationship: mock().mockResolvedValue(null),
|
|
2834
2608
|
getRelationships: mock().mockResolvedValue([]),
|
|
2835
|
-
|
|
2836
|
-
getCache: mock().mockResolvedValue(void 0),
|
|
2609
|
+
getCache: mock().mockResolvedValue(undefined),
|
|
2837
2610
|
setCache: mock().mockResolvedValue(true),
|
|
2838
2611
|
deleteCache: mock().mockResolvedValue(true),
|
|
2839
|
-
// Task Management
|
|
2840
2612
|
createTask: mock().mockResolvedValue("test-task-id"),
|
|
2841
2613
|
getTasks: mock().mockResolvedValue([]),
|
|
2842
2614
|
getTask: mock().mockResolvedValue(null),
|
|
2843
2615
|
getTasksByName: mock().mockResolvedValue([]),
|
|
2844
|
-
updateTask: mock().mockResolvedValue(
|
|
2845
|
-
deleteTask: mock().mockResolvedValue(
|
|
2846
|
-
// Apply overrides
|
|
2616
|
+
updateTask: mock().mockResolvedValue(undefined),
|
|
2617
|
+
deleteTask: mock().mockResolvedValue(undefined),
|
|
2847
2618
|
...overrides
|
|
2848
2619
|
};
|
|
2849
2620
|
return baseDatabaseAdapter;
|
|
@@ -2863,31 +2634,24 @@ function createMockDbConnection(overrides = {}) {
|
|
|
2863
2634
|
...overrides
|
|
2864
2635
|
};
|
|
2865
2636
|
}
|
|
2866
|
-
|
|
2867
2637
|
// src/mocks/services.ts
|
|
2868
2638
|
import { ServiceType } from "@elizaos/core";
|
|
2869
2639
|
function createMockService(serviceType = ServiceType.UNKNOWN, overrides = {}) {
|
|
2870
2640
|
const baseService = {
|
|
2871
|
-
// Static properties (would be on the class)
|
|
2872
2641
|
serviceType,
|
|
2873
|
-
// Instance properties
|
|
2874
2642
|
capabilityDescription: `Mock service for testing`,
|
|
2875
2643
|
config: {
|
|
2876
2644
|
enabled: true,
|
|
2877
2645
|
mockData: true,
|
|
2878
2646
|
...overrides.config
|
|
2879
2647
|
},
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
start: mock().mockResolvedValue(void 0),
|
|
2884
|
-
initialize: mock().mockResolvedValue(void 0),
|
|
2648
|
+
stop: mock().mockResolvedValue(undefined),
|
|
2649
|
+
start: mock().mockResolvedValue(undefined),
|
|
2650
|
+
initialize: mock().mockResolvedValue(undefined),
|
|
2885
2651
|
isReady: mock().mockReturnValue(true),
|
|
2886
2652
|
getStatus: mock().mockReturnValue("active"),
|
|
2887
|
-
restart: mock().mockResolvedValue(
|
|
2888
|
-
// Runtime property (protected in Service class, but needed for mocks)
|
|
2653
|
+
restart: mock().mockResolvedValue(undefined),
|
|
2889
2654
|
runtime: null,
|
|
2890
|
-
// Apply overrides
|
|
2891
2655
|
...overrides
|
|
2892
2656
|
};
|
|
2893
2657
|
return baseService;
|
|
@@ -2899,7 +2663,7 @@ function createMockDatabaseService(overrides = {}) {
|
|
|
2899
2663
|
});
|
|
2900
2664
|
}
|
|
2901
2665
|
function createMockCacheService(overrides = {}) {
|
|
2902
|
-
const cache =
|
|
2666
|
+
const cache = new Map;
|
|
2903
2667
|
return createMockService(ServiceType.UNKNOWN, {
|
|
2904
2668
|
capabilityDescription: "Provides in-memory caching capabilities",
|
|
2905
2669
|
...overrides
|
|
@@ -2930,7 +2694,7 @@ function createMockMessagingService(overrides = {}) {
|
|
|
2930
2694
|
});
|
|
2931
2695
|
}
|
|
2932
2696
|
function createMockServiceMap(services = []) {
|
|
2933
|
-
const serviceMap =
|
|
2697
|
+
const serviceMap = new Map;
|
|
2934
2698
|
if (services.length === 0) {
|
|
2935
2699
|
services = [
|
|
2936
2700
|
{ name: "database", type: ServiceType.UNKNOWN },
|
|
@@ -2953,67 +2717,69 @@ function registerMockServices(runtime, services = []) {
|
|
|
2953
2717
|
return runtime;
|
|
2954
2718
|
}
|
|
2955
2719
|
export {
|
|
2956
|
-
|
|
2957
|
-
IntegrationTestTemplate,
|
|
2958
|
-
PerformanceTestTemplate,
|
|
2959
|
-
PluginTestTemplate,
|
|
2960
|
-
RuntimeTestHarness,
|
|
2961
|
-
TestDataGenerator,
|
|
2962
|
-
TestDatabaseManager,
|
|
2963
|
-
TestModelProvider,
|
|
2964
|
-
TestScenarioBuilder,
|
|
2965
|
-
TestSuite,
|
|
2966
|
-
TestTemplate,
|
|
2967
|
-
UnitTestTemplate,
|
|
2968
|
-
createErrorTest,
|
|
2969
|
-
createIntegrationTest,
|
|
2970
|
-
createMinimalMockCharacter,
|
|
2971
|
-
createMockActionResult,
|
|
2972
|
-
createMockAgentResponse,
|
|
2973
|
-
createMockBlockchainService,
|
|
2974
|
-
createMockCacheService,
|
|
2975
|
-
createMockCharacter,
|
|
2976
|
-
createMockContent,
|
|
2977
|
-
createMockConversation,
|
|
2978
|
-
createMockConversationState,
|
|
2979
|
-
createMockDatabase,
|
|
2980
|
-
createMockDatabaseService,
|
|
2981
|
-
createMockDbConnection,
|
|
2982
|
-
createMockFact,
|
|
2983
|
-
createMockHttpService,
|
|
2984
|
-
createMockMedia,
|
|
2985
|
-
createMockMemory,
|
|
2986
|
-
createMockMemoryWithEmbedding,
|
|
2987
|
-
createMockMessagingService,
|
|
2988
|
-
createMockModelService,
|
|
2989
|
-
createMockProviderResult,
|
|
2990
|
-
createMockRuntime,
|
|
2991
|
-
createMockService,
|
|
2992
|
-
createMockServiceMap,
|
|
2993
|
-
createMockState,
|
|
2994
|
-
createMockStateWithActions,
|
|
2995
|
-
createMockStateWithProvider,
|
|
2996
|
-
createMockUserMessage,
|
|
2997
|
-
createModelHandler,
|
|
2998
|
-
createMultiAgentScenario,
|
|
2999
|
-
createMultipleCharacters,
|
|
3000
|
-
createPerformanceTest,
|
|
3001
|
-
createPluginTest,
|
|
3002
|
-
createPluginTestCharacter,
|
|
3003
|
-
createPluginTestScenario,
|
|
3004
|
-
createRichConversationCharacter,
|
|
3005
|
-
createSpecializedModelProvider,
|
|
3006
|
-
createTestAction,
|
|
3007
|
-
createTestDatabase,
|
|
3008
|
-
createTestEnvironment,
|
|
3009
|
-
createTestEvaluator,
|
|
3010
|
-
createTestModelProvider,
|
|
3011
|
-
createTestProvider,
|
|
3012
|
-
createTestRuntime,
|
|
3013
|
-
createUnitTest,
|
|
3014
|
-
mock,
|
|
3015
|
-
registerMockServices,
|
|
2720
|
+
scenarios,
|
|
3016
2721
|
runIntegrationTest,
|
|
3017
|
-
|
|
2722
|
+
registerMockServices,
|
|
2723
|
+
mock,
|
|
2724
|
+
createUnitTest,
|
|
2725
|
+
createTestRuntime,
|
|
2726
|
+
createTestProvider,
|
|
2727
|
+
createTestModelProvider,
|
|
2728
|
+
createTestEvaluator,
|
|
2729
|
+
createTestEnvironment,
|
|
2730
|
+
createTestDatabase,
|
|
2731
|
+
createTestAction,
|
|
2732
|
+
createSpecializedModelProvider,
|
|
2733
|
+
createRichConversationCharacter,
|
|
2734
|
+
createPluginTestScenario,
|
|
2735
|
+
createPluginTestCharacter,
|
|
2736
|
+
createPluginTest,
|
|
2737
|
+
createPerformanceTest,
|
|
2738
|
+
createMultipleCharacters,
|
|
2739
|
+
createMultiAgentScenario,
|
|
2740
|
+
createModelHandler,
|
|
2741
|
+
createMockUserMessage,
|
|
2742
|
+
createMockStateWithProvider,
|
|
2743
|
+
createMockStateWithActions,
|
|
2744
|
+
createMockState,
|
|
2745
|
+
createMockServiceMap,
|
|
2746
|
+
createMockService,
|
|
2747
|
+
createMockRuntime,
|
|
2748
|
+
createMockProviderResult,
|
|
2749
|
+
createMockModelService,
|
|
2750
|
+
createMockMessagingService,
|
|
2751
|
+
createMockMemoryWithEmbedding,
|
|
2752
|
+
createMockMemory,
|
|
2753
|
+
createMockMedia,
|
|
2754
|
+
createMockHttpService,
|
|
2755
|
+
createMockFact,
|
|
2756
|
+
createMockDbConnection,
|
|
2757
|
+
createMockDatabaseService,
|
|
2758
|
+
createMockDatabase,
|
|
2759
|
+
createMockConversationState,
|
|
2760
|
+
createMockConversation,
|
|
2761
|
+
createMockContent,
|
|
2762
|
+
createMockCharacter,
|
|
2763
|
+
createMockCacheService,
|
|
2764
|
+
createMockBlockchainService,
|
|
2765
|
+
createMockAgentResponse,
|
|
2766
|
+
createMockActionResult,
|
|
2767
|
+
createMinimalMockCharacter,
|
|
2768
|
+
createIntegrationTest,
|
|
2769
|
+
createErrorTest,
|
|
2770
|
+
UnitTestTemplate,
|
|
2771
|
+
TestTemplate,
|
|
2772
|
+
TestSuite,
|
|
2773
|
+
TestScenarioBuilder,
|
|
2774
|
+
TestModelProvider,
|
|
2775
|
+
TestDatabaseManager,
|
|
2776
|
+
TestDataGenerator,
|
|
2777
|
+
RuntimeTestHarness,
|
|
2778
|
+
PluginTestTemplate,
|
|
2779
|
+
PerformanceTestTemplate,
|
|
2780
|
+
IntegrationTestTemplate,
|
|
2781
|
+
ErrorTestTemplate
|
|
3018
2782
|
};
|
|
3019
|
-
|
|
2783
|
+
|
|
2784
|
+
//# debugId=E46556112309126564756E2164756E21
|
|
2785
|
+
//# sourceMappingURL=index.js.map
|