@elizaos/test-utils 1.6.5 → 1.7.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/DatabaseTestRegistry.d.ts.map +1 -1
- package/dist/TestInfrastructure.d.ts +2 -2
- package/dist/TestInfrastructure.d.ts.map +1 -1
- package/dist/index.js +123 -42
- package/dist/index.js.map +11 -11
- package/dist/mocks/database.d.ts +4 -0
- package/dist/mocks/database.d.ts.map +1 -1
- package/dist/mocks/mockUtils.d.ts.map +1 -1
- package/dist/mocks/runtime.d.ts.map +1 -1
- package/dist/mocks/services.d.ts.map +1 -1
- package/dist/mocks/state.d.ts.map +1 -1
- package/dist/realRuntime.d.ts.map +1 -1
- package/dist/templates.d.ts.map +1 -1
- package/dist/testDatabase.d.ts.map +1 -1
- package/dist/testModels.d.ts.map +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DatabaseTestRegistry.d.ts","sourceRoot":"","sources":["../src/DatabaseTestRegistry.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,
|
|
1
|
+
{"version":3,"file":"DatabaseTestRegistry.d.ts","sourceRoot":"","sources":["../src/DatabaseTestRegistry.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEtD,MAAM,WAAW,wBAAwB;IACvC,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,oBAAoB,EAAE,OAAO,CAAC;IAC9B,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,kBAAkB;IACjC,+BAA+B;IAC/B,gBAAgB,EAAE,YAAY,GAAG,MAAM,CAAC;IACxC,wCAAwC;IACxC,iBAAiB,EAAE,OAAO,CAAC;IAC3B,2BAA2B;IAC3B,SAAS,EAAE,QAAQ,GAAG,UAAU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MAAM,CAAC;QACrB,iBAAiB,EAAE,MAAM,CAAC;KAC3B,CAAC;CACH;AAED,MAAM,WAAW,wBAAwB;IACvC,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,eAAe,EAAE,MAAM,EAAE,CAAC;CAC3B;AAED,MAAM,WAAW,iBAAiB;IAChC,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,cAAc,EAAE,oBAAoB,GAAG,IAAI,CAAC;IAC5C,cAAc,EAAE,oBAAoB,GAAG,IAAI,CAAC;CAC7C"}
|
|
@@ -55,10 +55,10 @@ export declare class TestDataBuilder {
|
|
|
55
55
|
names: string[];
|
|
56
56
|
metadata?: Record<string, any>;
|
|
57
57
|
}): Promise<UUID>;
|
|
58
|
-
static createTestConversation(runtime: IAgentRuntime, participants:
|
|
58
|
+
static createTestConversation(runtime: IAgentRuntime, participants: UUID[], messageCount?: number): Promise<{
|
|
59
59
|
roomId: `${string}-${string}-${string}-${string}-${string}`;
|
|
60
60
|
messages: Memory[];
|
|
61
61
|
}>;
|
|
62
|
-
static createTestMemories(runtime: IAgentRuntime, roomId:
|
|
62
|
+
static createTestMemories(runtime: IAgentRuntime, roomId: UUID, count?: number): Promise<Memory[]>;
|
|
63
63
|
}
|
|
64
64
|
//# sourceMappingURL=TestInfrastructure.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TestInfrastructure.d.ts","sourceRoot":"","sources":["../src/TestInfrastructure.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"TestInfrastructure.d.ts","sourceRoot":"","sources":["../src/TestInfrastructure.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,gBAAgB,EAChB,IAAI,EAEJ,MAAM,EAEP,MAAM,eAAe,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AI,YAAY,IAAI,gBAAgB,CAKnC;IAED;;OAEG;IACG,kBAAkB,CAAC,CAAC,EACxB,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAC3B,SAAS,EAAE,MAAM,qBAAqB,EACtC,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,CAAC,CAAC;CAcd;AAED;;GAEG;AACH,qBAAa,eAAe;WACb,YAAY,CACvB,OAAO,EAAE,aAAa,EACtB,IAAI,EAAE;QACJ,KAAK,EAAE,MAAM,EAAE,CAAC;QAChB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KAChC,GACA,OAAO,CAAC,IAAI,CAAC;WAWH,sBAAsB,CACjC,OAAO,EAAE,aAAa,EACtB,YAAY,EAAE,IAAI,EAAE,EACpB,YAAY,GAAE,MAAU;;;;WA4Bb,kBAAkB,CAAC,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,GAAE,MAAW;CAkBzF"}
|
package/dist/index.js
CHANGED
|
@@ -61,12 +61,12 @@ class TestDatabaseManager {
|
|
|
61
61
|
tempPaths = new Set;
|
|
62
62
|
async createIsolatedDatabase(testId) {
|
|
63
63
|
try {
|
|
64
|
-
logger.debug(`Creating isolated test database for ${testId}`);
|
|
64
|
+
logger.debug({ src: "test-utils:test-database", testId }, `Creating isolated test database for ${testId}`);
|
|
65
65
|
let adapter;
|
|
66
66
|
try {
|
|
67
|
-
logger.debug(`Attempting to load PostgreSQL adapter for ${testId}`);
|
|
67
|
+
logger.debug({ src: "test-utils:test-database", testId }, `Attempting to load PostgreSQL adapter for ${testId}`);
|
|
68
68
|
if (process.env.FORCE_MOCK_DB === "true") {
|
|
69
|
-
logger.warn("FORCE_MOCK_DB is set - using mock database");
|
|
69
|
+
logger.warn({ src: "test-utils:test-database" }, "FORCE_MOCK_DB is set - using mock database");
|
|
70
70
|
adapter = this.createMockDatabase(testId);
|
|
71
71
|
} else {
|
|
72
72
|
try {
|
|
@@ -81,22 +81,32 @@ class TestDatabaseManager {
|
|
|
81
81
|
adapter = await sqlPlugin.createDatabaseAdapter({
|
|
82
82
|
postgresUrl
|
|
83
83
|
}, "11111111-2222-3333-4444-555555555555");
|
|
84
|
-
logger.debug(`Successfully created PostgreSQL adapter for ${testId}`);
|
|
84
|
+
logger.debug({ src: "test-utils:test-database", testId }, `Successfully created PostgreSQL adapter for ${testId}`);
|
|
85
85
|
} catch (importError) {
|
|
86
|
-
logger.warn(
|
|
86
|
+
logger.warn({
|
|
87
|
+
src: "test-utils:test-database",
|
|
88
|
+
error: importError instanceof Error ? importError.message : String(importError)
|
|
89
|
+
}, `SQL plugin not available: ${importError instanceof Error ? importError.message : String(importError)} - falling back to mock database`);
|
|
87
90
|
adapter = this.createMockDatabase(testId);
|
|
88
91
|
}
|
|
89
92
|
}
|
|
90
93
|
} catch (postgresError) {
|
|
91
|
-
logger.warn(
|
|
94
|
+
logger.warn({
|
|
95
|
+
src: "test-utils:test-database",
|
|
96
|
+
error: postgresError instanceof Error ? postgresError.message : String(postgresError)
|
|
97
|
+
}, `Failed to create PostgreSQL database: ${postgresError instanceof Error ? postgresError.message : String(postgresError)} - falling back to mock database`);
|
|
92
98
|
adapter = this.createMockDatabase(testId);
|
|
93
99
|
}
|
|
94
100
|
await adapter.init();
|
|
95
101
|
this.testDatabases.set(testId, adapter);
|
|
96
|
-
logger.debug(`Successfully created isolated database for ${testId}`);
|
|
102
|
+
logger.debug({ src: "test-utils:test-database", testId }, `Successfully created isolated database for ${testId}`);
|
|
97
103
|
return adapter;
|
|
98
104
|
} catch (error) {
|
|
99
|
-
logger.error(
|
|
105
|
+
logger.error({
|
|
106
|
+
src: "test-utils:test-database",
|
|
107
|
+
testId,
|
|
108
|
+
error: error instanceof Error ? error.message : String(error)
|
|
109
|
+
}, `Failed to create test database for ${testId}: ${error instanceof Error ? error.message : String(error)}`);
|
|
100
110
|
throw new Error(`Test database creation failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
101
111
|
}
|
|
102
112
|
}
|
|
@@ -116,10 +126,10 @@ class TestDatabaseManager {
|
|
|
116
126
|
const adapter = {
|
|
117
127
|
db: null,
|
|
118
128
|
async initialize() {
|
|
119
|
-
logger.debug(`Initialized mock database for ${testId}`);
|
|
129
|
+
logger.debug({ src: "test-utils:test-database", testId }, `Initialized mock database for ${testId}`);
|
|
120
130
|
},
|
|
121
131
|
async init() {
|
|
122
|
-
logger.debug(`Initialized mock database for ${testId}`);
|
|
132
|
+
logger.debug({ src: "test-utils:test-database", testId }, `Initialized mock database for ${testId}`);
|
|
123
133
|
},
|
|
124
134
|
async runMigrations() {},
|
|
125
135
|
async isReady() {
|
|
@@ -239,7 +249,7 @@ class TestDatabaseManager {
|
|
|
239
249
|
memories = memories.filter((m) => m.roomId === params.roomId);
|
|
240
250
|
}
|
|
241
251
|
if (params.query) {
|
|
242
|
-
memories = memories.filter((m) => m.content
|
|
252
|
+
memories = memories.filter((m) => typeof m.content === "object" && m.content !== null && ("text" in m.content) && typeof m.content.text === "string" ? m.content.text.toLowerCase().includes(params.query.toLowerCase()) : false);
|
|
243
253
|
}
|
|
244
254
|
return memories.slice(0, params.count || 10);
|
|
245
255
|
},
|
|
@@ -410,7 +420,7 @@ class TestDatabaseManager {
|
|
|
410
420
|
}
|
|
411
421
|
return null;
|
|
412
422
|
},
|
|
413
|
-
async countMemories(roomId, tableName = "messages") {
|
|
423
|
+
async countMemories(roomId, unique, tableName = "messages") {
|
|
414
424
|
const tableData = storage.memories.get(tableName);
|
|
415
425
|
if (!tableData) {
|
|
416
426
|
return 0;
|
|
@@ -418,7 +428,11 @@ class TestDatabaseManager {
|
|
|
418
428
|
if (!roomId) {
|
|
419
429
|
return tableData.size;
|
|
420
430
|
}
|
|
421
|
-
|
|
431
|
+
let memories = Array.from(tableData.values()).filter((m) => m.roomId === roomId);
|
|
432
|
+
if (unique) {
|
|
433
|
+
memories = memories.filter((m) => m.unique === true);
|
|
434
|
+
}
|
|
435
|
+
return memories.length;
|
|
422
436
|
},
|
|
423
437
|
async getMemoriesByEntityIds(entityIds, tableName = "messages") {
|
|
424
438
|
const tableData = storage.memories.get(tableName);
|
|
@@ -634,6 +648,10 @@ class TestDatabaseManager {
|
|
|
634
648
|
storage.participants.set(participantId, { entityId, roomId });
|
|
635
649
|
}
|
|
636
650
|
return true;
|
|
651
|
+
},
|
|
652
|
+
async isRoomParticipant(roomId, entityId) {
|
|
653
|
+
const participantId = `${entityId}-${roomId}`;
|
|
654
|
+
return storage.participants.has(participantId);
|
|
637
655
|
}
|
|
638
656
|
};
|
|
639
657
|
return adapter;
|
|
@@ -644,19 +662,23 @@ class TestDatabaseManager {
|
|
|
644
662
|
if (adapter) {
|
|
645
663
|
await adapter.close();
|
|
646
664
|
this.testDatabases.delete(testId);
|
|
647
|
-
logger.debug(`Cleaned up database for ${testId}`);
|
|
665
|
+
logger.debug({ src: "test-utils:test-database", testId }, `Cleaned up database for ${testId}`);
|
|
648
666
|
}
|
|
649
667
|
} catch (error) {
|
|
650
|
-
logger.warn(
|
|
668
|
+
logger.warn({
|
|
669
|
+
src: "test-utils:test-database",
|
|
670
|
+
testId,
|
|
671
|
+
error: error instanceof Error ? error.message : String(error)
|
|
672
|
+
}, `Error cleaning up database ${testId}: ${error instanceof Error ? error.message : String(error)}`);
|
|
651
673
|
}
|
|
652
674
|
}
|
|
653
675
|
async cleanup() {
|
|
654
|
-
logger.debug("Cleaning up all test databases");
|
|
676
|
+
logger.debug({ src: "test-utils:test-database" }, "Cleaning up all test databases");
|
|
655
677
|
const cleanupPromises = Array.from(this.testDatabases.keys()).map((testId) => this.cleanupDatabase(testId));
|
|
656
678
|
await Promise.all(cleanupPromises);
|
|
657
679
|
this.tempPaths.clear();
|
|
658
680
|
this.testDatabases.clear();
|
|
659
|
-
logger.debug("Successfully cleaned up all test databases");
|
|
681
|
+
logger.debug({ src: "test-utils:test-database" }, "Successfully cleaned up all test databases");
|
|
660
682
|
}
|
|
661
683
|
getStats() {
|
|
662
684
|
return {
|
|
@@ -793,7 +815,10 @@ class TestModelProvider {
|
|
|
793
815
|
this.addToHistory(prompt, intelligentResponse);
|
|
794
816
|
return intelligentResponse;
|
|
795
817
|
} catch (error) {
|
|
796
|
-
logger2.warn(
|
|
818
|
+
logger2.warn({
|
|
819
|
+
src: "test-utils:test-models",
|
|
820
|
+
error: error instanceof Error ? error.message : String(error)
|
|
821
|
+
}, `Error in test model provider: ${error instanceof Error ? error.message : String(error)}`);
|
|
797
822
|
return this.defaultResponse;
|
|
798
823
|
}
|
|
799
824
|
}
|
|
@@ -1042,7 +1067,7 @@ class RuntimeTestHarness {
|
|
|
1042
1067
|
}
|
|
1043
1068
|
async createTestRuntime(config) {
|
|
1044
1069
|
try {
|
|
1045
|
-
logger3.info(`Creating real test runtime for ${this.testId}`);
|
|
1070
|
+
logger3.info({ src: "test-utils:real-runtime", testId: this.testId }, `Creating real test runtime for ${this.testId}`);
|
|
1046
1071
|
const databaseAdapter = await this.databaseManager.createIsolatedDatabase(`${this.testId}-${Date.now()}`);
|
|
1047
1072
|
const runtime = new AgentRuntime({
|
|
1048
1073
|
character: config.character,
|
|
@@ -1058,31 +1083,42 @@ class RuntimeTestHarness {
|
|
|
1058
1083
|
}
|
|
1059
1084
|
await runtime.initialize();
|
|
1060
1085
|
this.runtimes.set(runtime.agentId, runtime);
|
|
1061
|
-
logger3.info(`Successfully created real runtime ${runtime.agentId}`);
|
|
1086
|
+
logger3.info({ src: "test-utils:real-runtime", agentId: runtime.agentId }, `Successfully created real runtime ${runtime.agentId}`);
|
|
1062
1087
|
return runtime;
|
|
1063
1088
|
} catch (error) {
|
|
1064
|
-
logger3.error(
|
|
1089
|
+
logger3.error({
|
|
1090
|
+
src: "test-utils:real-runtime",
|
|
1091
|
+
error: error instanceof Error ? error.message : String(error)
|
|
1092
|
+
}, `Failed to create test runtime: ${error instanceof Error ? error.message : String(error)}`);
|
|
1065
1093
|
throw new Error(`Test runtime creation failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
1066
1094
|
}
|
|
1067
1095
|
}
|
|
1068
1096
|
async loadPlugin(pluginName) {
|
|
1069
1097
|
try {
|
|
1070
|
-
logger3.info(`Attempting to load plugin: ${pluginName}`);
|
|
1098
|
+
logger3.info({ src: "test-utils:real-runtime", pluginName }, `Attempting to load plugin: ${pluginName}`);
|
|
1071
1099
|
let pluginModule;
|
|
1072
1100
|
try {
|
|
1073
1101
|
pluginModule = await import(pluginName);
|
|
1074
1102
|
} catch (importError) {
|
|
1075
|
-
logger3.warn(
|
|
1103
|
+
logger3.warn({
|
|
1104
|
+
src: "test-utils:real-runtime",
|
|
1105
|
+
pluginName,
|
|
1106
|
+
error: importError instanceof Error ? importError.message : String(importError)
|
|
1107
|
+
}, `Could not import ${pluginName}: ${importError instanceof Error ? importError.message : String(importError)}`);
|
|
1076
1108
|
throw importError;
|
|
1077
1109
|
}
|
|
1078
1110
|
const plugin = pluginModule.default || pluginModule[Object.keys(pluginModule)[0]];
|
|
1079
1111
|
if (!plugin || typeof plugin !== "object") {
|
|
1080
1112
|
throw new Error(`Invalid plugin export from ${pluginName}`);
|
|
1081
1113
|
}
|
|
1082
|
-
logger3.info(`Successfully loaded plugin: ${pluginName}`);
|
|
1114
|
+
logger3.info({ src: "test-utils:real-runtime", pluginName }, `Successfully loaded plugin: ${pluginName}`);
|
|
1083
1115
|
return plugin;
|
|
1084
1116
|
} catch (error) {
|
|
1085
|
-
logger3.error(
|
|
1117
|
+
logger3.error({
|
|
1118
|
+
src: "test-utils:real-runtime",
|
|
1119
|
+
pluginName,
|
|
1120
|
+
error: error instanceof Error ? error.message : String(error)
|
|
1121
|
+
}, `Failed to load plugin ${pluginName}: ${error instanceof Error ? error.message : String(error)}`);
|
|
1086
1122
|
throw new Error(`Plugin ${pluginName} must be available for testing. Install it before running tests. Error: ${error instanceof Error ? error.message : String(error)}`);
|
|
1087
1123
|
}
|
|
1088
1124
|
}
|
|
@@ -1173,7 +1209,10 @@ class RuntimeTestHarness {
|
|
|
1173
1209
|
}
|
|
1174
1210
|
return [...new Set(actions)];
|
|
1175
1211
|
} catch (error) {
|
|
1176
|
-
logger3.warn(
|
|
1212
|
+
logger3.warn({
|
|
1213
|
+
src: "test-utils:real-runtime",
|
|
1214
|
+
error: error instanceof Error ? error.message : String(error)
|
|
1215
|
+
}, `Could not retrieve executed actions: ${error instanceof Error ? error.message : String(error)}`);
|
|
1177
1216
|
return [];
|
|
1178
1217
|
}
|
|
1179
1218
|
}
|
|
@@ -1235,20 +1274,27 @@ class RuntimeTestHarness {
|
|
|
1235
1274
|
}
|
|
1236
1275
|
async cleanup() {
|
|
1237
1276
|
try {
|
|
1238
|
-
logger3.info(`Cleaning up test harness ${this.testId}`);
|
|
1277
|
+
logger3.info({ src: "test-utils:real-runtime", testId: this.testId }, `Cleaning up test harness ${this.testId}`);
|
|
1239
1278
|
for (const [runtimeId, runtime] of this.runtimes) {
|
|
1240
1279
|
try {
|
|
1241
1280
|
await runtime.stop();
|
|
1242
|
-
logger3.debug(`Stopped runtime ${runtimeId}`);
|
|
1281
|
+
logger3.debug({ src: "test-utils:real-runtime", runtimeId }, `Stopped runtime ${runtimeId}`);
|
|
1243
1282
|
} catch (error) {
|
|
1244
|
-
logger3.warn(
|
|
1283
|
+
logger3.warn({
|
|
1284
|
+
src: "test-utils:real-runtime",
|
|
1285
|
+
runtimeId,
|
|
1286
|
+
error: error instanceof Error ? error.message : String(error)
|
|
1287
|
+
}, `Error stopping runtime ${runtimeId}: ${error instanceof Error ? error.message : String(error)}`);
|
|
1245
1288
|
}
|
|
1246
1289
|
}
|
|
1247
1290
|
this.runtimes.clear();
|
|
1248
1291
|
await this.databaseManager.cleanup();
|
|
1249
|
-
logger3.info(`Successfully cleaned up test harness ${this.testId}`);
|
|
1292
|
+
logger3.info({ src: "test-utils:real-runtime", testId: this.testId }, `Successfully cleaned up test harness ${this.testId}`);
|
|
1250
1293
|
} catch (error) {
|
|
1251
|
-
logger3.error(
|
|
1294
|
+
logger3.error({
|
|
1295
|
+
src: "test-utils:real-runtime",
|
|
1296
|
+
error: error instanceof Error ? error.message : String(error)
|
|
1297
|
+
}, `Error during cleanup: ${error instanceof Error ? error.message : String(error)}`);
|
|
1252
1298
|
throw error;
|
|
1253
1299
|
}
|
|
1254
1300
|
}
|
|
@@ -1569,15 +1615,20 @@ class TestSuite {
|
|
|
1569
1615
|
async run() {
|
|
1570
1616
|
const startTime = Date.now();
|
|
1571
1617
|
const results = [];
|
|
1572
|
-
logger4.info(`Running test suite: ${this.name}`);
|
|
1618
|
+
logger4.info({ src: "test-utils:templates", suiteName: this.name }, `Running test suite: ${this.name}`);
|
|
1573
1619
|
for (const test of this.tests) {
|
|
1574
1620
|
try {
|
|
1575
1621
|
const result = await test.execute();
|
|
1576
1622
|
results.push(result);
|
|
1577
1623
|
if (result.passed) {
|
|
1578
|
-
logger4.info(`✓ ${result.name} (${result.duration}ms)`);
|
|
1624
|
+
logger4.info({ src: "test-utils:templates", testName: result.name, duration: result.duration }, `✓ ${result.name} (${result.duration}ms)`);
|
|
1579
1625
|
} else {
|
|
1580
|
-
logger4.error(
|
|
1626
|
+
logger4.error({
|
|
1627
|
+
src: "test-utils:templates",
|
|
1628
|
+
testName: result.name,
|
|
1629
|
+
duration: result.duration,
|
|
1630
|
+
error: result.error?.message
|
|
1631
|
+
}, `✗ ${result.name} (${result.duration}ms): ${result.error?.message}`);
|
|
1581
1632
|
}
|
|
1582
1633
|
} catch (error) {
|
|
1583
1634
|
const errorResult = {
|
|
@@ -1587,13 +1638,23 @@ class TestSuite {
|
|
|
1587
1638
|
error: error instanceof Error ? error : new Error(String(error))
|
|
1588
1639
|
};
|
|
1589
1640
|
results.push(errorResult);
|
|
1590
|
-
logger4.error(
|
|
1641
|
+
logger4.error({
|
|
1642
|
+
src: "test-utils:templates",
|
|
1643
|
+
testName: errorResult.name,
|
|
1644
|
+
error: errorResult.error?.message
|
|
1645
|
+
}, `✗ ${errorResult.name}: ${errorResult.error?.message}`);
|
|
1591
1646
|
}
|
|
1592
1647
|
}
|
|
1593
1648
|
const passed = results.filter((r) => r.passed).length;
|
|
1594
1649
|
const failed = results.length - passed;
|
|
1595
1650
|
const duration = Date.now() - startTime;
|
|
1596
|
-
logger4.info(
|
|
1651
|
+
logger4.info({
|
|
1652
|
+
src: "test-utils:templates",
|
|
1653
|
+
suiteName: this.name,
|
|
1654
|
+
passed,
|
|
1655
|
+
total: results.length,
|
|
1656
|
+
duration
|
|
1657
|
+
}, `Test suite ${this.name} completed: ${passed}/${results.length} passed (${duration}ms)`);
|
|
1597
1658
|
return {
|
|
1598
1659
|
suiteName: this.name,
|
|
1599
1660
|
totalTests: results.length,
|
|
@@ -1741,6 +1802,7 @@ function createMockRuntime(overrides = {}) {
|
|
|
1741
1802
|
const stateCache = overrides.stateCache || new Map;
|
|
1742
1803
|
const baseRuntime = {
|
|
1743
1804
|
agentId: "test-agent-id",
|
|
1805
|
+
initPromise: overrides.initPromise || Promise.resolve(),
|
|
1744
1806
|
character: overrides.character || defaultCharacter,
|
|
1745
1807
|
messageService: overrides.messageService ?? null,
|
|
1746
1808
|
providers: overrides.providers || [],
|
|
@@ -1763,7 +1825,20 @@ function createMockRuntime(overrides = {}) {
|
|
|
1763
1825
|
progress: () => {},
|
|
1764
1826
|
log: () => {},
|
|
1765
1827
|
clear: () => {},
|
|
1766
|
-
child: () => ({
|
|
1828
|
+
child: () => ({
|
|
1829
|
+
level: "info",
|
|
1830
|
+
trace: () => {},
|
|
1831
|
+
debug: () => {},
|
|
1832
|
+
info: () => {},
|
|
1833
|
+
warn: () => {},
|
|
1834
|
+
error: () => {},
|
|
1835
|
+
fatal: () => {},
|
|
1836
|
+
success: () => {},
|
|
1837
|
+
progress: () => {},
|
|
1838
|
+
log: () => {},
|
|
1839
|
+
clear: () => {},
|
|
1840
|
+
child: () => ({})
|
|
1841
|
+
})
|
|
1767
1842
|
},
|
|
1768
1843
|
stateCache,
|
|
1769
1844
|
db: overrides.db || mockDb,
|
|
@@ -2112,13 +2187,15 @@ function createMockActionResult(overrides = {}) {
|
|
|
2112
2187
|
return baseResult;
|
|
2113
2188
|
}
|
|
2114
2189
|
function createMockStateWithProvider(providerName, providerData, overrides = {}) {
|
|
2190
|
+
const providersOverride = overrides.data?.providers ?? {};
|
|
2191
|
+
const dataOverride = overrides.data ?? {};
|
|
2115
2192
|
return createMockState({
|
|
2116
2193
|
data: {
|
|
2117
2194
|
providers: {
|
|
2118
2195
|
[providerName]: providerData,
|
|
2119
|
-
...
|
|
2196
|
+
...providersOverride
|
|
2120
2197
|
},
|
|
2121
|
-
...
|
|
2198
|
+
...dataOverride
|
|
2122
2199
|
},
|
|
2123
2200
|
text: `[${providerName}]
|
|
2124
2201
|
${JSON.stringify(providerData, null, 2)}
|
|
@@ -2142,6 +2219,8 @@ function createMockStateWithActions(actionResults, overrides = {}) {
|
|
|
2142
2219
|
}
|
|
2143
2220
|
function createMockConversationState(conversationHistory = ["Hello", "Hi there!", "How are you?"], currentUser = "TestUser", overrides = {}) {
|
|
2144
2221
|
const recentContext = conversationHistory.slice(-3).join(" | ");
|
|
2222
|
+
const providersOverride = overrides.data?.providers ?? {};
|
|
2223
|
+
const dataOverride = overrides.data ?? {};
|
|
2145
2224
|
return createMockState({
|
|
2146
2225
|
values: {
|
|
2147
2226
|
userName: currentUser,
|
|
@@ -2157,9 +2236,9 @@ function createMockConversationState(conversationHistory = ["Hello", "Hi there!"
|
|
|
2157
2236
|
count: conversationHistory.length,
|
|
2158
2237
|
lastSpeaker: conversationHistory.length % 2 === 0 ? "agent" : "user"
|
|
2159
2238
|
},
|
|
2160
|
-
...
|
|
2239
|
+
...providersOverride
|
|
2161
2240
|
},
|
|
2162
|
-
...
|
|
2241
|
+
...dataOverride
|
|
2163
2242
|
},
|
|
2164
2243
|
text: `[CONVERSATION CONTEXT]
|
|
2165
2244
|
User: ${currentUser}
|
|
@@ -2646,6 +2725,7 @@ function createMockDatabase(overrides = {}) {
|
|
|
2646
2725
|
};
|
|
2647
2726
|
return baseDatabaseAdapter;
|
|
2648
2727
|
}
|
|
2728
|
+
var createMockDatabaseAdapter = createMockDatabase;
|
|
2649
2729
|
function createMockDbConnection(overrides = {}) {
|
|
2650
2730
|
return {
|
|
2651
2731
|
execute: mock().mockResolvedValue([]),
|
|
@@ -2782,6 +2862,7 @@ export {
|
|
|
2782
2862
|
createMockFact,
|
|
2783
2863
|
createMockDbConnection,
|
|
2784
2864
|
createMockDatabaseService,
|
|
2865
|
+
createMockDatabaseAdapter,
|
|
2785
2866
|
createMockDatabase,
|
|
2786
2867
|
createMockConversationState,
|
|
2787
2868
|
createMockConversation,
|
|
@@ -2808,5 +2889,5 @@ export {
|
|
|
2808
2889
|
ErrorTestTemplate
|
|
2809
2890
|
};
|
|
2810
2891
|
|
|
2811
|
-
//# debugId=
|
|
2892
|
+
//# debugId=C509FBC37EBDC1A464756E2164756E21
|
|
2812
2893
|
//# sourceMappingURL=index.js.map
|