@memberjunction/testing-engine 0.0.1 → 2.119.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.
Files changed (66) hide show
  1. package/README.md +403 -29
  2. package/dist/drivers/AgentEvalDriver.d.ts +197 -0
  3. package/dist/drivers/AgentEvalDriver.d.ts.map +1 -0
  4. package/dist/drivers/AgentEvalDriver.js +370 -0
  5. package/dist/drivers/AgentEvalDriver.js.map +1 -0
  6. package/dist/drivers/BaseTestDriver.d.ts +145 -0
  7. package/dist/drivers/BaseTestDriver.d.ts.map +1 -0
  8. package/dist/drivers/BaseTestDriver.js +266 -0
  9. package/dist/drivers/BaseTestDriver.js.map +1 -0
  10. package/dist/drivers/index.d.ts +6 -0
  11. package/dist/drivers/index.d.ts.map +1 -0
  12. package/dist/drivers/index.js +22 -0
  13. package/dist/drivers/index.js.map +1 -0
  14. package/dist/engine/TestEngine.d.ts +148 -0
  15. package/dist/engine/TestEngine.d.ts.map +1 -0
  16. package/dist/engine/TestEngine.js +490 -0
  17. package/dist/engine/TestEngine.js.map +1 -0
  18. package/dist/index.d.ts +20 -0
  19. package/dist/index.d.ts.map +1 -0
  20. package/dist/index.js +42 -0
  21. package/dist/index.js.map +1 -0
  22. package/dist/oracles/ExactMatchOracle.d.ts +98 -0
  23. package/dist/oracles/ExactMatchOracle.d.ts.map +1 -0
  24. package/dist/oracles/ExactMatchOracle.js +355 -0
  25. package/dist/oracles/ExactMatchOracle.js.map +1 -0
  26. package/dist/oracles/IOracle.d.ts +47 -0
  27. package/dist/oracles/IOracle.d.ts.map +1 -0
  28. package/dist/oracles/IOracle.js +7 -0
  29. package/dist/oracles/IOracle.js.map +1 -0
  30. package/dist/oracles/LLMJudgeOracle.d.ts +65 -0
  31. package/dist/oracles/LLMJudgeOracle.d.ts.map +1 -0
  32. package/dist/oracles/LLMJudgeOracle.js +214 -0
  33. package/dist/oracles/LLMJudgeOracle.js.map +1 -0
  34. package/dist/oracles/SQLValidatorOracle.d.ts +78 -0
  35. package/dist/oracles/SQLValidatorOracle.d.ts.map +1 -0
  36. package/dist/oracles/SQLValidatorOracle.js +215 -0
  37. package/dist/oracles/SQLValidatorOracle.js.map +1 -0
  38. package/dist/oracles/SchemaValidatorOracle.d.ts +61 -0
  39. package/dist/oracles/SchemaValidatorOracle.d.ts.map +1 -0
  40. package/dist/oracles/SchemaValidatorOracle.js +193 -0
  41. package/dist/oracles/SchemaValidatorOracle.js.map +1 -0
  42. package/dist/oracles/TraceValidatorOracle.d.ts +41 -0
  43. package/dist/oracles/TraceValidatorOracle.d.ts.map +1 -0
  44. package/dist/oracles/TraceValidatorOracle.js +159 -0
  45. package/dist/oracles/TraceValidatorOracle.js.map +1 -0
  46. package/dist/oracles/index.d.ts +10 -0
  47. package/dist/oracles/index.d.ts.map +1 -0
  48. package/dist/oracles/index.js +26 -0
  49. package/dist/oracles/index.js.map +1 -0
  50. package/dist/types.d.ts +428 -0
  51. package/dist/types.d.ts.map +1 -0
  52. package/dist/types.js +6 -0
  53. package/dist/types.js.map +1 -0
  54. package/dist/utils/cost-calculator.d.ts +92 -0
  55. package/dist/utils/cost-calculator.d.ts.map +1 -0
  56. package/dist/utils/cost-calculator.js +137 -0
  57. package/dist/utils/cost-calculator.js.map +1 -0
  58. package/dist/utils/result-formatter.d.ts +98 -0
  59. package/dist/utils/result-formatter.d.ts.map +1 -0
  60. package/dist/utils/result-formatter.js +252 -0
  61. package/dist/utils/result-formatter.js.map +1 -0
  62. package/dist/utils/scoring.d.ts +64 -0
  63. package/dist/utils/scoring.d.ts.map +1 -0
  64. package/dist/utils/scoring.js +140 -0
  65. package/dist/utils/scoring.js.map +1 -0
  66. package/package.json +36 -7
@@ -0,0 +1,428 @@
1
+ /**
2
+ * Core type definitions for the Testing Engine
3
+ */
4
+ import { UserInfo } from '@memberjunction/core';
5
+ import { TestEntity, TestRunEntity } from '@memberjunction/core-entities';
6
+ import { IOracle } from './oracles/IOracle';
7
+ /**
8
+ * Progress callback for test execution
9
+ */
10
+ export interface TestProgress {
11
+ /**
12
+ * Current execution step
13
+ */
14
+ step: string;
15
+ /**
16
+ * Progress percentage (0-100)
17
+ */
18
+ percentage: number;
19
+ /**
20
+ * Human-readable message
21
+ */
22
+ message: string;
23
+ /**
24
+ * Additional metadata
25
+ */
26
+ metadata?: {
27
+ testName?: string;
28
+ testRun?: any;
29
+ driverType?: string;
30
+ oracleType?: string;
31
+ [key: string]: any;
32
+ };
33
+ }
34
+ /**
35
+ * Options for running a single test
36
+ */
37
+ export interface TestRunOptions {
38
+ /**
39
+ * Verbose logging
40
+ */
41
+ verbose?: boolean;
42
+ /**
43
+ * Validate configuration without executing
44
+ */
45
+ dryRun?: boolean;
46
+ /**
47
+ * Environment context (dev, staging, prod)
48
+ */
49
+ environment?: string;
50
+ /**
51
+ * Git commit SHA for versioning
52
+ */
53
+ gitCommit?: string;
54
+ /**
55
+ * Agent/system version being tested
56
+ */
57
+ agentVersion?: string;
58
+ /**
59
+ * Override test configuration
60
+ */
61
+ configOverride?: Record<string, unknown>;
62
+ /**
63
+ * Progress callback for real-time updates
64
+ */
65
+ progressCallback?: (progress: TestProgress) => void;
66
+ }
67
+ /**
68
+ * Options for running a test suite
69
+ */
70
+ export interface SuiteRunOptions extends TestRunOptions {
71
+ /**
72
+ * Run tests in parallel
73
+ */
74
+ parallel?: boolean;
75
+ /**
76
+ * Stop on first failure
77
+ */
78
+ failFast?: boolean;
79
+ /**
80
+ * Maximum parallel tests (if parallel=true)
81
+ */
82
+ maxParallel?: number;
83
+ /**
84
+ * Run only specific sequence numbers
85
+ */
86
+ sequence?: number[];
87
+ }
88
+ /**
89
+ * Result from running a single test
90
+ */
91
+ export interface TestRunResult {
92
+ /**
93
+ * Test Run ID
94
+ */
95
+ testRunId: string;
96
+ /**
97
+ * Test ID
98
+ */
99
+ testId: string;
100
+ /**
101
+ * Test name (from lookup field)
102
+ */
103
+ testName: string;
104
+ /**
105
+ * Test execution status
106
+ */
107
+ status: 'Passed' | 'Failed' | 'Skipped' | 'Error';
108
+ /**
109
+ * Overall score (0.0000 to 1.0000)
110
+ */
111
+ score: number;
112
+ /**
113
+ * Number of checks that passed
114
+ */
115
+ passedChecks: number;
116
+ /**
117
+ * Number of checks that failed
118
+ */
119
+ failedChecks: number;
120
+ /**
121
+ * Total number of checks
122
+ */
123
+ totalChecks: number;
124
+ /**
125
+ * Oracle evaluation results
126
+ */
127
+ oracleResults: OracleResult[];
128
+ /**
129
+ * Target entity type (e.g., "AI Agent")
130
+ */
131
+ targetType: string;
132
+ /**
133
+ * Target entity ID (e.g., AIAgentRun.ID)
134
+ */
135
+ targetLogId: string;
136
+ /**
137
+ * Execution duration in milliseconds
138
+ */
139
+ durationMs: number;
140
+ /**
141
+ * Cost in USD
142
+ */
143
+ totalCost: number;
144
+ /**
145
+ * When execution started
146
+ */
147
+ startedAt: Date;
148
+ /**
149
+ * When execution completed
150
+ */
151
+ completedAt: Date;
152
+ /**
153
+ * Error message if status is Error
154
+ */
155
+ errorMessage?: string;
156
+ /**
157
+ * Iteration number for repeated tests (when RepeatCount > 1)
158
+ */
159
+ sequence?: number;
160
+ }
161
+ /**
162
+ * Result from running a test suite
163
+ */
164
+ export interface TestSuiteRunResult {
165
+ /**
166
+ * Suite Run ID
167
+ */
168
+ suiteRunId: string;
169
+ /**
170
+ * Suite ID
171
+ */
172
+ suiteId: string;
173
+ /**
174
+ * Suite name (from lookup field)
175
+ */
176
+ suiteName: string;
177
+ /**
178
+ * Suite execution status
179
+ */
180
+ status: 'Completed' | 'Failed' | 'Cancelled' | 'Pending' | 'Running';
181
+ /**
182
+ * Tests that passed
183
+ */
184
+ passedTests: number;
185
+ /**
186
+ * Tests that failed
187
+ */
188
+ failedTests: number;
189
+ /**
190
+ * Total tests
191
+ */
192
+ totalTests: number;
193
+ /**
194
+ * Average score across all tests
195
+ */
196
+ averageScore: number;
197
+ /**
198
+ * Individual test results
199
+ */
200
+ testResults: TestRunResult[];
201
+ /**
202
+ * Total duration in milliseconds
203
+ */
204
+ durationMs: number;
205
+ /**
206
+ * Total cost in USD
207
+ */
208
+ totalCost: number;
209
+ /**
210
+ * When execution started
211
+ */
212
+ startedAt: Date;
213
+ /**
214
+ * When execution completed
215
+ */
216
+ completedAt: Date;
217
+ }
218
+ /**
219
+ * Context for test driver execution
220
+ */
221
+ export interface DriverExecutionContext {
222
+ /**
223
+ * Test definition
224
+ */
225
+ test: TestEntity;
226
+ /**
227
+ * Test run entity (for bidirectional linking)
228
+ */
229
+ testRun: TestRunEntity;
230
+ /**
231
+ * User context for data access
232
+ */
233
+ contextUser: UserInfo;
234
+ /**
235
+ * Runtime options
236
+ */
237
+ options: TestRunOptions;
238
+ /**
239
+ * Oracle registry for evaluations
240
+ */
241
+ oracleRegistry: Map<string, IOracle>;
242
+ }
243
+ /**
244
+ * Result from driver execution
245
+ */
246
+ export interface DriverExecutionResult {
247
+ /**
248
+ * Target entity type (e.g., "AI Agent")
249
+ */
250
+ targetType: string;
251
+ /**
252
+ * Target entity ID
253
+ */
254
+ targetLogId: string;
255
+ /**
256
+ * Execution status
257
+ */
258
+ status: 'Passed' | 'Failed' | 'Error';
259
+ /**
260
+ * Overall score
261
+ */
262
+ score: number;
263
+ /**
264
+ * Oracle results
265
+ */
266
+ oracleResults: OracleResult[];
267
+ /**
268
+ * Number of checks that passed
269
+ */
270
+ passedChecks: number;
271
+ /**
272
+ * Number of checks that failed
273
+ */
274
+ failedChecks: number;
275
+ /**
276
+ * Total number of checks
277
+ */
278
+ totalChecks: number;
279
+ /**
280
+ * Input data used
281
+ */
282
+ inputData?: unknown;
283
+ /**
284
+ * Expected output data
285
+ */
286
+ expectedOutput?: unknown;
287
+ /**
288
+ * Actual output data
289
+ */
290
+ actualOutput?: unknown;
291
+ /**
292
+ * Cost in USD
293
+ */
294
+ totalCost?: number;
295
+ /**
296
+ * Duration in milliseconds
297
+ */
298
+ durationMs?: number;
299
+ /**
300
+ * Error message if status is Error
301
+ */
302
+ errorMessage?: string;
303
+ }
304
+ /**
305
+ * Oracle evaluation input
306
+ */
307
+ export interface OracleInput {
308
+ /**
309
+ * The test being evaluated
310
+ */
311
+ test: TestEntity;
312
+ /**
313
+ * Expected output from test definition
314
+ */
315
+ expectedOutput?: unknown;
316
+ /**
317
+ * Actual output from execution
318
+ */
319
+ actualOutput?: unknown;
320
+ /**
321
+ * Target entity (e.g., AgentRun)
322
+ */
323
+ targetEntity?: unknown;
324
+ /**
325
+ * User context
326
+ */
327
+ contextUser: UserInfo;
328
+ }
329
+ /**
330
+ * Oracle configuration (can have any additional properties)
331
+ */
332
+ export interface OracleConfig {
333
+ /**
334
+ * Oracle-specific configuration properties
335
+ */
336
+ [key: string]: unknown;
337
+ }
338
+ /**
339
+ * Oracle evaluation result
340
+ */
341
+ export interface OracleResult {
342
+ /**
343
+ * Oracle type that produced this result
344
+ */
345
+ oracleType: string;
346
+ /**
347
+ * Whether the oracle check passed
348
+ */
349
+ passed: boolean;
350
+ /**
351
+ * Numeric score (0.0 to 1.0)
352
+ */
353
+ score: number;
354
+ /**
355
+ * Human-readable message
356
+ */
357
+ message: string;
358
+ /**
359
+ * Additional details (oracle-specific)
360
+ */
361
+ details?: unknown;
362
+ }
363
+ /**
364
+ * Scoring weights for different evaluation dimensions
365
+ */
366
+ export interface ScoringWeights {
367
+ /**
368
+ * Weight for each oracle type
369
+ * Keys are oracle types, values are weights (should sum to 1.0)
370
+ */
371
+ [oracleType: string]: number;
372
+ }
373
+ /**
374
+ * Validation result for test configuration
375
+ */
376
+ export interface ValidationResult {
377
+ /**
378
+ * Whether validation passed
379
+ */
380
+ valid: boolean;
381
+ /**
382
+ * Validation errors (blocking issues)
383
+ */
384
+ errors: ValidationError[];
385
+ /**
386
+ * Validation warnings (non-blocking issues)
387
+ */
388
+ warnings: ValidationWarning[];
389
+ }
390
+ /**
391
+ * Validation error
392
+ */
393
+ export interface ValidationError {
394
+ /**
395
+ * Error category
396
+ */
397
+ category: 'configuration' | 'input' | 'expected-outcome';
398
+ /**
399
+ * Error message
400
+ */
401
+ message: string;
402
+ /**
403
+ * Field path (if applicable)
404
+ */
405
+ field?: string;
406
+ /**
407
+ * Suggested fix
408
+ */
409
+ suggestion?: string;
410
+ }
411
+ /**
412
+ * Validation warning
413
+ */
414
+ export interface ValidationWarning {
415
+ /**
416
+ * Warning category
417
+ */
418
+ category: 'best-practice' | 'performance' | 'cost';
419
+ /**
420
+ * Warning message
421
+ */
422
+ message: string;
423
+ /**
424
+ * Recommendation
425
+ */
426
+ recommendation?: string;
427
+ }
428
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EACL,UAAU,EACV,aAAa,EAKd,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,QAAQ,CAAC,EAAE;QACT,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,OAAO,CAAC,EAAE,GAAG,CAAC;QACd,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,SAAS,CAA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,MAAM,GAAG,MAAM,CAAC;CAC9B;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,KAAK,EAAE,OAAO,CAAC;IAEf;;OAEG;IACH,MAAM,EAAE,eAAe,EAAE,CAAC;IAE1B;;OAEG;IACH,QAAQ,EAAE,iBAAiB,EAAE,CAAC;CAC/B;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,QAAQ,EAAE,eAAe,GAAG,OAAO,GAAG,kBAAkB,CAAC;IAEzD;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,QAAQ,EAAE,eAAe,GAAG,aAAa,GAAG,MAAM,CAAC;IAEnD;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB"}
package/dist/types.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ /**
3
+ * Core type definitions for the Testing Engine
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA;;GAEG"}
@@ -0,0 +1,92 @@
1
+ /**
2
+ * @fileoverview Cost calculation utilities for test execution
3
+ * @module @memberjunction/testing-engine
4
+ */
5
+ import { UserInfo } from '@memberjunction/core';
6
+ import { AIAgentRunEntity } from '@memberjunction/core-entities';
7
+ /**
8
+ * Calculate total cost from AI Agent Run.
9
+ *
10
+ * Aggregates costs from all AI prompt runs within the agent run.
11
+ *
12
+ * @param agentRun - Agent run entity
13
+ * @param contextUser - User context
14
+ * @returns Total cost in dollars
15
+ */
16
+ export declare function calculateAgentRunCost(agentRun: AIAgentRunEntity, contextUser: UserInfo): Promise<number>;
17
+ /**
18
+ * Calculate cost from multiple test runs.
19
+ *
20
+ * @param testRunCosts - Array of individual test run costs
21
+ * @returns Total cost
22
+ */
23
+ export declare function aggregateTestRunCosts(testRunCosts: number[]): number;
24
+ /**
25
+ * Calculate average cost per test.
26
+ *
27
+ * @param totalCost - Total cost across all tests
28
+ * @param testCount - Number of tests
29
+ * @returns Average cost per test
30
+ */
31
+ export declare function calculateAverageCost(totalCost: number, testCount: number): number;
32
+ /**
33
+ * Format cost for display.
34
+ *
35
+ * @param cost - Cost in dollars
36
+ * @param precision - Decimal places (default: 4)
37
+ * @returns Formatted cost string
38
+ */
39
+ export declare function formatCost(cost: number, precision?: number): string;
40
+ /**
41
+ * Calculate cost per oracle evaluation.
42
+ *
43
+ * Used for tracking costs of LLM-based oracles.
44
+ *
45
+ * @param oracleResults - Oracle results with cost details
46
+ * @returns Map of oracle type to cost
47
+ */
48
+ export declare function calculateOracleCosts(oracleResults: Array<{
49
+ oracleType: string;
50
+ details?: {
51
+ llmCost?: number;
52
+ };
53
+ }>): Map<string, number>;
54
+ /**
55
+ * Calculate cost breakdown by component.
56
+ *
57
+ * @param testRunCost - Total test run cost
58
+ * @param oracleCosts - Costs by oracle type
59
+ * @returns Cost breakdown
60
+ */
61
+ export declare function calculateCostBreakdown(testRunCost: number, oracleCosts: Map<string, number>): {
62
+ agentExecution: number;
63
+ oracleEvaluation: number;
64
+ total: number;
65
+ breakdown: Array<{
66
+ component: string;
67
+ cost: number;
68
+ percentage: number;
69
+ }>;
70
+ };
71
+ /**
72
+ * Estimate cost for test suite.
73
+ *
74
+ * @param testCount - Number of tests
75
+ * @param avgCostPerTest - Average cost per test
76
+ * @returns Estimated total cost
77
+ */
78
+ export declare function estimateSuiteCost(testCount: number, avgCostPerTest: number): number;
79
+ /**
80
+ * Calculate cost efficiency metrics.
81
+ *
82
+ * @param totalCost - Total execution cost
83
+ * @param passedTests - Number of passed tests
84
+ * @param totalTests - Total number of tests
85
+ * @returns Cost efficiency metrics
86
+ */
87
+ export declare function calculateCostEfficiency(totalCost: number, passedTests: number, totalTests: number): {
88
+ costPerTest: number;
89
+ costPerPassedTest: number;
90
+ costEfficiencyRatio: number;
91
+ };
92
+ //# sourceMappingURL=cost-calculator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cost-calculator.d.ts","sourceRoot":"","sources":["../../src/utils/cost-calculator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAW,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAqB,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAEpF;;;;;;;;GAQG;AACH,wBAAsB,qBAAqB,CACvC,QAAQ,EAAE,gBAAgB,EAC1B,WAAW,EAAE,QAAQ,GACtB,OAAO,CAAC,MAAM,CAAC,CAGjB;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,YAAY,EAAE,MAAM,EAAE,GAAG,MAAM,CAEpE;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAEjF;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,GAAE,MAAU,GAAG,MAAM,CAUtE;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAChC,aAAa,EAAE,KAAK,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAClC,CAAC,GACH,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CASrB;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAClC,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GACjC;IACC,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB,EAAE,MAAM,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,KAAK,CAAC;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC7E,CAuBA;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,MAAM,CAEnF;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACnC,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,GACnB;IACC,WAAW,EAAE,MAAM,CAAC;IACpB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,mBAAmB,EAAE,MAAM,CAAC;CAC/B,CAUA"}
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ /**
3
+ * @fileoverview Cost calculation utilities for test execution
4
+ * @module @memberjunction/testing-engine
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.calculateCostEfficiency = exports.estimateSuiteCost = exports.calculateCostBreakdown = exports.calculateOracleCosts = exports.formatCost = exports.calculateAverageCost = exports.aggregateTestRunCosts = exports.calculateAgentRunCost = void 0;
8
+ /**
9
+ * Calculate total cost from AI Agent Run.
10
+ *
11
+ * Aggregates costs from all AI prompt runs within the agent run.
12
+ *
13
+ * @param agentRun - Agent run entity
14
+ * @param contextUser - User context
15
+ * @returns Total cost in dollars
16
+ */
17
+ async function calculateAgentRunCost(agentRun, contextUser) {
18
+ // Agent run already has TotalCost calculated
19
+ return agentRun.TotalCost || 0;
20
+ }
21
+ exports.calculateAgentRunCost = calculateAgentRunCost;
22
+ /**
23
+ * Calculate cost from multiple test runs.
24
+ *
25
+ * @param testRunCosts - Array of individual test run costs
26
+ * @returns Total cost
27
+ */
28
+ function aggregateTestRunCosts(testRunCosts) {
29
+ return testRunCosts.reduce((sum, cost) => sum + cost, 0);
30
+ }
31
+ exports.aggregateTestRunCosts = aggregateTestRunCosts;
32
+ /**
33
+ * Calculate average cost per test.
34
+ *
35
+ * @param totalCost - Total cost across all tests
36
+ * @param testCount - Number of tests
37
+ * @returns Average cost per test
38
+ */
39
+ function calculateAverageCost(totalCost, testCount) {
40
+ return testCount > 0 ? totalCost / testCount : 0;
41
+ }
42
+ exports.calculateAverageCost = calculateAverageCost;
43
+ /**
44
+ * Format cost for display.
45
+ *
46
+ * @param cost - Cost in dollars
47
+ * @param precision - Decimal places (default: 4)
48
+ * @returns Formatted cost string
49
+ */
50
+ function formatCost(cost, precision = 4) {
51
+ if (cost === 0) {
52
+ return '$0.00';
53
+ }
54
+ if (cost < 0.0001) {
55
+ return `$${cost.toExponential(2)}`;
56
+ }
57
+ return `$${cost.toFixed(precision)}`;
58
+ }
59
+ exports.formatCost = formatCost;
60
+ /**
61
+ * Calculate cost per oracle evaluation.
62
+ *
63
+ * Used for tracking costs of LLM-based oracles.
64
+ *
65
+ * @param oracleResults - Oracle results with cost details
66
+ * @returns Map of oracle type to cost
67
+ */
68
+ function calculateOracleCosts(oracleResults) {
69
+ const costs = new Map();
70
+ for (const result of oracleResults) {
71
+ const cost = result.details?.llmCost || 0;
72
+ costs.set(result.oracleType, cost);
73
+ }
74
+ return costs;
75
+ }
76
+ exports.calculateOracleCosts = calculateOracleCosts;
77
+ /**
78
+ * Calculate cost breakdown by component.
79
+ *
80
+ * @param testRunCost - Total test run cost
81
+ * @param oracleCosts - Costs by oracle type
82
+ * @returns Cost breakdown
83
+ */
84
+ function calculateCostBreakdown(testRunCost, oracleCosts) {
85
+ const oracleTotal = Array.from(oracleCosts.values()).reduce((sum, c) => sum + c, 0);
86
+ const agentExecution = Math.max(0, testRunCost - oracleTotal);
87
+ const breakdown = [
88
+ {
89
+ component: 'Agent Execution',
90
+ cost: agentExecution,
91
+ percentage: testRunCost > 0 ? (agentExecution / testRunCost) * 100 : 0
92
+ },
93
+ ...Array.from(oracleCosts.entries()).map(([type, cost]) => ({
94
+ component: `Oracle: ${type}`,
95
+ cost,
96
+ percentage: testRunCost > 0 ? (cost / testRunCost) * 100 : 0
97
+ }))
98
+ ];
99
+ return {
100
+ agentExecution,
101
+ oracleEvaluation: oracleTotal,
102
+ total: testRunCost,
103
+ breakdown
104
+ };
105
+ }
106
+ exports.calculateCostBreakdown = calculateCostBreakdown;
107
+ /**
108
+ * Estimate cost for test suite.
109
+ *
110
+ * @param testCount - Number of tests
111
+ * @param avgCostPerTest - Average cost per test
112
+ * @returns Estimated total cost
113
+ */
114
+ function estimateSuiteCost(testCount, avgCostPerTest) {
115
+ return testCount * avgCostPerTest;
116
+ }
117
+ exports.estimateSuiteCost = estimateSuiteCost;
118
+ /**
119
+ * Calculate cost efficiency metrics.
120
+ *
121
+ * @param totalCost - Total execution cost
122
+ * @param passedTests - Number of passed tests
123
+ * @param totalTests - Total number of tests
124
+ * @returns Cost efficiency metrics
125
+ */
126
+ function calculateCostEfficiency(totalCost, passedTests, totalTests) {
127
+ const costPerTest = totalTests > 0 ? totalCost / totalTests : 0;
128
+ const costPerPassedTest = passedTests > 0 ? totalCost / passedTests : 0;
129
+ const costEfficiencyRatio = totalCost > 0 ? passedTests / totalCost : 0;
130
+ return {
131
+ costPerTest,
132
+ costPerPassedTest,
133
+ costEfficiencyRatio
134
+ };
135
+ }
136
+ exports.calculateCostEfficiency = calculateCostEfficiency;
137
+ //# sourceMappingURL=cost-calculator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cost-calculator.js","sourceRoot":"","sources":["../../src/utils/cost-calculator.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAKH;;;;;;;;GAQG;AACI,KAAK,UAAU,qBAAqB,CACvC,QAA0B,EAC1B,WAAqB;IAErB,6CAA6C;IAC7C,OAAO,QAAQ,CAAC,SAAS,IAAI,CAAC,CAAC;AACnC,CAAC;AAND,sDAMC;AAED;;;;;GAKG;AACH,SAAg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