@assay-ai/vitest 0.1.0-beta
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/LICENSE +21 -0
- package/dist/index.cjs +322 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +111 -0
- package/dist/index.d.ts +111 -0
- package/dist/index.js +295 -0
- package/dist/index.js.map +1 -0
- package/package.json +48 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Assay AI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
AssayReporter: () => AssayReporter,
|
|
24
|
+
assayMatchers: () => assayMatchers,
|
|
25
|
+
setupAssayMatchers: () => setupAssayMatchers
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
|
28
|
+
var import_vitest = require("vitest");
|
|
29
|
+
|
|
30
|
+
// src/matchers.ts
|
|
31
|
+
var import_core = require("@assay-ai/core");
|
|
32
|
+
function formatScore(score) {
|
|
33
|
+
return `${(score * 100).toFixed(1)}%`;
|
|
34
|
+
}
|
|
35
|
+
function formatFailureMessage(metricName, score, threshold, reason) {
|
|
36
|
+
const lines = [
|
|
37
|
+
`Expected test case to pass ${metricName}`,
|
|
38
|
+
` Score: ${formatScore(score)}`,
|
|
39
|
+
` Threshold: ${formatScore(threshold)}`
|
|
40
|
+
];
|
|
41
|
+
if (reason) {
|
|
42
|
+
lines.push(` Reason: ${reason}`);
|
|
43
|
+
}
|
|
44
|
+
return lines.join("\n");
|
|
45
|
+
}
|
|
46
|
+
function formatPassMessage(metricName, score, threshold) {
|
|
47
|
+
return [
|
|
48
|
+
`Expected test case NOT to pass ${metricName}`,
|
|
49
|
+
` Score: ${formatScore(score)}`,
|
|
50
|
+
` Threshold: ${formatScore(threshold)}`
|
|
51
|
+
].join("\n");
|
|
52
|
+
}
|
|
53
|
+
async function evaluateWithMetric(testCase, metric) {
|
|
54
|
+
const result = await metric.measure(testCase);
|
|
55
|
+
const passed = result.score >= metric.threshold;
|
|
56
|
+
return {
|
|
57
|
+
pass: passed,
|
|
58
|
+
message: () => passed ? formatPassMessage(metric.name, result.score, metric.threshold) : formatFailureMessage(metric.name, result.score, metric.threshold, result.reason),
|
|
59
|
+
actual: result.score,
|
|
60
|
+
expected: metric.threshold
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
var assayMatchers = {
|
|
64
|
+
async toBeRelevant(received, options) {
|
|
65
|
+
const threshold = options?.threshold ?? 0.5;
|
|
66
|
+
const metric = new import_core.AnswerRelevancyMetric({ threshold });
|
|
67
|
+
return evaluateWithMetric(received, metric);
|
|
68
|
+
},
|
|
69
|
+
async toBeFaithful(received, options) {
|
|
70
|
+
const threshold = options?.threshold ?? 0.5;
|
|
71
|
+
const metric = new import_core.FaithfulnessMetric({ threshold });
|
|
72
|
+
return evaluateWithMetric(received, metric);
|
|
73
|
+
},
|
|
74
|
+
async toNotHallucinate(received, options) {
|
|
75
|
+
const threshold = options?.threshold ?? 0.5;
|
|
76
|
+
const metric = new import_core.HallucinationMetric({ threshold });
|
|
77
|
+
const result = await metric.measure(received);
|
|
78
|
+
const hallucinationScore = result.score;
|
|
79
|
+
const passed = hallucinationScore <= 1 - threshold;
|
|
80
|
+
return {
|
|
81
|
+
pass: passed,
|
|
82
|
+
message: () => passed ? formatPassMessage("HallucinationMetric (inverted)", 1 - hallucinationScore, threshold) : formatFailureMessage(
|
|
83
|
+
"HallucinationMetric",
|
|
84
|
+
1 - hallucinationScore,
|
|
85
|
+
threshold,
|
|
86
|
+
result.reason
|
|
87
|
+
),
|
|
88
|
+
actual: 1 - hallucinationScore,
|
|
89
|
+
expected: threshold
|
|
90
|
+
};
|
|
91
|
+
},
|
|
92
|
+
async toPassMetric(received, metric) {
|
|
93
|
+
return evaluateWithMetric(received, metric);
|
|
94
|
+
},
|
|
95
|
+
async toPassAllMetrics(received, metrics) {
|
|
96
|
+
const results = await Promise.all(
|
|
97
|
+
metrics.map(async (metric) => {
|
|
98
|
+
const result = await metric.measure(received);
|
|
99
|
+
return {
|
|
100
|
+
metric,
|
|
101
|
+
result,
|
|
102
|
+
passed: result.score >= metric.threshold
|
|
103
|
+
};
|
|
104
|
+
})
|
|
105
|
+
);
|
|
106
|
+
const allPassed = results.every((r) => r.passed);
|
|
107
|
+
const failures = results.filter((r) => !r.passed);
|
|
108
|
+
return {
|
|
109
|
+
pass: allPassed,
|
|
110
|
+
message: () => {
|
|
111
|
+
if (allPassed) {
|
|
112
|
+
const summary2 = results.map(
|
|
113
|
+
(r) => ` ${r.metric.name}: ${formatScore(r.result.score)} (threshold: ${formatScore(r.metric.threshold)})`
|
|
114
|
+
).join("\n");
|
|
115
|
+
return `Expected test case NOT to pass all metrics:
|
|
116
|
+
${summary2}`;
|
|
117
|
+
}
|
|
118
|
+
const summary = failures.map(
|
|
119
|
+
(r) => ` ${r.metric.name}: ${formatScore(r.result.score)} < ${formatScore(r.metric.threshold)}${r.result.reason ? ` \u2014 ${r.result.reason}` : ""}`
|
|
120
|
+
).join("\n");
|
|
121
|
+
return `Expected test case to pass all metrics. ${failures.length} of ${metrics.length} failed:
|
|
122
|
+
${summary}`;
|
|
123
|
+
},
|
|
124
|
+
actual: results.map((r) => ({
|
|
125
|
+
metric: r.metric.name,
|
|
126
|
+
score: r.result.score
|
|
127
|
+
})),
|
|
128
|
+
expected: metrics.map((m) => ({
|
|
129
|
+
metric: m.name,
|
|
130
|
+
threshold: m.threshold
|
|
131
|
+
}))
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
// src/reporter.ts
|
|
137
|
+
var COLORS = {
|
|
138
|
+
reset: "\x1B[0m",
|
|
139
|
+
bold: "\x1B[1m",
|
|
140
|
+
dim: "\x1B[2m",
|
|
141
|
+
green: "\x1B[32m",
|
|
142
|
+
red: "\x1B[31m",
|
|
143
|
+
yellow: "\x1B[33m",
|
|
144
|
+
cyan: "\x1B[36m",
|
|
145
|
+
magenta: "\x1B[35m",
|
|
146
|
+
white: "\x1B[37m",
|
|
147
|
+
bgGreen: "\x1B[42m",
|
|
148
|
+
bgRed: "\x1B[41m",
|
|
149
|
+
bgYellow: "\x1B[43m"
|
|
150
|
+
};
|
|
151
|
+
function colorize(text, ...codes) {
|
|
152
|
+
return codes.join("") + text + COLORS.reset;
|
|
153
|
+
}
|
|
154
|
+
function scoreBar(score, width = 20) {
|
|
155
|
+
const filled = Math.round(score * width);
|
|
156
|
+
const empty = width - filled;
|
|
157
|
+
const color = score >= 0.8 ? COLORS.green : score >= 0.5 ? COLORS.yellow : COLORS.red;
|
|
158
|
+
return color + "\u2588".repeat(filled) + COLORS.dim + "\u2591".repeat(empty) + COLORS.reset;
|
|
159
|
+
}
|
|
160
|
+
function formatDuration(ms) {
|
|
161
|
+
if (ms < 1e3) return `${ms}ms`;
|
|
162
|
+
if (ms < 6e4) return `${(ms / 1e3).toFixed(1)}s`;
|
|
163
|
+
return `${(ms / 6e4).toFixed(1)}m`;
|
|
164
|
+
}
|
|
165
|
+
function extractMetricResults(task) {
|
|
166
|
+
const results = [];
|
|
167
|
+
if (task.result?.state !== "pass" && task.result?.state !== "fail") {
|
|
168
|
+
return results;
|
|
169
|
+
}
|
|
170
|
+
if (task.result.errors) {
|
|
171
|
+
for (const error of task.result.errors) {
|
|
172
|
+
const message = error.message ?? "";
|
|
173
|
+
const metricMatch = /Expected test case (?:to|NOT to) pass (\S+)/.exec(message);
|
|
174
|
+
const scoreMatch = /Score:\s+([\d.]+)%/.exec(message);
|
|
175
|
+
const thresholdMatch = /Threshold:\s+([\d.]+)%/.exec(message);
|
|
176
|
+
if (metricMatch && scoreMatch && thresholdMatch) {
|
|
177
|
+
const score = Number.parseFloat(scoreMatch[1]) / 100;
|
|
178
|
+
const threshold = Number.parseFloat(thresholdMatch[1]) / 100;
|
|
179
|
+
results.push({
|
|
180
|
+
metric: metricMatch[1],
|
|
181
|
+
score,
|
|
182
|
+
threshold,
|
|
183
|
+
passed: score >= threshold
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return results;
|
|
189
|
+
}
|
|
190
|
+
var AssayReporter = class {
|
|
191
|
+
startTime = 0;
|
|
192
|
+
totalTests = 0;
|
|
193
|
+
passedTests = 0;
|
|
194
|
+
failedTests = 0;
|
|
195
|
+
skippedTests = 0;
|
|
196
|
+
allMetricResults = [];
|
|
197
|
+
onInit() {
|
|
198
|
+
this.startTime = Date.now();
|
|
199
|
+
console.log("");
|
|
200
|
+
console.log(
|
|
201
|
+
colorize(" ASSAY ", COLORS.bold, COLORS.bgGreen, COLORS.white) + colorize(" LLM Evaluation Suite", COLORS.bold, COLORS.cyan)
|
|
202
|
+
);
|
|
203
|
+
console.log(colorize("\u2500".repeat(60), COLORS.dim));
|
|
204
|
+
console.log("");
|
|
205
|
+
}
|
|
206
|
+
onTaskUpdate(packs) {
|
|
207
|
+
for (const [id, result] of packs) {
|
|
208
|
+
if (!result) continue;
|
|
209
|
+
void id;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
onFinished(files) {
|
|
213
|
+
if (!files) return;
|
|
214
|
+
const tasks = this.collectTasks(files);
|
|
215
|
+
for (const task of tasks) {
|
|
216
|
+
this.totalTests++;
|
|
217
|
+
if (task.result?.state === "pass") {
|
|
218
|
+
this.passedTests++;
|
|
219
|
+
this.printTaskResult(task, true);
|
|
220
|
+
} else if (task.result?.state === "fail") {
|
|
221
|
+
this.failedTests++;
|
|
222
|
+
this.printTaskResult(task, false);
|
|
223
|
+
} else {
|
|
224
|
+
this.skippedTests++;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
this.printSummary();
|
|
228
|
+
}
|
|
229
|
+
collectTasks(files) {
|
|
230
|
+
const tasks = [];
|
|
231
|
+
function walk(items) {
|
|
232
|
+
for (const item of items) {
|
|
233
|
+
if (item.type === "test") {
|
|
234
|
+
tasks.push(item);
|
|
235
|
+
}
|
|
236
|
+
if ("tasks" in item && item.tasks) {
|
|
237
|
+
walk(item.tasks);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
for (const file of files) {
|
|
242
|
+
walk(file.tasks);
|
|
243
|
+
}
|
|
244
|
+
return tasks;
|
|
245
|
+
}
|
|
246
|
+
printTaskResult(task, passed) {
|
|
247
|
+
const icon = passed ? colorize("\u2713", COLORS.green) : colorize("\u2717", COLORS.red);
|
|
248
|
+
const name = task.name;
|
|
249
|
+
const duration = task.result?.duration ? colorize(` (${formatDuration(task.result.duration)})`, COLORS.dim) : "";
|
|
250
|
+
console.log(` ${icon} ${name}${duration}`);
|
|
251
|
+
const metricResults = extractMetricResults(task);
|
|
252
|
+
if (metricResults.length > 0) {
|
|
253
|
+
this.allMetricResults.push({ test: name, metrics: metricResults });
|
|
254
|
+
for (const mr of metricResults) {
|
|
255
|
+
const statusIcon = mr.passed ? colorize("\u25CF", COLORS.green) : colorize("\u25CF", COLORS.red);
|
|
256
|
+
const scoreStr = `${(mr.score * 100).toFixed(1)}%`;
|
|
257
|
+
const thresholdStr = mr.threshold ? colorize(` (min: ${(mr.threshold * 100).toFixed(1)}%)`, COLORS.dim) : "";
|
|
258
|
+
console.log(
|
|
259
|
+
` ${statusIcon} ${mr.metric}: ${scoreBar(mr.score)} ${scoreStr}${thresholdStr}`
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
printSummary() {
|
|
265
|
+
const duration = Date.now() - this.startTime;
|
|
266
|
+
console.log("");
|
|
267
|
+
console.log(colorize("\u2500".repeat(60), COLORS.dim));
|
|
268
|
+
if (this.allMetricResults.length > 0) {
|
|
269
|
+
console.log("");
|
|
270
|
+
console.log(colorize(" Metric Summary", COLORS.bold, COLORS.magenta));
|
|
271
|
+
console.log("");
|
|
272
|
+
const allMetrics = /* @__PURE__ */ new Map();
|
|
273
|
+
for (const { metrics } of this.allMetricResults) {
|
|
274
|
+
for (const m of metrics) {
|
|
275
|
+
const existing = allMetrics.get(m.metric) ?? { scores: [], passed: 0, total: 0 };
|
|
276
|
+
existing.scores.push(m.score);
|
|
277
|
+
existing.total++;
|
|
278
|
+
if (m.passed) existing.passed++;
|
|
279
|
+
allMetrics.set(m.metric, existing);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
for (const [name, data] of allMetrics) {
|
|
283
|
+
const avg = data.scores.reduce((a, b) => a + b, 0) / data.scores.length;
|
|
284
|
+
const min = Math.min(...data.scores);
|
|
285
|
+
const max = Math.max(...data.scores);
|
|
286
|
+
const passRate = `${data.passed}/${data.total}`;
|
|
287
|
+
console.log(
|
|
288
|
+
` ${colorize(name, COLORS.bold)} avg: ${(avg * 100).toFixed(1)}% min: ${(min * 100).toFixed(1)}% max: ${(max * 100).toFixed(1)}% pass: ${passRate}`
|
|
289
|
+
);
|
|
290
|
+
}
|
|
291
|
+
console.log("");
|
|
292
|
+
console.log(colorize("\u2500".repeat(60), COLORS.dim));
|
|
293
|
+
}
|
|
294
|
+
console.log("");
|
|
295
|
+
const parts = [];
|
|
296
|
+
if (this.passedTests > 0) {
|
|
297
|
+
parts.push(colorize(`${this.passedTests} passed`, COLORS.green, COLORS.bold));
|
|
298
|
+
}
|
|
299
|
+
if (this.failedTests > 0) {
|
|
300
|
+
parts.push(colorize(`${this.failedTests} failed`, COLORS.red, COLORS.bold));
|
|
301
|
+
}
|
|
302
|
+
if (this.skippedTests > 0) {
|
|
303
|
+
parts.push(colorize(`${this.skippedTests} skipped`, COLORS.yellow));
|
|
304
|
+
}
|
|
305
|
+
parts.push(colorize(`${this.totalTests} total`, COLORS.white));
|
|
306
|
+
console.log(` Tests: ${parts.join(colorize(" | ", COLORS.dim))}`);
|
|
307
|
+
console.log(` Duration: ${colorize(formatDuration(duration), COLORS.cyan)}`);
|
|
308
|
+
console.log("");
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
// src/index.ts
|
|
313
|
+
function setupAssayMatchers() {
|
|
314
|
+
import_vitest.expect.extend(assayMatchers);
|
|
315
|
+
}
|
|
316
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
317
|
+
0 && (module.exports = {
|
|
318
|
+
AssayReporter,
|
|
319
|
+
assayMatchers,
|
|
320
|
+
setupAssayMatchers
|
|
321
|
+
});
|
|
322
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/matchers.ts","../src/reporter.ts"],"sourcesContent":["import { expect } from \"vitest\";\nimport { assayMatchers } from \"./matchers\";\n\nexport { AssayReporter } from \"./reporter\";\nexport type {} from \"./types\";\n\n/**\n * Register all Assay custom matchers with Vitest.\n *\n * Call this once in your test setup file:\n * ```ts\n * import { setupAssayMatchers } from \"@assay-ai/vitest\";\n * setupAssayMatchers();\n * ```\n *\n * Then use the matchers in your tests:\n * ```ts\n * await expect(testCase).toBeRelevant({ threshold: 0.7 });\n * await expect(testCase).toBeFaithful();\n * await expect(testCase).toNotHallucinate();\n * await expect(testCase).toPassMetric(myCustomMetric);\n * await expect(testCase).toPassAllMetrics([metric1, metric2]);\n * ```\n */\nexport function setupAssayMatchers(): void {\n expect.extend(assayMatchers);\n}\n\nexport { assayMatchers } from \"./matchers\";\n","import type { BaseMetric, LLMTestCase } from \"@assay-ai/core\";\nimport { AnswerRelevancyMetric, FaithfulnessMetric, HallucinationMetric } from \"@assay-ai/core\";\n\nfunction formatScore(score: number): string {\n return `${(score * 100).toFixed(1)}%`;\n}\n\nfunction formatFailureMessage(\n metricName: string,\n score: number,\n threshold: number,\n reason?: string,\n): string {\n const lines = [\n `Expected test case to pass ${metricName}`,\n ` Score: ${formatScore(score)}`,\n ` Threshold: ${formatScore(threshold)}`,\n ];\n if (reason) {\n lines.push(` Reason: ${reason}`);\n }\n return lines.join(\"\\n\");\n}\n\nfunction formatPassMessage(metricName: string, score: number, threshold: number): string {\n return [\n `Expected test case NOT to pass ${metricName}`,\n ` Score: ${formatScore(score)}`,\n ` Threshold: ${formatScore(threshold)}`,\n ].join(\"\\n\");\n}\n\nasync function evaluateWithMetric(\n testCase: LLMTestCase,\n metric: BaseMetric,\n): Promise<{ pass: boolean; message: () => string; actual?: unknown; expected?: unknown }> {\n const result = await metric.measure(testCase);\n const passed = result.score >= metric.threshold;\n\n return {\n pass: passed,\n message: () =>\n passed\n ? formatPassMessage(metric.name, result.score, metric.threshold)\n : formatFailureMessage(metric.name, result.score, metric.threshold, result.reason),\n actual: result.score,\n expected: metric.threshold,\n };\n}\n\nexport const assayMatchers = {\n async toBeRelevant(\n received: LLMTestCase,\n options?: { threshold?: number },\n ): Promise<{ pass: boolean; message: () => string; actual?: unknown; expected?: unknown }> {\n const threshold = options?.threshold ?? 0.5;\n const metric = new AnswerRelevancyMetric({ threshold });\n return evaluateWithMetric(received, metric);\n },\n\n async toBeFaithful(\n received: LLMTestCase,\n options?: { threshold?: number },\n ): Promise<{ pass: boolean; message: () => string; actual?: unknown; expected?: unknown }> {\n const threshold = options?.threshold ?? 0.5;\n const metric = new FaithfulnessMetric({ threshold });\n return evaluateWithMetric(received, metric);\n },\n\n async toNotHallucinate(\n received: LLMTestCase,\n options?: { threshold?: number },\n ): Promise<{ pass: boolean; message: () => string; actual?: unknown; expected?: unknown }> {\n const threshold = options?.threshold ?? 0.5;\n const metric = new HallucinationMetric({ threshold });\n const result = await metric.measure(received);\n // HallucinationMetric returns a score where higher = more hallucination.\n // We invert: the test passes when hallucination score is BELOW the threshold.\n const hallucinationScore = result.score;\n const passed = hallucinationScore <= 1 - threshold;\n\n return {\n pass: passed,\n message: () =>\n passed\n ? formatPassMessage(\"HallucinationMetric (inverted)\", 1 - hallucinationScore, threshold)\n : formatFailureMessage(\n \"HallucinationMetric\",\n 1 - hallucinationScore,\n threshold,\n result.reason,\n ),\n actual: 1 - hallucinationScore,\n expected: threshold,\n };\n },\n\n async toPassMetric(\n received: LLMTestCase,\n metric: BaseMetric,\n ): Promise<{ pass: boolean; message: () => string; actual?: unknown; expected?: unknown }> {\n return evaluateWithMetric(received, metric);\n },\n\n async toPassAllMetrics(\n received: LLMTestCase,\n metrics: BaseMetric[],\n ): Promise<{ pass: boolean; message: () => string; actual?: unknown; expected?: unknown }> {\n const results = await Promise.all(\n metrics.map(async (metric) => {\n const result = await metric.measure(received);\n return {\n metric,\n result,\n passed: result.score >= metric.threshold,\n };\n }),\n );\n\n const allPassed = results.every((r) => r.passed);\n const failures = results.filter((r) => !r.passed);\n\n return {\n pass: allPassed,\n message: () => {\n if (allPassed) {\n const summary = results\n .map(\n (r) =>\n ` ${r.metric.name}: ${formatScore(r.result.score)} (threshold: ${formatScore(r.metric.threshold)})`,\n )\n .join(\"\\n\");\n return `Expected test case NOT to pass all metrics:\\n${summary}`;\n }\n\n const summary = failures\n .map(\n (r) =>\n ` ${r.metric.name}: ${formatScore(r.result.score)} < ${formatScore(r.metric.threshold)}${r.result.reason ? ` — ${r.result.reason}` : \"\"}`,\n )\n .join(\"\\n\");\n return `Expected test case to pass all metrics. ${failures.length} of ${metrics.length} failed:\\n${summary}`;\n },\n actual: results.map((r) => ({\n metric: r.metric.name,\n score: r.result.score,\n })),\n expected: metrics.map((m) => ({\n metric: m.name,\n threshold: m.threshold,\n })),\n };\n },\n};\n","import type { File, Reporter, Task, TaskResultPack } from \"vitest\";\n\nconst COLORS = {\n reset: \"\\x1b[0m\",\n bold: \"\\x1b[1m\",\n dim: \"\\x1b[2m\",\n green: \"\\x1b[32m\",\n red: \"\\x1b[31m\",\n yellow: \"\\x1b[33m\",\n cyan: \"\\x1b[36m\",\n magenta: \"\\x1b[35m\",\n white: \"\\x1b[37m\",\n bgGreen: \"\\x1b[42m\",\n bgRed: \"\\x1b[41m\",\n bgYellow: \"\\x1b[43m\",\n};\n\nfunction colorize(text: string, ...codes: string[]): string {\n return codes.join(\"\") + text + COLORS.reset;\n}\n\nfunction scoreBar(score: number, width = 20): string {\n const filled = Math.round(score * width);\n const empty = width - filled;\n const color = score >= 0.8 ? COLORS.green : score >= 0.5 ? COLORS.yellow : COLORS.red;\n return color + \"\\u2588\".repeat(filled) + COLORS.dim + \"\\u2591\".repeat(empty) + COLORS.reset;\n}\n\nfunction formatDuration(ms: number): string {\n if (ms < 1000) return `${ms}ms`;\n if (ms < 60_000) return `${(ms / 1000).toFixed(1)}s`;\n return `${(ms / 60_000).toFixed(1)}m`;\n}\n\ninterface MetricResult {\n metric: string;\n score: number;\n threshold?: number;\n passed: boolean;\n}\n\nfunction extractMetricResults(task: Task): MetricResult[] {\n const results: MetricResult[] = [];\n\n if (task.result?.state !== \"pass\" && task.result?.state !== \"fail\") {\n return results;\n }\n\n // Extract metric info from assertion errors if available\n if (task.result.errors) {\n for (const error of task.result.errors) {\n const message = error.message ?? \"\";\n\n // Parse metric results from our formatted error messages\n const metricMatch = /Expected test case (?:to|NOT to) pass (\\S+)/.exec(message);\n const scoreMatch = /Score:\\s+([\\d.]+)%/.exec(message);\n const thresholdMatch = /Threshold:\\s+([\\d.]+)%/.exec(message);\n\n if (metricMatch && scoreMatch && thresholdMatch) {\n const score = Number.parseFloat(scoreMatch[1]!) / 100;\n const threshold = Number.parseFloat(thresholdMatch[1]!) / 100;\n results.push({\n metric: metricMatch[1]!,\n score,\n threshold,\n passed: score >= threshold,\n });\n }\n }\n }\n\n return results;\n}\n\n/**\n * Vitest Reporter that formats Assay evaluation results with visual scoring\n * indicators, metric breakdowns, and a summary table.\n */\nexport class AssayReporter implements Reporter {\n private startTime = 0;\n private totalTests = 0;\n private passedTests = 0;\n private failedTests = 0;\n private skippedTests = 0;\n private allMetricResults: Array<{ test: string; metrics: MetricResult[] }> = [];\n\n onInit(): void {\n this.startTime = Date.now();\n console.log(\"\");\n console.log(\n colorize(\" ASSAY \", COLORS.bold, COLORS.bgGreen, COLORS.white) +\n colorize(\" LLM Evaluation Suite\", COLORS.bold, COLORS.cyan),\n );\n console.log(colorize(\"─\".repeat(60), COLORS.dim));\n console.log(\"\");\n }\n\n onTaskUpdate(packs: TaskResultPack[]): void {\n for (const [id, result] of packs) {\n if (!result) continue;\n\n // Task updates are processed; we accumulate counts in onFinished\n void id;\n }\n }\n\n onFinished(files?: File[]): void {\n if (!files) return;\n\n const tasks = this.collectTasks(files);\n\n for (const task of tasks) {\n this.totalTests++;\n\n if (task.result?.state === \"pass\") {\n this.passedTests++;\n this.printTaskResult(task, true);\n } else if (task.result?.state === \"fail\") {\n this.failedTests++;\n this.printTaskResult(task, false);\n } else {\n this.skippedTests++;\n }\n }\n\n this.printSummary();\n }\n\n private collectTasks(files: File[]): Task[] {\n const tasks: Task[] = [];\n\n function walk(items: Task[]): void {\n for (const item of items) {\n if (item.type === \"test\") {\n tasks.push(item);\n }\n if (\"tasks\" in item && item.tasks) {\n walk(item.tasks);\n }\n }\n }\n\n for (const file of files) {\n walk(file.tasks);\n }\n\n return tasks;\n }\n\n private printTaskResult(task: Task, passed: boolean): void {\n const icon = passed ? colorize(\"\\u2713\", COLORS.green) : colorize(\"\\u2717\", COLORS.red);\n const name = task.name;\n const duration = task.result?.duration\n ? colorize(` (${formatDuration(task.result.duration)})`, COLORS.dim)\n : \"\";\n\n console.log(` ${icon} ${name}${duration}`);\n\n // Extract and display metric results\n const metricResults = extractMetricResults(task);\n if (metricResults.length > 0) {\n this.allMetricResults.push({ test: name, metrics: metricResults });\n for (const mr of metricResults) {\n const statusIcon = mr.passed\n ? colorize(\"\\u25CF\", COLORS.green)\n : colorize(\"\\u25CF\", COLORS.red);\n const scoreStr = `${(mr.score * 100).toFixed(1)}%`;\n const thresholdStr = mr.threshold\n ? colorize(` (min: ${(mr.threshold * 100).toFixed(1)}%)`, COLORS.dim)\n : \"\";\n console.log(\n ` ${statusIcon} ${mr.metric}: ${scoreBar(mr.score)} ${scoreStr}${thresholdStr}`,\n );\n }\n }\n }\n\n private printSummary(): void {\n const duration = Date.now() - this.startTime;\n\n console.log(\"\");\n console.log(colorize(\"─\".repeat(60), COLORS.dim));\n\n // Metrics summary table\n if (this.allMetricResults.length > 0) {\n console.log(\"\");\n console.log(colorize(\" Metric Summary\", COLORS.bold, COLORS.magenta));\n console.log(\"\");\n\n const allMetrics = new Map<string, { scores: number[]; passed: number; total: number }>();\n\n for (const { metrics } of this.allMetricResults) {\n for (const m of metrics) {\n const existing = allMetrics.get(m.metric) ?? { scores: [], passed: 0, total: 0 };\n existing.scores.push(m.score);\n existing.total++;\n if (m.passed) existing.passed++;\n allMetrics.set(m.metric, existing);\n }\n }\n\n for (const [name, data] of allMetrics) {\n const avg = data.scores.reduce((a, b) => a + b, 0) / data.scores.length;\n const min = Math.min(...data.scores);\n const max = Math.max(...data.scores);\n const passRate = `${data.passed}/${data.total}`;\n\n console.log(\n ` ${colorize(name, COLORS.bold)} avg: ${(avg * 100).toFixed(1)}% min: ${(min * 100).toFixed(1)}% max: ${(max * 100).toFixed(1)}% pass: ${passRate}`,\n );\n }\n\n console.log(\"\");\n console.log(colorize(\"─\".repeat(60), COLORS.dim));\n }\n\n // Test totals\n console.log(\"\");\n const parts: string[] = [];\n if (this.passedTests > 0) {\n parts.push(colorize(`${this.passedTests} passed`, COLORS.green, COLORS.bold));\n }\n if (this.failedTests > 0) {\n parts.push(colorize(`${this.failedTests} failed`, COLORS.red, COLORS.bold));\n }\n if (this.skippedTests > 0) {\n parts.push(colorize(`${this.skippedTests} skipped`, COLORS.yellow));\n }\n parts.push(colorize(`${this.totalTests} total`, COLORS.white));\n\n console.log(` Tests: ${parts.join(colorize(\" | \", COLORS.dim))}`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pE,YAAQ,IAAI,eAAe,SAAS,eAAe,QAAQ,GAAG,OAAO,IAAI,CAAC,EAAE;AAC5E,YAAQ,IAAI,EAAE;AAAA,EAChB;AACF;;;AFlNO,SAAS,qBAA2B;AACzC,uBAAO,OAAO,aAAa;AAC7B;","names":["summary"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { Reporter, TaskResultPack, File } from 'vitest';
|
|
2
|
+
import { BaseMetric, LLMTestCase } from '@assay-ai/core';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Vitest Reporter that formats Assay evaluation results with visual scoring
|
|
6
|
+
* indicators, metric breakdowns, and a summary table.
|
|
7
|
+
*/
|
|
8
|
+
declare class AssayReporter implements Reporter {
|
|
9
|
+
private startTime;
|
|
10
|
+
private totalTests;
|
|
11
|
+
private passedTests;
|
|
12
|
+
private failedTests;
|
|
13
|
+
private skippedTests;
|
|
14
|
+
private allMetricResults;
|
|
15
|
+
onInit(): void;
|
|
16
|
+
onTaskUpdate(packs: TaskResultPack[]): void;
|
|
17
|
+
onFinished(files?: File[]): void;
|
|
18
|
+
private collectTasks;
|
|
19
|
+
private printTaskResult;
|
|
20
|
+
private printSummary;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
declare module "vitest" {
|
|
24
|
+
interface Assertion<T = any> {
|
|
25
|
+
toBeRelevant(options?: {
|
|
26
|
+
threshold?: number;
|
|
27
|
+
}): Promise<void>;
|
|
28
|
+
toBeFaithful(options?: {
|
|
29
|
+
threshold?: number;
|
|
30
|
+
}): Promise<void>;
|
|
31
|
+
toNotHallucinate(options?: {
|
|
32
|
+
threshold?: number;
|
|
33
|
+
}): Promise<void>;
|
|
34
|
+
toPassMetric(metric: BaseMetric): Promise<void>;
|
|
35
|
+
toPassAllMetrics(metrics: BaseMetric[]): Promise<void>;
|
|
36
|
+
}
|
|
37
|
+
interface AsymmetricMatchersContaining {
|
|
38
|
+
toBeRelevant(options?: {
|
|
39
|
+
threshold?: number;
|
|
40
|
+
}): void;
|
|
41
|
+
toBeFaithful(options?: {
|
|
42
|
+
threshold?: number;
|
|
43
|
+
}): void;
|
|
44
|
+
toNotHallucinate(options?: {
|
|
45
|
+
threshold?: number;
|
|
46
|
+
}): void;
|
|
47
|
+
toPassMetric(metric: BaseMetric): void;
|
|
48
|
+
toPassAllMetrics(metrics: BaseMetric[]): void;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
declare const assayMatchers: {
|
|
53
|
+
toBeRelevant(received: LLMTestCase, options?: {
|
|
54
|
+
threshold?: number;
|
|
55
|
+
}): Promise<{
|
|
56
|
+
pass: boolean;
|
|
57
|
+
message: () => string;
|
|
58
|
+
actual?: unknown;
|
|
59
|
+
expected?: unknown;
|
|
60
|
+
}>;
|
|
61
|
+
toBeFaithful(received: LLMTestCase, options?: {
|
|
62
|
+
threshold?: number;
|
|
63
|
+
}): Promise<{
|
|
64
|
+
pass: boolean;
|
|
65
|
+
message: () => string;
|
|
66
|
+
actual?: unknown;
|
|
67
|
+
expected?: unknown;
|
|
68
|
+
}>;
|
|
69
|
+
toNotHallucinate(received: LLMTestCase, options?: {
|
|
70
|
+
threshold?: number;
|
|
71
|
+
}): Promise<{
|
|
72
|
+
pass: boolean;
|
|
73
|
+
message: () => string;
|
|
74
|
+
actual?: unknown;
|
|
75
|
+
expected?: unknown;
|
|
76
|
+
}>;
|
|
77
|
+
toPassMetric(received: LLMTestCase, metric: BaseMetric): Promise<{
|
|
78
|
+
pass: boolean;
|
|
79
|
+
message: () => string;
|
|
80
|
+
actual?: unknown;
|
|
81
|
+
expected?: unknown;
|
|
82
|
+
}>;
|
|
83
|
+
toPassAllMetrics(received: LLMTestCase, metrics: BaseMetric[]): Promise<{
|
|
84
|
+
pass: boolean;
|
|
85
|
+
message: () => string;
|
|
86
|
+
actual?: unknown;
|
|
87
|
+
expected?: unknown;
|
|
88
|
+
}>;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Register all Assay custom matchers with Vitest.
|
|
93
|
+
*
|
|
94
|
+
* Call this once in your test setup file:
|
|
95
|
+
* ```ts
|
|
96
|
+
* import { setupAssayMatchers } from "@assay-ai/vitest";
|
|
97
|
+
* setupAssayMatchers();
|
|
98
|
+
* ```
|
|
99
|
+
*
|
|
100
|
+
* Then use the matchers in your tests:
|
|
101
|
+
* ```ts
|
|
102
|
+
* await expect(testCase).toBeRelevant({ threshold: 0.7 });
|
|
103
|
+
* await expect(testCase).toBeFaithful();
|
|
104
|
+
* await expect(testCase).toNotHallucinate();
|
|
105
|
+
* await expect(testCase).toPassMetric(myCustomMetric);
|
|
106
|
+
* await expect(testCase).toPassAllMetrics([metric1, metric2]);
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
declare function setupAssayMatchers(): void;
|
|
110
|
+
|
|
111
|
+
export { AssayReporter, assayMatchers, setupAssayMatchers };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { Reporter, TaskResultPack, File } from 'vitest';
|
|
2
|
+
import { BaseMetric, LLMTestCase } from '@assay-ai/core';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Vitest Reporter that formats Assay evaluation results with visual scoring
|
|
6
|
+
* indicators, metric breakdowns, and a summary table.
|
|
7
|
+
*/
|
|
8
|
+
declare class AssayReporter implements Reporter {
|
|
9
|
+
private startTime;
|
|
10
|
+
private totalTests;
|
|
11
|
+
private passedTests;
|
|
12
|
+
private failedTests;
|
|
13
|
+
private skippedTests;
|
|
14
|
+
private allMetricResults;
|
|
15
|
+
onInit(): void;
|
|
16
|
+
onTaskUpdate(packs: TaskResultPack[]): void;
|
|
17
|
+
onFinished(files?: File[]): void;
|
|
18
|
+
private collectTasks;
|
|
19
|
+
private printTaskResult;
|
|
20
|
+
private printSummary;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
declare module "vitest" {
|
|
24
|
+
interface Assertion<T = any> {
|
|
25
|
+
toBeRelevant(options?: {
|
|
26
|
+
threshold?: number;
|
|
27
|
+
}): Promise<void>;
|
|
28
|
+
toBeFaithful(options?: {
|
|
29
|
+
threshold?: number;
|
|
30
|
+
}): Promise<void>;
|
|
31
|
+
toNotHallucinate(options?: {
|
|
32
|
+
threshold?: number;
|
|
33
|
+
}): Promise<void>;
|
|
34
|
+
toPassMetric(metric: BaseMetric): Promise<void>;
|
|
35
|
+
toPassAllMetrics(metrics: BaseMetric[]): Promise<void>;
|
|
36
|
+
}
|
|
37
|
+
interface AsymmetricMatchersContaining {
|
|
38
|
+
toBeRelevant(options?: {
|
|
39
|
+
threshold?: number;
|
|
40
|
+
}): void;
|
|
41
|
+
toBeFaithful(options?: {
|
|
42
|
+
threshold?: number;
|
|
43
|
+
}): void;
|
|
44
|
+
toNotHallucinate(options?: {
|
|
45
|
+
threshold?: number;
|
|
46
|
+
}): void;
|
|
47
|
+
toPassMetric(metric: BaseMetric): void;
|
|
48
|
+
toPassAllMetrics(metrics: BaseMetric[]): void;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
declare const assayMatchers: {
|
|
53
|
+
toBeRelevant(received: LLMTestCase, options?: {
|
|
54
|
+
threshold?: number;
|
|
55
|
+
}): Promise<{
|
|
56
|
+
pass: boolean;
|
|
57
|
+
message: () => string;
|
|
58
|
+
actual?: unknown;
|
|
59
|
+
expected?: unknown;
|
|
60
|
+
}>;
|
|
61
|
+
toBeFaithful(received: LLMTestCase, options?: {
|
|
62
|
+
threshold?: number;
|
|
63
|
+
}): Promise<{
|
|
64
|
+
pass: boolean;
|
|
65
|
+
message: () => string;
|
|
66
|
+
actual?: unknown;
|
|
67
|
+
expected?: unknown;
|
|
68
|
+
}>;
|
|
69
|
+
toNotHallucinate(received: LLMTestCase, options?: {
|
|
70
|
+
threshold?: number;
|
|
71
|
+
}): Promise<{
|
|
72
|
+
pass: boolean;
|
|
73
|
+
message: () => string;
|
|
74
|
+
actual?: unknown;
|
|
75
|
+
expected?: unknown;
|
|
76
|
+
}>;
|
|
77
|
+
toPassMetric(received: LLMTestCase, metric: BaseMetric): Promise<{
|
|
78
|
+
pass: boolean;
|
|
79
|
+
message: () => string;
|
|
80
|
+
actual?: unknown;
|
|
81
|
+
expected?: unknown;
|
|
82
|
+
}>;
|
|
83
|
+
toPassAllMetrics(received: LLMTestCase, metrics: BaseMetric[]): Promise<{
|
|
84
|
+
pass: boolean;
|
|
85
|
+
message: () => string;
|
|
86
|
+
actual?: unknown;
|
|
87
|
+
expected?: unknown;
|
|
88
|
+
}>;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Register all Assay custom matchers with Vitest.
|
|
93
|
+
*
|
|
94
|
+
* Call this once in your test setup file:
|
|
95
|
+
* ```ts
|
|
96
|
+
* import { setupAssayMatchers } from "@assay-ai/vitest";
|
|
97
|
+
* setupAssayMatchers();
|
|
98
|
+
* ```
|
|
99
|
+
*
|
|
100
|
+
* Then use the matchers in your tests:
|
|
101
|
+
* ```ts
|
|
102
|
+
* await expect(testCase).toBeRelevant({ threshold: 0.7 });
|
|
103
|
+
* await expect(testCase).toBeFaithful();
|
|
104
|
+
* await expect(testCase).toNotHallucinate();
|
|
105
|
+
* await expect(testCase).toPassMetric(myCustomMetric);
|
|
106
|
+
* await expect(testCase).toPassAllMetrics([metric1, metric2]);
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
declare function setupAssayMatchers(): void;
|
|
110
|
+
|
|
111
|
+
export { AssayReporter, assayMatchers, setupAssayMatchers };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { expect } from "vitest";
|
|
3
|
+
|
|
4
|
+
// src/matchers.ts
|
|
5
|
+
import { AnswerRelevancyMetric, FaithfulnessMetric, HallucinationMetric } from "@assay-ai/core";
|
|
6
|
+
function formatScore(score) {
|
|
7
|
+
return `${(score * 100).toFixed(1)}%`;
|
|
8
|
+
}
|
|
9
|
+
function formatFailureMessage(metricName, score, threshold, reason) {
|
|
10
|
+
const lines = [
|
|
11
|
+
`Expected test case to pass ${metricName}`,
|
|
12
|
+
` Score: ${formatScore(score)}`,
|
|
13
|
+
` Threshold: ${formatScore(threshold)}`
|
|
14
|
+
];
|
|
15
|
+
if (reason) {
|
|
16
|
+
lines.push(` Reason: ${reason}`);
|
|
17
|
+
}
|
|
18
|
+
return lines.join("\n");
|
|
19
|
+
}
|
|
20
|
+
function formatPassMessage(metricName, score, threshold) {
|
|
21
|
+
return [
|
|
22
|
+
`Expected test case NOT to pass ${metricName}`,
|
|
23
|
+
` Score: ${formatScore(score)}`,
|
|
24
|
+
` Threshold: ${formatScore(threshold)}`
|
|
25
|
+
].join("\n");
|
|
26
|
+
}
|
|
27
|
+
async function evaluateWithMetric(testCase, metric) {
|
|
28
|
+
const result = await metric.measure(testCase);
|
|
29
|
+
const passed = result.score >= metric.threshold;
|
|
30
|
+
return {
|
|
31
|
+
pass: passed,
|
|
32
|
+
message: () => passed ? formatPassMessage(metric.name, result.score, metric.threshold) : formatFailureMessage(metric.name, result.score, metric.threshold, result.reason),
|
|
33
|
+
actual: result.score,
|
|
34
|
+
expected: metric.threshold
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
var assayMatchers = {
|
|
38
|
+
async toBeRelevant(received, options) {
|
|
39
|
+
const threshold = options?.threshold ?? 0.5;
|
|
40
|
+
const metric = new AnswerRelevancyMetric({ threshold });
|
|
41
|
+
return evaluateWithMetric(received, metric);
|
|
42
|
+
},
|
|
43
|
+
async toBeFaithful(received, options) {
|
|
44
|
+
const threshold = options?.threshold ?? 0.5;
|
|
45
|
+
const metric = new FaithfulnessMetric({ threshold });
|
|
46
|
+
return evaluateWithMetric(received, metric);
|
|
47
|
+
},
|
|
48
|
+
async toNotHallucinate(received, options) {
|
|
49
|
+
const threshold = options?.threshold ?? 0.5;
|
|
50
|
+
const metric = new HallucinationMetric({ threshold });
|
|
51
|
+
const result = await metric.measure(received);
|
|
52
|
+
const hallucinationScore = result.score;
|
|
53
|
+
const passed = hallucinationScore <= 1 - threshold;
|
|
54
|
+
return {
|
|
55
|
+
pass: passed,
|
|
56
|
+
message: () => passed ? formatPassMessage("HallucinationMetric (inverted)", 1 - hallucinationScore, threshold) : formatFailureMessage(
|
|
57
|
+
"HallucinationMetric",
|
|
58
|
+
1 - hallucinationScore,
|
|
59
|
+
threshold,
|
|
60
|
+
result.reason
|
|
61
|
+
),
|
|
62
|
+
actual: 1 - hallucinationScore,
|
|
63
|
+
expected: threshold
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
async toPassMetric(received, metric) {
|
|
67
|
+
return evaluateWithMetric(received, metric);
|
|
68
|
+
},
|
|
69
|
+
async toPassAllMetrics(received, metrics) {
|
|
70
|
+
const results = await Promise.all(
|
|
71
|
+
metrics.map(async (metric) => {
|
|
72
|
+
const result = await metric.measure(received);
|
|
73
|
+
return {
|
|
74
|
+
metric,
|
|
75
|
+
result,
|
|
76
|
+
passed: result.score >= metric.threshold
|
|
77
|
+
};
|
|
78
|
+
})
|
|
79
|
+
);
|
|
80
|
+
const allPassed = results.every((r) => r.passed);
|
|
81
|
+
const failures = results.filter((r) => !r.passed);
|
|
82
|
+
return {
|
|
83
|
+
pass: allPassed,
|
|
84
|
+
message: () => {
|
|
85
|
+
if (allPassed) {
|
|
86
|
+
const summary2 = results.map(
|
|
87
|
+
(r) => ` ${r.metric.name}: ${formatScore(r.result.score)} (threshold: ${formatScore(r.metric.threshold)})`
|
|
88
|
+
).join("\n");
|
|
89
|
+
return `Expected test case NOT to pass all metrics:
|
|
90
|
+
${summary2}`;
|
|
91
|
+
}
|
|
92
|
+
const summary = failures.map(
|
|
93
|
+
(r) => ` ${r.metric.name}: ${formatScore(r.result.score)} < ${formatScore(r.metric.threshold)}${r.result.reason ? ` \u2014 ${r.result.reason}` : ""}`
|
|
94
|
+
).join("\n");
|
|
95
|
+
return `Expected test case to pass all metrics. ${failures.length} of ${metrics.length} failed:
|
|
96
|
+
${summary}`;
|
|
97
|
+
},
|
|
98
|
+
actual: results.map((r) => ({
|
|
99
|
+
metric: r.metric.name,
|
|
100
|
+
score: r.result.score
|
|
101
|
+
})),
|
|
102
|
+
expected: metrics.map((m) => ({
|
|
103
|
+
metric: m.name,
|
|
104
|
+
threshold: m.threshold
|
|
105
|
+
}))
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
// src/reporter.ts
|
|
111
|
+
var COLORS = {
|
|
112
|
+
reset: "\x1B[0m",
|
|
113
|
+
bold: "\x1B[1m",
|
|
114
|
+
dim: "\x1B[2m",
|
|
115
|
+
green: "\x1B[32m",
|
|
116
|
+
red: "\x1B[31m",
|
|
117
|
+
yellow: "\x1B[33m",
|
|
118
|
+
cyan: "\x1B[36m",
|
|
119
|
+
magenta: "\x1B[35m",
|
|
120
|
+
white: "\x1B[37m",
|
|
121
|
+
bgGreen: "\x1B[42m",
|
|
122
|
+
bgRed: "\x1B[41m",
|
|
123
|
+
bgYellow: "\x1B[43m"
|
|
124
|
+
};
|
|
125
|
+
function colorize(text, ...codes) {
|
|
126
|
+
return codes.join("") + text + COLORS.reset;
|
|
127
|
+
}
|
|
128
|
+
function scoreBar(score, width = 20) {
|
|
129
|
+
const filled = Math.round(score * width);
|
|
130
|
+
const empty = width - filled;
|
|
131
|
+
const color = score >= 0.8 ? COLORS.green : score >= 0.5 ? COLORS.yellow : COLORS.red;
|
|
132
|
+
return color + "\u2588".repeat(filled) + COLORS.dim + "\u2591".repeat(empty) + COLORS.reset;
|
|
133
|
+
}
|
|
134
|
+
function formatDuration(ms) {
|
|
135
|
+
if (ms < 1e3) return `${ms}ms`;
|
|
136
|
+
if (ms < 6e4) return `${(ms / 1e3).toFixed(1)}s`;
|
|
137
|
+
return `${(ms / 6e4).toFixed(1)}m`;
|
|
138
|
+
}
|
|
139
|
+
function extractMetricResults(task) {
|
|
140
|
+
const results = [];
|
|
141
|
+
if (task.result?.state !== "pass" && task.result?.state !== "fail") {
|
|
142
|
+
return results;
|
|
143
|
+
}
|
|
144
|
+
if (task.result.errors) {
|
|
145
|
+
for (const error of task.result.errors) {
|
|
146
|
+
const message = error.message ?? "";
|
|
147
|
+
const metricMatch = /Expected test case (?:to|NOT to) pass (\S+)/.exec(message);
|
|
148
|
+
const scoreMatch = /Score:\s+([\d.]+)%/.exec(message);
|
|
149
|
+
const thresholdMatch = /Threshold:\s+([\d.]+)%/.exec(message);
|
|
150
|
+
if (metricMatch && scoreMatch && thresholdMatch) {
|
|
151
|
+
const score = Number.parseFloat(scoreMatch[1]) / 100;
|
|
152
|
+
const threshold = Number.parseFloat(thresholdMatch[1]) / 100;
|
|
153
|
+
results.push({
|
|
154
|
+
metric: metricMatch[1],
|
|
155
|
+
score,
|
|
156
|
+
threshold,
|
|
157
|
+
passed: score >= threshold
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return results;
|
|
163
|
+
}
|
|
164
|
+
var AssayReporter = class {
|
|
165
|
+
startTime = 0;
|
|
166
|
+
totalTests = 0;
|
|
167
|
+
passedTests = 0;
|
|
168
|
+
failedTests = 0;
|
|
169
|
+
skippedTests = 0;
|
|
170
|
+
allMetricResults = [];
|
|
171
|
+
onInit() {
|
|
172
|
+
this.startTime = Date.now();
|
|
173
|
+
console.log("");
|
|
174
|
+
console.log(
|
|
175
|
+
colorize(" ASSAY ", COLORS.bold, COLORS.bgGreen, COLORS.white) + colorize(" LLM Evaluation Suite", COLORS.bold, COLORS.cyan)
|
|
176
|
+
);
|
|
177
|
+
console.log(colorize("\u2500".repeat(60), COLORS.dim));
|
|
178
|
+
console.log("");
|
|
179
|
+
}
|
|
180
|
+
onTaskUpdate(packs) {
|
|
181
|
+
for (const [id, result] of packs) {
|
|
182
|
+
if (!result) continue;
|
|
183
|
+
void id;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
onFinished(files) {
|
|
187
|
+
if (!files) return;
|
|
188
|
+
const tasks = this.collectTasks(files);
|
|
189
|
+
for (const task of tasks) {
|
|
190
|
+
this.totalTests++;
|
|
191
|
+
if (task.result?.state === "pass") {
|
|
192
|
+
this.passedTests++;
|
|
193
|
+
this.printTaskResult(task, true);
|
|
194
|
+
} else if (task.result?.state === "fail") {
|
|
195
|
+
this.failedTests++;
|
|
196
|
+
this.printTaskResult(task, false);
|
|
197
|
+
} else {
|
|
198
|
+
this.skippedTests++;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
this.printSummary();
|
|
202
|
+
}
|
|
203
|
+
collectTasks(files) {
|
|
204
|
+
const tasks = [];
|
|
205
|
+
function walk(items) {
|
|
206
|
+
for (const item of items) {
|
|
207
|
+
if (item.type === "test") {
|
|
208
|
+
tasks.push(item);
|
|
209
|
+
}
|
|
210
|
+
if ("tasks" in item && item.tasks) {
|
|
211
|
+
walk(item.tasks);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
for (const file of files) {
|
|
216
|
+
walk(file.tasks);
|
|
217
|
+
}
|
|
218
|
+
return tasks;
|
|
219
|
+
}
|
|
220
|
+
printTaskResult(task, passed) {
|
|
221
|
+
const icon = passed ? colorize("\u2713", COLORS.green) : colorize("\u2717", COLORS.red);
|
|
222
|
+
const name = task.name;
|
|
223
|
+
const duration = task.result?.duration ? colorize(` (${formatDuration(task.result.duration)})`, COLORS.dim) : "";
|
|
224
|
+
console.log(` ${icon} ${name}${duration}`);
|
|
225
|
+
const metricResults = extractMetricResults(task);
|
|
226
|
+
if (metricResults.length > 0) {
|
|
227
|
+
this.allMetricResults.push({ test: name, metrics: metricResults });
|
|
228
|
+
for (const mr of metricResults) {
|
|
229
|
+
const statusIcon = mr.passed ? colorize("\u25CF", COLORS.green) : colorize("\u25CF", COLORS.red);
|
|
230
|
+
const scoreStr = `${(mr.score * 100).toFixed(1)}%`;
|
|
231
|
+
const thresholdStr = mr.threshold ? colorize(` (min: ${(mr.threshold * 100).toFixed(1)}%)`, COLORS.dim) : "";
|
|
232
|
+
console.log(
|
|
233
|
+
` ${statusIcon} ${mr.metric}: ${scoreBar(mr.score)} ${scoreStr}${thresholdStr}`
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
printSummary() {
|
|
239
|
+
const duration = Date.now() - this.startTime;
|
|
240
|
+
console.log("");
|
|
241
|
+
console.log(colorize("\u2500".repeat(60), COLORS.dim));
|
|
242
|
+
if (this.allMetricResults.length > 0) {
|
|
243
|
+
console.log("");
|
|
244
|
+
console.log(colorize(" Metric Summary", COLORS.bold, COLORS.magenta));
|
|
245
|
+
console.log("");
|
|
246
|
+
const allMetrics = /* @__PURE__ */ new Map();
|
|
247
|
+
for (const { metrics } of this.allMetricResults) {
|
|
248
|
+
for (const m of metrics) {
|
|
249
|
+
const existing = allMetrics.get(m.metric) ?? { scores: [], passed: 0, total: 0 };
|
|
250
|
+
existing.scores.push(m.score);
|
|
251
|
+
existing.total++;
|
|
252
|
+
if (m.passed) existing.passed++;
|
|
253
|
+
allMetrics.set(m.metric, existing);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
for (const [name, data] of allMetrics) {
|
|
257
|
+
const avg = data.scores.reduce((a, b) => a + b, 0) / data.scores.length;
|
|
258
|
+
const min = Math.min(...data.scores);
|
|
259
|
+
const max = Math.max(...data.scores);
|
|
260
|
+
const passRate = `${data.passed}/${data.total}`;
|
|
261
|
+
console.log(
|
|
262
|
+
` ${colorize(name, COLORS.bold)} avg: ${(avg * 100).toFixed(1)}% min: ${(min * 100).toFixed(1)}% max: ${(max * 100).toFixed(1)}% pass: ${passRate}`
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
console.log("");
|
|
266
|
+
console.log(colorize("\u2500".repeat(60), COLORS.dim));
|
|
267
|
+
}
|
|
268
|
+
console.log("");
|
|
269
|
+
const parts = [];
|
|
270
|
+
if (this.passedTests > 0) {
|
|
271
|
+
parts.push(colorize(`${this.passedTests} passed`, COLORS.green, COLORS.bold));
|
|
272
|
+
}
|
|
273
|
+
if (this.failedTests > 0) {
|
|
274
|
+
parts.push(colorize(`${this.failedTests} failed`, COLORS.red, COLORS.bold));
|
|
275
|
+
}
|
|
276
|
+
if (this.skippedTests > 0) {
|
|
277
|
+
parts.push(colorize(`${this.skippedTests} skipped`, COLORS.yellow));
|
|
278
|
+
}
|
|
279
|
+
parts.push(colorize(`${this.totalTests} total`, COLORS.white));
|
|
280
|
+
console.log(` Tests: ${parts.join(colorize(" | ", COLORS.dim))}`);
|
|
281
|
+
console.log(` Duration: ${colorize(formatDuration(duration), COLORS.cyan)}`);
|
|
282
|
+
console.log("");
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
// src/index.ts
|
|
287
|
+
function setupAssayMatchers() {
|
|
288
|
+
expect.extend(assayMatchers);
|
|
289
|
+
}
|
|
290
|
+
export {
|
|
291
|
+
AssayReporter,
|
|
292
|
+
assayMatchers,
|
|
293
|
+
setupAssayMatchers
|
|
294
|
+
};
|
|
295
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/matchers.ts","../src/reporter.ts"],"sourcesContent":["import { expect } from \"vitest\";\nimport { assayMatchers } from \"./matchers\";\n\nexport { AssayReporter } from \"./reporter\";\nexport type {} from \"./types\";\n\n/**\n * Register all Assay custom matchers with Vitest.\n *\n * Call this once in your test setup file:\n * ```ts\n * import { setupAssayMatchers } from \"@assay-ai/vitest\";\n * setupAssayMatchers();\n * ```\n *\n * Then use the matchers in your tests:\n * ```ts\n * await expect(testCase).toBeRelevant({ threshold: 0.7 });\n * await expect(testCase).toBeFaithful();\n * await expect(testCase).toNotHallucinate();\n * await expect(testCase).toPassMetric(myCustomMetric);\n * await expect(testCase).toPassAllMetrics([metric1, metric2]);\n * ```\n */\nexport function setupAssayMatchers(): void {\n expect.extend(assayMatchers);\n}\n\nexport { assayMatchers } from \"./matchers\";\n","import type { BaseMetric, LLMTestCase } from \"@assay-ai/core\";\nimport { AnswerRelevancyMetric, FaithfulnessMetric, HallucinationMetric } from \"@assay-ai/core\";\n\nfunction formatScore(score: number): string {\n return `${(score * 100).toFixed(1)}%`;\n}\n\nfunction formatFailureMessage(\n metricName: string,\n score: number,\n threshold: number,\n reason?: string,\n): string {\n const lines = [\n `Expected test case to pass ${metricName}`,\n ` Score: ${formatScore(score)}`,\n ` Threshold: ${formatScore(threshold)}`,\n ];\n if (reason) {\n lines.push(` Reason: ${reason}`);\n }\n return lines.join(\"\\n\");\n}\n\nfunction formatPassMessage(metricName: string, score: number, threshold: number): string {\n return [\n `Expected test case NOT to pass ${metricName}`,\n ` Score: ${formatScore(score)}`,\n ` Threshold: ${formatScore(threshold)}`,\n ].join(\"\\n\");\n}\n\nasync function evaluateWithMetric(\n testCase: LLMTestCase,\n metric: BaseMetric,\n): Promise<{ pass: boolean; message: () => string; actual?: unknown; expected?: unknown }> {\n const result = await metric.measure(testCase);\n const passed = result.score >= metric.threshold;\n\n return {\n pass: passed,\n message: () =>\n passed\n ? formatPassMessage(metric.name, result.score, metric.threshold)\n : formatFailureMessage(metric.name, result.score, metric.threshold, result.reason),\n actual: result.score,\n expected: metric.threshold,\n };\n}\n\nexport const assayMatchers = {\n async toBeRelevant(\n received: LLMTestCase,\n options?: { threshold?: number },\n ): Promise<{ pass: boolean; message: () => string; actual?: unknown; expected?: unknown }> {\n const threshold = options?.threshold ?? 0.5;\n const metric = new AnswerRelevancyMetric({ threshold });\n return evaluateWithMetric(received, metric);\n },\n\n async toBeFaithful(\n received: LLMTestCase,\n options?: { threshold?: number },\n ): Promise<{ pass: boolean; message: () => string; actual?: unknown; expected?: unknown }> {\n const threshold = options?.threshold ?? 0.5;\n const metric = new FaithfulnessMetric({ threshold });\n return evaluateWithMetric(received, metric);\n },\n\n async toNotHallucinate(\n received: LLMTestCase,\n options?: { threshold?: number },\n ): Promise<{ pass: boolean; message: () => string; actual?: unknown; expected?: unknown }> {\n const threshold = options?.threshold ?? 0.5;\n const metric = new HallucinationMetric({ threshold });\n const result = await metric.measure(received);\n // HallucinationMetric returns a score where higher = more hallucination.\n // We invert: the test passes when hallucination score is BELOW the threshold.\n const hallucinationScore = result.score;\n const passed = hallucinationScore <= 1 - threshold;\n\n return {\n pass: passed,\n message: () =>\n passed\n ? formatPassMessage(\"HallucinationMetric (inverted)\", 1 - hallucinationScore, threshold)\n : formatFailureMessage(\n \"HallucinationMetric\",\n 1 - hallucinationScore,\n threshold,\n result.reason,\n ),\n actual: 1 - hallucinationScore,\n expected: threshold,\n };\n },\n\n async toPassMetric(\n received: LLMTestCase,\n metric: BaseMetric,\n ): Promise<{ pass: boolean; message: () => string; actual?: unknown; expected?: unknown }> {\n return evaluateWithMetric(received, metric);\n },\n\n async toPassAllMetrics(\n received: LLMTestCase,\n metrics: BaseMetric[],\n ): Promise<{ pass: boolean; message: () => string; actual?: unknown; expected?: unknown }> {\n const results = await Promise.all(\n metrics.map(async (metric) => {\n const result = await metric.measure(received);\n return {\n metric,\n result,\n passed: result.score >= metric.threshold,\n };\n }),\n );\n\n const allPassed = results.every((r) => r.passed);\n const failures = results.filter((r) => !r.passed);\n\n return {\n pass: allPassed,\n message: () => {\n if (allPassed) {\n const summary = results\n .map(\n (r) =>\n ` ${r.metric.name}: ${formatScore(r.result.score)} (threshold: ${formatScore(r.metric.threshold)})`,\n )\n .join(\"\\n\");\n return `Expected test case NOT to pass all metrics:\\n${summary}`;\n }\n\n const summary = failures\n .map(\n (r) =>\n ` ${r.metric.name}: ${formatScore(r.result.score)} < ${formatScore(r.metric.threshold)}${r.result.reason ? ` — ${r.result.reason}` : \"\"}`,\n )\n .join(\"\\n\");\n return `Expected test case to pass all metrics. ${failures.length} of ${metrics.length} failed:\\n${summary}`;\n },\n actual: results.map((r) => ({\n metric: r.metric.name,\n score: r.result.score,\n })),\n expected: metrics.map((m) => ({\n metric: m.name,\n threshold: m.threshold,\n })),\n };\n },\n};\n","import type { File, Reporter, Task, TaskResultPack } from \"vitest\";\n\nconst COLORS = {\n reset: \"\\x1b[0m\",\n bold: \"\\x1b[1m\",\n dim: \"\\x1b[2m\",\n green: \"\\x1b[32m\",\n red: \"\\x1b[31m\",\n yellow: \"\\x1b[33m\",\n cyan: \"\\x1b[36m\",\n magenta: \"\\x1b[35m\",\n white: \"\\x1b[37m\",\n bgGreen: \"\\x1b[42m\",\n bgRed: \"\\x1b[41m\",\n bgYellow: \"\\x1b[43m\",\n};\n\nfunction colorize(text: string, ...codes: string[]): string {\n return codes.join(\"\") + text + COLORS.reset;\n}\n\nfunction scoreBar(score: number, width = 20): string {\n const filled = Math.round(score * width);\n const empty = width - filled;\n const color = score >= 0.8 ? COLORS.green : score >= 0.5 ? COLORS.yellow : COLORS.red;\n return color + \"\\u2588\".repeat(filled) + COLORS.dim + \"\\u2591\".repeat(empty) + COLORS.reset;\n}\n\nfunction formatDuration(ms: number): string {\n if (ms < 1000) return `${ms}ms`;\n if (ms < 60_000) return `${(ms / 1000).toFixed(1)}s`;\n return `${(ms / 60_000).toFixed(1)}m`;\n}\n\ninterface MetricResult {\n metric: string;\n score: number;\n threshold?: number;\n passed: boolean;\n}\n\nfunction extractMetricResults(task: Task): MetricResult[] {\n const results: MetricResult[] = [];\n\n if (task.result?.state !== \"pass\" && task.result?.state !== \"fail\") {\n return results;\n }\n\n // Extract metric info from assertion errors if available\n if (task.result.errors) {\n for (const error of task.result.errors) {\n const message = error.message ?? \"\";\n\n // Parse metric results from our formatted error messages\n const metricMatch = /Expected test case (?:to|NOT to) pass (\\S+)/.exec(message);\n const scoreMatch = /Score:\\s+([\\d.]+)%/.exec(message);\n const thresholdMatch = /Threshold:\\s+([\\d.]+)%/.exec(message);\n\n if (metricMatch && scoreMatch && thresholdMatch) {\n const score = Number.parseFloat(scoreMatch[1]!) / 100;\n const threshold = Number.parseFloat(thresholdMatch[1]!) / 100;\n results.push({\n metric: metricMatch[1]!,\n score,\n threshold,\n passed: score >= threshold,\n });\n }\n }\n }\n\n return results;\n}\n\n/**\n * Vitest Reporter that formats Assay evaluation results with visual scoring\n * indicators, metric breakdowns, and a summary table.\n */\nexport class AssayReporter implements Reporter {\n private startTime = 0;\n private totalTests = 0;\n private passedTests = 0;\n private failedTests = 0;\n private skippedTests = 0;\n private allMetricResults: Array<{ test: string; metrics: MetricResult[] }> = [];\n\n onInit(): void {\n this.startTime = Date.now();\n console.log(\"\");\n console.log(\n colorize(\" ASSAY \", COLORS.bold, COLORS.bgGreen, COLORS.white) +\n colorize(\" LLM Evaluation Suite\", COLORS.bold, COLORS.cyan),\n );\n console.log(colorize(\"─\".repeat(60), COLORS.dim));\n console.log(\"\");\n }\n\n onTaskUpdate(packs: TaskResultPack[]): void {\n for (const [id, result] of packs) {\n if (!result) continue;\n\n // Task updates are processed; we accumulate counts in onFinished\n void id;\n }\n }\n\n onFinished(files?: File[]): void {\n if (!files) return;\n\n const tasks = this.collectTasks(files);\n\n for (const task of tasks) {\n this.totalTests++;\n\n if (task.result?.state === \"pass\") {\n this.passedTests++;\n this.printTaskResult(task, true);\n } else if (task.result?.state === \"fail\") {\n this.failedTests++;\n this.printTaskResult(task, false);\n } else {\n this.skippedTests++;\n }\n }\n\n this.printSummary();\n }\n\n private collectTasks(files: File[]): Task[] {\n const tasks: Task[] = [];\n\n function walk(items: Task[]): void {\n for (const item of items) {\n if (item.type === \"test\") {\n tasks.push(item);\n }\n if (\"tasks\" in item && item.tasks) {\n walk(item.tasks);\n }\n }\n }\n\n for (const file of files) {\n walk(file.tasks);\n }\n\n return tasks;\n }\n\n private printTaskResult(task: Task, passed: boolean): void {\n const icon = passed ? colorize(\"\\u2713\", COLORS.green) : colorize(\"\\u2717\", COLORS.red);\n const name = task.name;\n const duration = task.result?.duration\n ? colorize(` (${formatDuration(task.result.duration)})`, COLORS.dim)\n : \"\";\n\n console.log(` ${icon} ${name}${duration}`);\n\n // Extract and display metric results\n const metricResults = extractMetricResults(task);\n if (metricResults.length > 0) {\n this.allMetricResults.push({ test: name, metrics: metricResults });\n for (const mr of metricResults) {\n const statusIcon = mr.passed\n ? colorize(\"\\u25CF\", COLORS.green)\n : colorize(\"\\u25CF\", COLORS.red);\n const scoreStr = `${(mr.score * 100).toFixed(1)}%`;\n const thresholdStr = mr.threshold\n ? colorize(` (min: ${(mr.threshold * 100).toFixed(1)}%)`, COLORS.dim)\n : \"\";\n console.log(\n ` ${statusIcon} ${mr.metric}: ${scoreBar(mr.score)} ${scoreStr}${thresholdStr}`,\n );\n }\n }\n }\n\n private printSummary(): void {\n const duration = Date.now() - this.startTime;\n\n console.log(\"\");\n console.log(colorize(\"─\".repeat(60), COLORS.dim));\n\n // Metrics summary table\n if (this.allMetricResults.length > 0) {\n console.log(\"\");\n console.log(colorize(\" Metric Summary\", COLORS.bold, COLORS.magenta));\n console.log(\"\");\n\n const allMetrics = new Map<string, { scores: number[]; passed: number; total: number }>();\n\n for (const { metrics } of this.allMetricResults) {\n for (const m of metrics) {\n const existing = allMetrics.get(m.metric) ?? { scores: [], passed: 0, total: 0 };\n existing.scores.push(m.score);\n existing.total++;\n if (m.passed) existing.passed++;\n allMetrics.set(m.metric, existing);\n }\n }\n\n for (const [name, data] of allMetrics) {\n const avg = data.scores.reduce((a, b) => a + b, 0) / data.scores.length;\n const min = Math.min(...data.scores);\n const max = Math.max(...data.scores);\n const passRate = `${data.passed}/${data.total}`;\n\n console.log(\n ` ${colorize(name, COLORS.bold)} avg: ${(avg * 100).toFixed(1)}% min: ${(min * 100).toFixed(1)}% max: ${(max * 100).toFixed(1)}% pass: ${passRate}`,\n );\n }\n\n console.log(\"\");\n console.log(colorize(\"─\".repeat(60), COLORS.dim));\n }\n\n // Test totals\n console.log(\"\");\n const parts: string[] = [];\n if (this.passedTests > 0) {\n parts.push(colorize(`${this.passedTests} passed`, COLORS.green, COLORS.bold));\n }\n if (this.failedTests > 0) {\n parts.push(colorize(`${this.failedTests} failed`, COLORS.red, COLORS.bold));\n }\n if (this.skippedTests > 0) {\n parts.push(colorize(`${this.skippedTests} skipped`, COLORS.yellow));\n }\n parts.push(colorize(`${this.totalTests} total`, COLORS.white));\n\n console.log(` Tests: ${parts.join(colorize(\" | \", COLORS.dim))}`);\n console.log(` Duration: ${colorize(formatDuration(duration), COLORS.cyan)}`);\n console.log(\"\");\n }\n}\n"],"mappings":";AAAA,SAAS,cAAc;;;ACCvB,SAAS,uBAAuB,oBAAoB,2BAA2B;AAE/E,SAAS,YAAY,OAAuB;AAC1C,SAAO,IAAI,QAAQ,KAAK,QAAQ,CAAC,CAAC;AACpC;AAEA,SAAS,qBACP,YACA,OACA,WACA,QACQ;AACR,QAAM,QAAQ;AAAA,IACZ,8BAA8B,UAAU;AAAA,IACxC,gBAAgB,YAAY,KAAK,CAAC;AAAA,IAClC,gBAAgB,YAAY,SAAS,CAAC;AAAA,EACxC;AACA,MAAI,QAAQ;AACV,UAAM,KAAK,gBAAgB,MAAM,EAAE;AAAA,EACrC;AACA,SAAO,MAAM,KAAK,IAAI;AACxB;AAEA,SAAS,kBAAkB,YAAoB,OAAe,WAA2B;AACvF,SAAO;AAAA,IACL,kCAAkC,UAAU;AAAA,IAC5C,gBAAgB,YAAY,KAAK,CAAC;AAAA,IAClC,gBAAgB,YAAY,SAAS,CAAC;AAAA,EACxC,EAAE,KAAK,IAAI;AACb;AAEA,eAAe,mBACb,UACA,QACyF;AACzF,QAAM,SAAS,MAAM,OAAO,QAAQ,QAAQ;AAC5C,QAAM,SAAS,OAAO,SAAS,OAAO;AAEtC,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS,MACP,SACI,kBAAkB,OAAO,MAAM,OAAO,OAAO,OAAO,SAAS,IAC7D,qBAAqB,OAAO,MAAM,OAAO,OAAO,OAAO,WAAW,OAAO,MAAM;AAAA,IACrF,QAAQ,OAAO;AAAA,IACf,UAAU,OAAO;AAAA,EACnB;AACF;AAEO,IAAM,gBAAgB;AAAA,EAC3B,M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SAAS,GAAG,KAAK,UAAU,UAAU,OAAO,KAAK,CAAC;AAE7D,YAAQ,IAAI,eAAe,MAAM,KAAK,SAAS,OAAO,OAAO,GAAG,CAAC,CAAC,EAAE;AACpE,YAAQ,IAAI,eAAe,SAAS,eAAe,QAAQ,GAAG,OAAO,IAAI,CAAC,EAAE;AAC5E,YAAQ,IAAI,EAAE;AAAA,EAChB;AACF;;;AFlNO,SAAS,qBAA2B;AACzC,SAAO,OAAO,aAAa;AAC7B;","names":["summary"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@assay-ai/vitest",
|
|
3
|
+
"version": "0.1.0-beta",
|
|
4
|
+
"description": "Vitest integration for the Assay LLM evaluation framework",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.cjs",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
},
|
|
16
|
+
"require": {
|
|
17
|
+
"types": "./dist/index.d.cts",
|
|
18
|
+
"default": "./dist/index.cjs"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"vitest": ">=2.0.0",
|
|
27
|
+
"@assay-ai/core": "0.1.0-beta"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"tsup": "^8.3.0",
|
|
31
|
+
"typescript": "^5.7.0",
|
|
32
|
+
"vitest": "^3.0.0",
|
|
33
|
+
"@assay-ai/core": "0.1.0-beta",
|
|
34
|
+
"@assay-ai/tsconfig": "0.0.0"
|
|
35
|
+
},
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "https://github.com/assay-ai/assay",
|
|
39
|
+
"directory": "packages/vitest"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsup",
|
|
43
|
+
"dev": "tsup --watch",
|
|
44
|
+
"typecheck": "tsc --noEmit",
|
|
45
|
+
"test": "vitest run",
|
|
46
|
+
"clean": "rm -rf dist .turbo"
|
|
47
|
+
}
|
|
48
|
+
}
|