@mastra/evals 1.10.8 → 1.10.9-alpha.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/{checks-BX_kIFwJ.cjs → checks-CVR2yDHg.cjs} +3 -5
- package/dist/{checks-BX_kIFwJ.cjs.map → checks-CVR2yDHg.cjs.map} +1 -1
- package/dist/{checks-DxbqoaYq.js → checks-DXG9awTJ.js} +2 -3
- package/dist/{checks-DxbqoaYq.js.map → checks-DXG9awTJ.js.map} +1 -1
- package/dist/checks.cjs +1 -1
- package/dist/checks.js +1 -1
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-evals-overview.md +6 -4
- package/dist/docs/references/docs-evals-quick-checks.md +2 -2
- package/dist/docs/references/docs-guides-build-an-eval-loop.md +3 -3
- package/dist/docs/references/reference-evals-answer-relevancy.md +3 -3
- package/dist/docs/references/reference-evals-answer-similarity.md +5 -3
- package/dist/docs/references/reference-evals-bias.md +3 -3
- package/dist/docs/references/reference-evals-checks.md +1 -1
- package/dist/docs/references/reference-evals-content-similarity.md +2 -2
- package/dist/docs/references/reference-evals-context-precision.md +3 -3
- package/dist/docs/references/reference-evals-context-recall.md +3 -3
- package/dist/docs/references/reference-evals-context-relevance.md +11 -11
- package/dist/docs/references/reference-evals-faithfulness.md +1 -1
- package/dist/docs/references/reference-evals-hallucination.md +8 -8
- package/dist/docs/references/reference-evals-multi-turn-judge.md +2 -2
- package/dist/docs/references/reference-evals-noise-sensitivity.md +13 -13
- package/dist/docs/references/reference-evals-prompt-alignment.md +26 -25
- package/dist/docs/references/reference-evals-rubric.md +6 -6
- package/dist/docs/references/reference-evals-scorer-utils.md +6 -4
- package/dist/docs/references/reference-evals-summarization.md +4 -4
- package/dist/docs/references/reference-evals-tone-consistency.md +5 -5
- package/dist/docs/references/reference-evals-tool-call-accuracy.md +8 -8
- package/dist/docs/references/reference-evals-toxicity.md +1 -1
- package/dist/docs/references/reference-evals-trajectory-accuracy.md +1 -1
- package/dist/index.cjs +1 -2
- package/dist/index.js +1 -2
- package/dist/{matchers-DzWDR4_h.cjs → matchers-CL0xCK25.cjs} +2 -3
- package/dist/{matchers-DzWDR4_h.cjs.map → matchers-CL0xCK25.cjs.map} +1 -1
- package/dist/{matchers-D3c6f71B.js → matchers-CVIJYGVp.js} +2 -3
- package/dist/{matchers-D3c6f71B.js.map → matchers-CVIJYGVp.js.map} +1 -1
- package/dist/scorers/llm/rubric/index.d.ts +1 -1
- package/dist/scorers/prebuilt/index.cjs +41 -80
- package/dist/scorers/prebuilt/index.cjs.map +1 -1
- package/dist/scorers/prebuilt/index.js +41 -80
- package/dist/scorers/prebuilt/index.js.map +1 -1
- package/dist/scorers/utils.cjs +1 -2
- package/dist/scorers/utils.js +1 -2
- package/dist/vitest/index.cjs +4 -7
- package/dist/vitest/index.cjs.map +1 -1
- package/dist/vitest/index.js +4 -7
- package/dist/vitest/index.js.map +1 -1
- package/dist/vitest/setup.cjs +2 -3
- package/dist/vitest/setup.js +2 -3
- package/package.json +11 -11
package/dist/scorers/utils.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
let _mastra_core_evals = require("@mastra/core/evals");
|
|
3
3
|
let _mastra_core_request_context = require("@mastra/core/request-context");
|
|
4
|
-
|
|
4
|
+
// src/scorers/utils.ts
|
|
5
5
|
/**
|
|
6
6
|
* Extracts text content from a MastraDBMessage or ModelMessage-like object.
|
|
7
7
|
*
|
|
@@ -1133,7 +1133,6 @@ function analyzeToolFailures(trajectory, options = {}) {
|
|
|
1133
1133
|
excessiveRetryTools
|
|
1134
1134
|
};
|
|
1135
1135
|
}
|
|
1136
|
-
//#endregion
|
|
1137
1136
|
exports.analyzeToolFailures = analyzeToolFailures;
|
|
1138
1137
|
exports.checkTrajectoryBlacklist = checkTrajectoryBlacklist;
|
|
1139
1138
|
exports.checkTrajectoryEfficiency = checkTrajectoryEfficiency;
|
package/dist/scorers/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { extractTrajectory } from "@mastra/core/evals";
|
|
2
2
|
import { RequestContext } from "@mastra/core/request-context";
|
|
3
|
-
|
|
3
|
+
// src/scorers/utils.ts
|
|
4
4
|
/**
|
|
5
5
|
* Extracts text content from a MastraDBMessage or ModelMessage-like object.
|
|
6
6
|
*
|
|
@@ -1132,7 +1132,6 @@ function analyzeToolFailures(trajectory, options = {}) {
|
|
|
1132
1132
|
excessiveRetryTools
|
|
1133
1133
|
};
|
|
1134
1134
|
}
|
|
1135
|
-
//#endregion
|
|
1136
1135
|
export { analyzeToolFailures, checkTrajectoryBlacklist, checkTrajectoryEfficiency, compareTrajectories, createAgentTestRun, createTestMessage, createTestRun, createToolInvocation, createTrajectoryTestRun, extractAgentResponseMessages, extractInputMessages, extractToolCalls, extractToolResults, extractTrajectory, getAssistantMessageFromRunOutput, getCombinedSystemPrompt, getConversationHistoryFromRunInput, getReasoningFromRunOutput, getSystemMessagesFromRunInput, getTextContentFromMastraDBMessage, getUserMessageFromRunInput, isCloserTo, isScorerRunInputForAgent, isScorerRunOutputForAgent, mergeToolInvocations, roundToTwoDecimals, toToolLevelSteps };
|
|
1137
1136
|
|
|
1138
1137
|
//# sourceMappingURL=utils.js.map
|
package/dist/vitest/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_matchers = require("../matchers-
|
|
2
|
+
const require_matchers = require("../matchers-CL0xCK25.cjs");
|
|
3
3
|
let _mastra_core_evals = require("@mastra/core/evals");
|
|
4
|
-
|
|
4
|
+
// src/vitest/meta.ts
|
|
5
5
|
/**
|
|
6
6
|
* Flattens the `scores` record of a `RunEvalsResult` into `Record<string, number>`.
|
|
7
7
|
* Categorized results (`agent`, `workflow`, `steps`, `trajectory`) are flattened
|
|
@@ -30,8 +30,7 @@ function toEvalMeta(result) {
|
|
|
30
30
|
if (result.turnResults) meta.turnResults = result.turnResults;
|
|
31
31
|
return meta;
|
|
32
32
|
}
|
|
33
|
-
|
|
34
|
-
//#region src/vitest/expect-evals.ts
|
|
33
|
+
// src/vitest/expect-evals.ts
|
|
35
34
|
/** Thrown by `expectEval`/`expectEvals` `.toPass()` when the pass rate is not met. */
|
|
36
35
|
var EvalPassRateError = class extends Error {
|
|
37
36
|
result;
|
|
@@ -120,8 +119,7 @@ function expectEval(options) {
|
|
|
120
119
|
data: [options.data]
|
|
121
120
|
});
|
|
122
121
|
}
|
|
123
|
-
|
|
124
|
-
//#region src/vitest/reporter.ts
|
|
122
|
+
// src/vitest/reporter.ts
|
|
125
123
|
const GREEN = "\x1B[32m";
|
|
126
124
|
const RED = "\x1B[31m";
|
|
127
125
|
const YELLOW = "\x1B[33m";
|
|
@@ -257,7 +255,6 @@ const ANSI_PATTERN = /\u001b\[[0-9;]*m/g;
|
|
|
257
255
|
function stripAnsi(text) {
|
|
258
256
|
return text.replace(ANSI_PATTERN, "");
|
|
259
257
|
}
|
|
260
|
-
//#endregion
|
|
261
258
|
exports.EvalPassRateError = EvalPassRateError;
|
|
262
259
|
exports.MastraEvalsReporter = MastraEvalsReporter;
|
|
263
260
|
exports.evalMatchers = require_matchers.evalMatchers;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["runEvals"],"sources":["../../src/vitest/meta.ts","../../src/vitest/expect-evals.ts","../../src/vitest/reporter.ts"],"sourcesContent":["import type { EvalVerdict, GateResult, RunEvalsResult, ThresholdConfig, TurnResult } from '@mastra/core/evals';\n\n/** Per-threshold-scorer result, as reported in `RunEvalsResult.thresholdResults`. */\nexport type EvalThresholdResult = {\n id: string;\n passed: boolean;\n averageScore: number;\n threshold: ThresholdConfig;\n};\n\n/**\n * Serializable projection of a `RunEvalsResult` stored in `task.meta.mastraEval`.\n *\n * This is the contract between the test worker (which runs `runEvals`) and the\n * `MastraEvalsReporter` running in the main process. It intentionally excludes\n * raw agent/workflow payloads: `task.meta` is structured-cloned from worker to\n * main, so only lightweight, serializable data belongs here.\n */\nexport type MastraEvalMeta = {\n /**\n * Average score per scorer id across all data items. Categorized scorer\n * configs are flattened into dot-separated keys (e.g. `agent.my-scorer`,\n * `steps.step-1.my-scorer`).\n */\n scores: Record<string, number>;\n /** Number of data items evaluated. */\n totalItems: number;\n /** Present when gates or threshold-bearing scorers were provided. */\n verdict?: EvalVerdict;\n /** Per-gate results (averaged across all data items). */\n gateResults?: GateResult[];\n /** Per-threshold-scorer results (averaged across all data items). */\n thresholdResults?: EvalThresholdResult[];\n /** Per-turn assertion results, present when data items use `turns`. */\n turnResults?: TurnResult[];\n};\n\ndeclare module 'vitest' {\n interface TaskMeta {\n mastraEval?: MastraEvalMeta;\n }\n}\n\n/**\n * Flattens the `scores` record of a `RunEvalsResult` into `Record<string, number>`.\n * Categorized results (`agent`, `workflow`, `steps`, `trajectory`) are flattened\n * into dot-separated keys, e.g. `agent.my-scorer` or `steps.step-1.my-scorer`.\n */\nfunction flattenScores(scores: Record<string, any>, prefix = '', out: Record<string, number> = {}) {\n for (const [id, value] of Object.entries(scores)) {\n const key = prefix ? `${prefix}.${id}` : id;\n if (typeof value === 'number') {\n out[key] = value;\n } else if (value && typeof value === 'object') {\n flattenScores(value, key, out);\n }\n }\n return out;\n}\n\n/**\n * Projects a `RunEvalsResult` into the serializable `MastraEvalMeta` shape\n * stored in `task.meta.mastraEval`.\n */\nexport function toEvalMeta(result: RunEvalsResult): MastraEvalMeta {\n const meta: MastraEvalMeta = {\n scores: flattenScores(result.scores),\n totalItems: result.summary.totalItems,\n };\n if (result.verdict !== undefined) meta.verdict = result.verdict;\n if (result.gateResults) meta.gateResults = result.gateResults.map(g => ({ ...g }));\n if (result.thresholdResults) meta.thresholdResults = result.thresholdResults.map(t => ({ ...t }));\n if (result.turnResults) meta.turnResults = result.turnResults;\n return meta;\n}\n","import type { RunEvalsConfig, RunEvalsResult } from '@mastra/core/evals';\nimport { runEvals } from '@mastra/core/evals';\n\nimport { toEvalMeta } from './meta';\n\n/**\n * Options accepted by `expectEvals`: exactly the `runEvals` configuration\n * (target, data items, scorers/gates/thresholds, etc.).\n */\nexport type ExpectEvalsOptions = RunEvalsConfig;\n\n/** A single eval data item, as accepted by `runEvals` in its `data` array. */\nexport type EvalDataItem = RunEvalsConfig['data'][number];\n\n/**\n * Options accepted by `expectEval`: same as `expectEvals`, but `data` is a single item.\n * Distributes over the config union so each target keeps its own data-item contract\n * (e.g. `turns` stays agent-only).\n */\nexport type ExpectEvalOptions = RunEvalsConfig extends infer T\n ? T extends RunEvalsConfig\n ? Omit<T, 'data'> & { data: T['data'][number] }\n : never\n : never;\n\n/** Thrown by `expectEval`/`expectEvals` `.toPass()` when the pass rate is not met. */\nexport class EvalPassRateError extends Error {\n readonly result: RunEvalsResult;\n\n constructor(message: string, result: RunEvalsResult) {\n super(message);\n this.name = 'EvalPassRateError';\n this.result = result;\n }\n}\n\n/** Fluent assertion returned by `expectEval` and `expectEvals`. */\nexport type EvalScoresAssertion = {\n /**\n * Runs the eval and asserts it passes.\n *\n * - Every gate's pass rate across data items must be `>= minPassRate`\n * (gates score 1 on pass and 0 on failure, so the averaged gate score\n * is exactly the fraction of items that passed the gate).\n * - Every scorer threshold must pass (thresholds compare the average\n * score across items and are not relaxed by `minPassRate`).\n *\n * @param minPassRate Minimum per-gate pass rate in `[0, 1]`. Defaults to 1\n * (all items must pass every gate).\n * @returns The full `RunEvalsResult` for further assertions.\n */\n toPass(minPassRate?: number): Promise<RunEvalsResult>;\n};\n\nasync function attachMetaToCurrentTest(result: RunEvalsResult): Promise<void> {\n try {\n const vitest = await import('vitest');\n // Vitest >= 4.1\n const task = (vitest as any).TestRunner?.getCurrentTest?.();\n if (task?.meta) {\n task.meta.mastraEval = toEvalMeta(result);\n return;\n }\n // Vitest 3.x / < 4.1\n const suite = await import('vitest/suite');\n const legacyTask = (suite as any).getCurrentTest?.();\n if (legacyTask?.meta) {\n legacyTask.meta.mastraEval = toEvalMeta(result);\n }\n } catch {\n // Outside a Vitest test context — assertion still works, reporter meta is skipped.\n }\n}\n\nfunction assertPassRate(result: RunEvalsResult, minPassRate: number): void {\n if (!Number.isFinite(minPassRate) || minPassRate < 0 || minPassRate > 1) {\n throw new Error(`toPass(minPassRate): minPassRate must be within [0, 1], got ${minPassRate}`);\n }\n\n const lines: string[] = [];\n\n for (const gate of result.gateResults ?? []) {\n if (gate.score < minPassRate) {\n lines.push(` ✗ gate ${gate.id}: pass rate ${formatRate(gate.score)} < required ${formatRate(minPassRate)}`);\n }\n }\n\n for (const t of result.thresholdResults ?? []) {\n if (!t.passed) {\n lines.push(` ✗ threshold ${t.id}: average score ${t.averageScore} (threshold: ${JSON.stringify(t.threshold)})`);\n }\n }\n\n for (const turn of result.turnResults ?? []) {\n for (const gate of turn.gateResults ?? []) {\n if (gate.score < minPassRate) {\n lines.push(\n ` ✗ turn ${turn.index} gate ${gate.id}: pass rate ${formatRate(gate.score)} < required ${formatRate(minPassRate)}`,\n );\n }\n }\n for (const t of turn.thresholdResults ?? []) {\n if (!t.passed) {\n lines.push(\n ` ✗ turn ${turn.index} threshold ${t.id}: average score ${t.averageScore} (threshold: ${JSON.stringify(t.threshold)})`,\n );\n }\n }\n }\n\n if (lines.length > 0) {\n throw new EvalPassRateError(\n [`Eval did not pass (required pass rate: ${formatRate(minPassRate)}).`, ...lines].join('\\n'),\n result,\n );\n }\n}\n\nfunction formatRate(rate: number): string {\n return `${Math.round(rate * 1000) / 10}%`;\n}\n\nfunction makeAssertion(options: ExpectEvalsOptions): EvalScoresAssertion {\n return {\n async toPass(minPassRate = 1): Promise<RunEvalsResult> {\n const result = await runEvals(options as Parameters<typeof runEvals>[0]);\n await attachMetaToCurrentTest(result);\n assertPassRate(result, minPassRate);\n return result;\n },\n };\n}\n\n/**\n * Fluent eval assertion over a dataset, for use inside a regular `test()`.\n *\n * Runs `runEvals` with the given options when awaited and asserts the outcome.\n * The run's scores are attached to the current test's meta so\n * `MastraEvalsReporter` displays them in the runner output.\n *\n * Must be awaited — otherwise the test finishes before the eval runs.\n *\n * @example\n * test('capitals agent answers with the expected city', async () => {\n * await expectEvals({\n * target: capitalsAgent,\n * data: [{ input: 'What is the capital of France?', groundTruth: 'Paris' }],\n * gates: [containsGroundTruth],\n * scorers: [{ scorer: createKeywordCoverageScorer(), threshold: 0.4 }],\n * }).toPass(0.8);\n * });\n */\nexport function expectEvals(options: ExpectEvalsOptions): EvalScoresAssertion {\n return makeAssertion(options);\n}\n\n/**\n * Single-item variant of `expectEvals`: `data` is one item instead of an array.\n *\n * Use it with `test.each`/`it.each` for matrix testing when you want one test\n * (and one reporter entry) per data item instead of one per dataset run.\n *\n * @example\n * test.each([\n * { input: 'What is the capital of France?', groundTruth: 'Paris' },\n * { input: 'What is the capital of Japan?', groundTruth: 'Tokyo' },\n * ])('capitals agent: $input', async item => {\n * await expectEval({\n * target: capitalsAgent,\n * data: item,\n * gates: [containsGroundTruth],\n * }).toPass();\n * });\n */\nexport function expectEval(options: ExpectEvalOptions): EvalScoresAssertion {\n return makeAssertion({ ...options, data: [options.data] } as ExpectEvalsOptions);\n}\n","import type { ThresholdConfig } from '@mastra/core/evals';\nimport type { Reporter, TestCase, TestModule } from 'vitest/node';\n\nimport type { MastraEvalMeta } from './meta';\n\ntype EvalEntry = {\n fullName: string;\n meta: MastraEvalMeta;\n};\n\nconst GREEN = '\\u001b[32m';\nconst RED = '\\u001b[31m';\nconst YELLOW = '\\u001b[33m';\nconst BOLD = '\\u001b[1m';\nconst DIM = '\\u001b[2m';\nconst RESET = '\\u001b[0m';\n\nfunction supportsColor(): boolean {\n return process.stdout.isTTY === true && process.env.NO_COLOR === undefined;\n}\n\n/**\n * Vitest reporter that prints a per-test score table for every eval run\n * using `expectEval`/`expectEvals` (or any test that populates `task.meta.mastraEval`).\n *\n * Usage in `vitest.config.ts`:\n * test: { reporters: ['default', new MastraEvalsReporter()] }\n */\nexport class MastraEvalsReporter implements Reporter {\n private readonly color: boolean;\n\n constructor(options: { color?: boolean } = {}) {\n this.color = options.color ?? supportsColor();\n }\n\n onTestRunEnd(testModules: ReadonlyArray<TestModule>): void {\n const entries: EvalEntry[] = [];\n for (const module of testModules) {\n for (const test of module.children.allTests()) {\n const meta = ((test as TestCase).meta() as { mastraEval?: MastraEvalMeta }).mastraEval;\n if (meta) {\n entries.push({ fullName: test.fullName, meta });\n }\n }\n }\n\n if (entries.length === 0) return;\n\n this.print(this.render(entries));\n }\n\n /** Renders the score report as plain lines. Exposed for testing. */\n render(entries: EvalEntry[]): string {\n const lines: string[] = [];\n lines.push('');\n lines.push(this.style(BOLD, ' Mastra Evals '));\n\n for (const { fullName, meta } of entries) {\n lines.push('');\n lines.push(\n `${this.verdictBadge(meta.verdict)} ${this.style(BOLD, fullName)} ${this.style(DIM, `(${meta.totalItems} item${meta.totalItems === 1 ? '' : 's'})`)}`,\n );\n\n const rows: Array<[string, string, string]> = [];\n for (const gate of meta.gateResults ?? []) {\n rows.push([`${gate.id} ${this.style(DIM, '(gate)')}`, formatScore(gate.score), this.passMark(gate.passed)]);\n }\n for (const t of meta.thresholdResults ?? []) {\n rows.push([\n `${t.id} ${this.style(DIM, `(threshold: ${formatThreshold(t.threshold)})`)}`,\n formatScore(t.averageScore),\n this.passMark(t.passed),\n ]);\n }\n const covered = new Set([\n ...(meta.gateResults ?? []).map(g => g.id),\n ...(meta.thresholdResults ?? []).map(t => t.id),\n ]);\n for (const [id, score] of Object.entries(meta.scores)) {\n if (covered.has(id)) continue;\n rows.push([id, formatScore(score), '']);\n }\n\n lines.push(...this.table(rows));\n\n for (const turn of meta.turnResults ?? []) {\n const turnRows: Array<[string, string, string]> = [];\n for (const gate of turn.gateResults ?? []) {\n turnRows.push([\n `${gate.id} ${this.style(DIM, '(gate)')}`,\n formatScore(gate.score),\n this.passMark(gate.passed),\n ]);\n }\n for (const t of turn.thresholdResults ?? []) {\n turnRows.push([\n `${t.id} ${this.style(DIM, `(threshold: ${formatThreshold(t.threshold)})`)}`,\n formatScore(t.averageScore),\n this.passMark(t.passed),\n ]);\n }\n const turnCovered = new Set([\n ...(turn.gateResults ?? []).map(g => g.id),\n ...(turn.thresholdResults ?? []).map(t => t.id),\n ]);\n for (const [id, score] of Object.entries(turn.scores ?? {})) {\n if (turnCovered.has(id)) continue;\n turnRows.push([id, formatScore(score), '']);\n }\n if (turnRows.length === 0) continue;\n lines.push(` ${this.style(DIM, `turn ${turn.index}`)}`);\n lines.push(...this.table(turnRows, ' '));\n }\n }\n\n const withVerdict = entries.filter(e => e.meta.verdict !== undefined);\n const passed = withVerdict.filter(e => e.meta.verdict === 'passed').length;\n const failed = withVerdict.filter(e => e.meta.verdict === 'failed').length;\n const scored = entries.length - passed - failed;\n lines.push('');\n const parts: string[] = [];\n if (passed > 0) parts.push(this.style(GREEN, `${passed} passed`));\n if (failed > 0) parts.push(this.style(RED, `${failed} failed`));\n if (scored > 0) parts.push(this.style(YELLOW, `${scored} scored`));\n lines.push(` Eval runs: ${entries.length} ${this.style(DIM, `(${parts.join(', ')})`)}`);\n lines.push('');\n\n return lines.join('\\n');\n }\n\n private table(rows: Array<[string, string, string]>, indent = ''): string[] {\n if (rows.length === 0) return [];\n const nameWidth = Math.max(...rows.map(([name]) => stripAnsi(name).length));\n const scoreWidth = Math.max(5, ...rows.map(([, score]) => score.length));\n return rows.map(([name, score, mark]) => {\n const namePad = ' '.repeat(nameWidth - stripAnsi(name).length);\n return `${indent} ${name}${namePad} ${score.padStart(scoreWidth)} ${mark}`.trimEnd();\n });\n }\n\n private verdictBadge(verdict: MastraEvalMeta['verdict']): string {\n if (verdict === 'passed') return this.style(GREEN, '✓');\n if (verdict === 'failed') return this.style(RED, '✗');\n return this.style(YELLOW, '•');\n }\n\n private passMark(passed: boolean): string {\n return passed ? this.style(GREEN, '✓') : this.style(RED, '✗');\n }\n\n private style(code: string, text: string): string {\n return this.color ? `${code}${text}${RESET}` : text;\n }\n\n private print(output: string): void {\n process.stdout.write(`${output}\\n`);\n }\n}\n\nfunction formatScore(score: number): string {\n return Number.isInteger(score) ? score.toFixed(1) : score.toFixed(3).replace(/0+$/, '').replace(/\\.$/, '.0');\n}\n\nfunction formatThreshold(threshold: ThresholdConfig): string {\n if (typeof threshold === 'number') return `min ${threshold}`;\n return Object.entries(threshold)\n .map(([key, value]) => `${key} ${value}`)\n .join(', ');\n}\n\n// eslint-disable-next-line no-control-regex\nconst ANSI_PATTERN = /\\u001b\\[[0-9;]*m/g;\n\nfunction stripAnsi(text: string): string {\n return text.replace(ANSI_PATTERN, '');\n}\n"],"mappings":";;;;;;;;;AAgDA,SAAS,cAAc,QAA6B,SAAS,IAAI,MAA8B,CAAC,GAAG;CACjG,KAAK,MAAM,CAAC,IAAI,UAAU,OAAO,QAAQ,MAAM,GAAG;EAChD,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,OAAO;EACzC,IAAI,OAAO,UAAU,UACnB,IAAI,OAAO;OACN,IAAI,SAAS,OAAO,UAAU,UACnC,cAAc,OAAO,KAAK,GAAG;CAEjC;CACA,OAAO;AACT;;;;;AAMA,SAAgB,WAAW,QAAwC;CACjE,MAAM,OAAuB;EAC3B,QAAQ,cAAc,OAAO,MAAM;EACnC,YAAY,OAAO,QAAQ;CAC7B;CACA,IAAI,OAAO,YAAY,KAAA,GAAW,KAAK,UAAU,OAAO;CACxD,IAAI,OAAO,aAAa,KAAK,cAAc,OAAO,YAAY,KAAI,OAAM,EAAE,GAAG,EAAE,EAAE;CACjF,IAAI,OAAO,kBAAkB,KAAK,mBAAmB,OAAO,iBAAiB,KAAI,OAAM,EAAE,GAAG,EAAE,EAAE;CAChG,IAAI,OAAO,aAAa,KAAK,cAAc,OAAO;CAClD,OAAO;AACT;;;;AChDA,IAAa,oBAAb,cAAuC,MAAM;CAC3C;CAEA,YAAY,SAAiB,QAAwB;EACnD,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,SAAS;CAChB;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,KAAK,QAAQ,GAAG,OAAO,OAAO,UAAU;CACjD;CAEA,MAAc,QAAsB;EAClC,QAAQ,OAAO,MAAM,GAAG,OAAO,GAAG;CACpC;AACF;AAEA,SAAS,YAAY,OAAuB;CAC1C,OAAO,OAAO,UAAU,KAAK,IAAI,MAAM,QAAQ,CAAC,IAAI,MAAM,QAAQ,CAAC,CAAC,CAAC,QAAQ,OAAO,EAAE,CAAC,CAAC,QAAQ,OAAO,IAAI;AAC7G;AAEA,SAAS,gBAAgB,WAAoC;CAC3D,IAAI,OAAO,cAAc,UAAU,OAAO,OAAO;CACjD,OAAO,OAAO,QAAQ,SAAS,CAAC,CAC7B,KAAK,CAAC,KAAK,WAAW,GAAG,IAAI,GAAG,OAAO,CAAC,CACxC,KAAK,IAAI;AACd;AAGA,MAAM,eAAe;AAErB,SAAS,UAAU,MAAsB;CACvC,OAAO,KAAK,QAAQ,cAAc,EAAE;AACtC"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["runEvals"],"sources":["../../src/vitest/meta.ts","../../src/vitest/expect-evals.ts","../../src/vitest/reporter.ts"],"sourcesContent":["import type { EvalVerdict, GateResult, RunEvalsResult, ThresholdConfig, TurnResult } from '@mastra/core/evals';\n\n/** Per-threshold-scorer result, as reported in `RunEvalsResult.thresholdResults`. */\nexport type EvalThresholdResult = {\n id: string;\n passed: boolean;\n averageScore: number;\n threshold: ThresholdConfig;\n};\n\n/**\n * Serializable projection of a `RunEvalsResult` stored in `task.meta.mastraEval`.\n *\n * This is the contract between the test worker (which runs `runEvals`) and the\n * `MastraEvalsReporter` running in the main process. It intentionally excludes\n * raw agent/workflow payloads: `task.meta` is structured-cloned from worker to\n * main, so only lightweight, serializable data belongs here.\n */\nexport type MastraEvalMeta = {\n /**\n * Average score per scorer id across all data items. Categorized scorer\n * configs are flattened into dot-separated keys (e.g. `agent.my-scorer`,\n * `steps.step-1.my-scorer`).\n */\n scores: Record<string, number>;\n /** Number of data items evaluated. */\n totalItems: number;\n /** Present when gates or threshold-bearing scorers were provided. */\n verdict?: EvalVerdict;\n /** Per-gate results (averaged across all data items). */\n gateResults?: GateResult[];\n /** Per-threshold-scorer results (averaged across all data items). */\n thresholdResults?: EvalThresholdResult[];\n /** Per-turn assertion results, present when data items use `turns`. */\n turnResults?: TurnResult[];\n};\n\ndeclare module 'vitest' {\n interface TaskMeta {\n mastraEval?: MastraEvalMeta;\n }\n}\n\n/**\n * Flattens the `scores` record of a `RunEvalsResult` into `Record<string, number>`.\n * Categorized results (`agent`, `workflow`, `steps`, `trajectory`) are flattened\n * into dot-separated keys, e.g. `agent.my-scorer` or `steps.step-1.my-scorer`.\n */\nfunction flattenScores(scores: Record<string, any>, prefix = '', out: Record<string, number> = {}) {\n for (const [id, value] of Object.entries(scores)) {\n const key = prefix ? `${prefix}.${id}` : id;\n if (typeof value === 'number') {\n out[key] = value;\n } else if (value && typeof value === 'object') {\n flattenScores(value, key, out);\n }\n }\n return out;\n}\n\n/**\n * Projects a `RunEvalsResult` into the serializable `MastraEvalMeta` shape\n * stored in `task.meta.mastraEval`.\n */\nexport function toEvalMeta(result: RunEvalsResult): MastraEvalMeta {\n const meta: MastraEvalMeta = {\n scores: flattenScores(result.scores),\n totalItems: result.summary.totalItems,\n };\n if (result.verdict !== undefined) meta.verdict = result.verdict;\n if (result.gateResults) meta.gateResults = result.gateResults.map(g => ({ ...g }));\n if (result.thresholdResults) meta.thresholdResults = result.thresholdResults.map(t => ({ ...t }));\n if (result.turnResults) meta.turnResults = result.turnResults;\n return meta;\n}\n","import type { RunEvalsConfig, RunEvalsResult } from '@mastra/core/evals';\nimport { runEvals } from '@mastra/core/evals';\n\nimport { toEvalMeta } from './meta';\n\n/**\n * Options accepted by `expectEvals`: exactly the `runEvals` configuration\n * (target, data items, scorers/gates/thresholds, etc.).\n */\nexport type ExpectEvalsOptions = RunEvalsConfig;\n\n/** A single eval data item, as accepted by `runEvals` in its `data` array. */\nexport type EvalDataItem = RunEvalsConfig['data'][number];\n\n/**\n * Options accepted by `expectEval`: same as `expectEvals`, but `data` is a single item.\n * Distributes over the config union so each target keeps its own data-item contract\n * (e.g. `turns` stays agent-only).\n */\nexport type ExpectEvalOptions = RunEvalsConfig extends infer T\n ? T extends RunEvalsConfig\n ? Omit<T, 'data'> & { data: T['data'][number] }\n : never\n : never;\n\n/** Thrown by `expectEval`/`expectEvals` `.toPass()` when the pass rate is not met. */\nexport class EvalPassRateError extends Error {\n readonly result: RunEvalsResult;\n\n constructor(message: string, result: RunEvalsResult) {\n super(message);\n this.name = 'EvalPassRateError';\n this.result = result;\n }\n}\n\n/** Fluent assertion returned by `expectEval` and `expectEvals`. */\nexport type EvalScoresAssertion = {\n /**\n * Runs the eval and asserts it passes.\n *\n * - Every gate's pass rate across data items must be `>= minPassRate`\n * (gates score 1 on pass and 0 on failure, so the averaged gate score\n * is exactly the fraction of items that passed the gate).\n * - Every scorer threshold must pass (thresholds compare the average\n * score across items and are not relaxed by `minPassRate`).\n *\n * @param minPassRate Minimum per-gate pass rate in `[0, 1]`. Defaults to 1\n * (all items must pass every gate).\n * @returns The full `RunEvalsResult` for further assertions.\n */\n toPass(minPassRate?: number): Promise<RunEvalsResult>;\n};\n\nasync function attachMetaToCurrentTest(result: RunEvalsResult): Promise<void> {\n try {\n const vitest = await import('vitest');\n // Vitest >= 4.1\n const task = (vitest as any).TestRunner?.getCurrentTest?.();\n if (task?.meta) {\n task.meta.mastraEval = toEvalMeta(result);\n return;\n }\n // Vitest 3.x / < 4.1\n const suite = await import('vitest/suite');\n const legacyTask = (suite as any).getCurrentTest?.();\n if (legacyTask?.meta) {\n legacyTask.meta.mastraEval = toEvalMeta(result);\n }\n } catch {\n // Outside a Vitest test context — assertion still works, reporter meta is skipped.\n }\n}\n\nfunction assertPassRate(result: RunEvalsResult, minPassRate: number): void {\n if (!Number.isFinite(minPassRate) || minPassRate < 0 || minPassRate > 1) {\n throw new Error(`toPass(minPassRate): minPassRate must be within [0, 1], got ${minPassRate}`);\n }\n\n const lines: string[] = [];\n\n for (const gate of result.gateResults ?? []) {\n if (gate.score < minPassRate) {\n lines.push(` ✗ gate ${gate.id}: pass rate ${formatRate(gate.score)} < required ${formatRate(minPassRate)}`);\n }\n }\n\n for (const t of result.thresholdResults ?? []) {\n if (!t.passed) {\n lines.push(` ✗ threshold ${t.id}: average score ${t.averageScore} (threshold: ${JSON.stringify(t.threshold)})`);\n }\n }\n\n for (const turn of result.turnResults ?? []) {\n for (const gate of turn.gateResults ?? []) {\n if (gate.score < minPassRate) {\n lines.push(\n ` ✗ turn ${turn.index} gate ${gate.id}: pass rate ${formatRate(gate.score)} < required ${formatRate(minPassRate)}`,\n );\n }\n }\n for (const t of turn.thresholdResults ?? []) {\n if (!t.passed) {\n lines.push(\n ` ✗ turn ${turn.index} threshold ${t.id}: average score ${t.averageScore} (threshold: ${JSON.stringify(t.threshold)})`,\n );\n }\n }\n }\n\n if (lines.length > 0) {\n throw new EvalPassRateError(\n [`Eval did not pass (required pass rate: ${formatRate(minPassRate)}).`, ...lines].join('\\n'),\n result,\n );\n }\n}\n\nfunction formatRate(rate: number): string {\n return `${Math.round(rate * 1000) / 10}%`;\n}\n\nfunction makeAssertion(options: ExpectEvalsOptions): EvalScoresAssertion {\n return {\n async toPass(minPassRate = 1): Promise<RunEvalsResult> {\n const result = await runEvals(options as Parameters<typeof runEvals>[0]);\n await attachMetaToCurrentTest(result);\n assertPassRate(result, minPassRate);\n return result;\n },\n };\n}\n\n/**\n * Fluent eval assertion over a dataset, for use inside a regular `test()`.\n *\n * Runs `runEvals` with the given options when awaited and asserts the outcome.\n * The run's scores are attached to the current test's meta so\n * `MastraEvalsReporter` displays them in the runner output.\n *\n * Must be awaited — otherwise the test finishes before the eval runs.\n *\n * @example\n * test('capitals agent answers with the expected city', async () => {\n * await expectEvals({\n * target: capitalsAgent,\n * data: [{ input: 'What is the capital of France?', groundTruth: 'Paris' }],\n * gates: [containsGroundTruth],\n * scorers: [{ scorer: createKeywordCoverageScorer(), threshold: 0.4 }],\n * }).toPass(0.8);\n * });\n */\nexport function expectEvals(options: ExpectEvalsOptions): EvalScoresAssertion {\n return makeAssertion(options);\n}\n\n/**\n * Single-item variant of `expectEvals`: `data` is one item instead of an array.\n *\n * Use it with `test.each`/`it.each` for matrix testing when you want one test\n * (and one reporter entry) per data item instead of one per dataset run.\n *\n * @example\n * test.each([\n * { input: 'What is the capital of France?', groundTruth: 'Paris' },\n * { input: 'What is the capital of Japan?', groundTruth: 'Tokyo' },\n * ])('capitals agent: $input', async item => {\n * await expectEval({\n * target: capitalsAgent,\n * data: item,\n * gates: [containsGroundTruth],\n * }).toPass();\n * });\n */\nexport function expectEval(options: ExpectEvalOptions): EvalScoresAssertion {\n return makeAssertion({ ...options, data: [options.data] } as ExpectEvalsOptions);\n}\n","import type { ThresholdConfig } from '@mastra/core/evals';\nimport type { Reporter, TestCase, TestModule } from 'vitest/node';\n\nimport type { MastraEvalMeta } from './meta';\n\ntype EvalEntry = {\n fullName: string;\n meta: MastraEvalMeta;\n};\n\nconst GREEN = '\\u001b[32m';\nconst RED = '\\u001b[31m';\nconst YELLOW = '\\u001b[33m';\nconst BOLD = '\\u001b[1m';\nconst DIM = '\\u001b[2m';\nconst RESET = '\\u001b[0m';\n\nfunction supportsColor(): boolean {\n return process.stdout.isTTY === true && process.env.NO_COLOR === undefined;\n}\n\n/**\n * Vitest reporter that prints a per-test score table for every eval run\n * using `expectEval`/`expectEvals` (or any test that populates `task.meta.mastraEval`).\n *\n * Usage in `vitest.config.ts`:\n * test: { reporters: ['default', new MastraEvalsReporter()] }\n */\nexport class MastraEvalsReporter implements Reporter {\n private readonly color: boolean;\n\n constructor(options: { color?: boolean } = {}) {\n this.color = options.color ?? supportsColor();\n }\n\n onTestRunEnd(testModules: ReadonlyArray<TestModule>): void {\n const entries: EvalEntry[] = [];\n for (const module of testModules) {\n for (const test of module.children.allTests()) {\n const meta = ((test as TestCase).meta() as { mastraEval?: MastraEvalMeta }).mastraEval;\n if (meta) {\n entries.push({ fullName: test.fullName, meta });\n }\n }\n }\n\n if (entries.length === 0) return;\n\n this.print(this.render(entries));\n }\n\n /** Renders the score report as plain lines. Exposed for testing. */\n render(entries: EvalEntry[]): string {\n const lines: string[] = [];\n lines.push('');\n lines.push(this.style(BOLD, ' Mastra Evals '));\n\n for (const { fullName, meta } of entries) {\n lines.push('');\n lines.push(\n `${this.verdictBadge(meta.verdict)} ${this.style(BOLD, fullName)} ${this.style(DIM, `(${meta.totalItems} item${meta.totalItems === 1 ? '' : 's'})`)}`,\n );\n\n const rows: Array<[string, string, string]> = [];\n for (const gate of meta.gateResults ?? []) {\n rows.push([`${gate.id} ${this.style(DIM, '(gate)')}`, formatScore(gate.score), this.passMark(gate.passed)]);\n }\n for (const t of meta.thresholdResults ?? []) {\n rows.push([\n `${t.id} ${this.style(DIM, `(threshold: ${formatThreshold(t.threshold)})`)}`,\n formatScore(t.averageScore),\n this.passMark(t.passed),\n ]);\n }\n const covered = new Set([\n ...(meta.gateResults ?? []).map(g => g.id),\n ...(meta.thresholdResults ?? []).map(t => t.id),\n ]);\n for (const [id, score] of Object.entries(meta.scores)) {\n if (covered.has(id)) continue;\n rows.push([id, formatScore(score), '']);\n }\n\n lines.push(...this.table(rows));\n\n for (const turn of meta.turnResults ?? []) {\n const turnRows: Array<[string, string, string]> = [];\n for (const gate of turn.gateResults ?? []) {\n turnRows.push([\n `${gate.id} ${this.style(DIM, '(gate)')}`,\n formatScore(gate.score),\n this.passMark(gate.passed),\n ]);\n }\n for (const t of turn.thresholdResults ?? []) {\n turnRows.push([\n `${t.id} ${this.style(DIM, `(threshold: ${formatThreshold(t.threshold)})`)}`,\n formatScore(t.averageScore),\n this.passMark(t.passed),\n ]);\n }\n const turnCovered = new Set([\n ...(turn.gateResults ?? []).map(g => g.id),\n ...(turn.thresholdResults ?? []).map(t => t.id),\n ]);\n for (const [id, score] of Object.entries(turn.scores ?? {})) {\n if (turnCovered.has(id)) continue;\n turnRows.push([id, formatScore(score), '']);\n }\n if (turnRows.length === 0) continue;\n lines.push(` ${this.style(DIM, `turn ${turn.index}`)}`);\n lines.push(...this.table(turnRows, ' '));\n }\n }\n\n const withVerdict = entries.filter(e => e.meta.verdict !== undefined);\n const passed = withVerdict.filter(e => e.meta.verdict === 'passed').length;\n const failed = withVerdict.filter(e => e.meta.verdict === 'failed').length;\n const scored = entries.length - passed - failed;\n lines.push('');\n const parts: string[] = [];\n if (passed > 0) parts.push(this.style(GREEN, `${passed} passed`));\n if (failed > 0) parts.push(this.style(RED, `${failed} failed`));\n if (scored > 0) parts.push(this.style(YELLOW, `${scored} scored`));\n lines.push(` Eval runs: ${entries.length} ${this.style(DIM, `(${parts.join(', ')})`)}`);\n lines.push('');\n\n return lines.join('\\n');\n }\n\n private table(rows: Array<[string, string, string]>, indent = ''): string[] {\n if (rows.length === 0) return [];\n const nameWidth = Math.max(...rows.map(([name]) => stripAnsi(name).length));\n const scoreWidth = Math.max(5, ...rows.map(([, score]) => score.length));\n return rows.map(([name, score, mark]) => {\n const namePad = ' '.repeat(nameWidth - stripAnsi(name).length);\n return `${indent} ${name}${namePad} ${score.padStart(scoreWidth)} ${mark}`.trimEnd();\n });\n }\n\n private verdictBadge(verdict: MastraEvalMeta['verdict']): string {\n if (verdict === 'passed') return this.style(GREEN, '✓');\n if (verdict === 'failed') return this.style(RED, '✗');\n return this.style(YELLOW, '•');\n }\n\n private passMark(passed: boolean): string {\n return passed ? this.style(GREEN, '✓') : this.style(RED, '✗');\n }\n\n private style(code: string, text: string): string {\n return this.color ? `${code}${text}${RESET}` : text;\n }\n\n private print(output: string): void {\n process.stdout.write(`${output}\\n`);\n }\n}\n\nfunction formatScore(score: number): string {\n return Number.isInteger(score) ? score.toFixed(1) : score.toFixed(3).replace(/0+$/, '').replace(/\\.$/, '.0');\n}\n\nfunction formatThreshold(threshold: ThresholdConfig): string {\n if (typeof threshold === 'number') return `min ${threshold}`;\n return Object.entries(threshold)\n .map(([key, value]) => `${key} ${value}`)\n .join(', ');\n}\n\n// eslint-disable-next-line no-control-regex\nconst ANSI_PATTERN = /\\u001b\\[[0-9;]*m/g;\n\nfunction stripAnsi(text: string): string {\n return text.replace(ANSI_PATTERN, '');\n}\n"],"mappings":";;;;;;;;;AAgDA,SAAS,cAAc,QAA6B,SAAS,IAAI,MAA8B,CAAC,GAAG;CACjG,KAAK,MAAM,CAAC,IAAI,UAAU,OAAO,QAAQ,MAAM,GAAG;EAChD,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,OAAO;EACzC,IAAI,OAAO,UAAU,UACnB,IAAI,OAAO;OACN,IAAI,SAAS,OAAO,UAAU,UACnC,cAAc,OAAO,KAAK,GAAG;CAEjC;CACA,OAAO;AACT;;;;;AAMA,SAAgB,WAAW,QAAwC;CACjE,MAAM,OAAuB;EAC3B,QAAQ,cAAc,OAAO,MAAM;EACnC,YAAY,OAAO,QAAQ;CAC7B;CACA,IAAI,OAAO,YAAY,KAAA,GAAW,KAAK,UAAU,OAAO;CACxD,IAAI,OAAO,aAAa,KAAK,cAAc,OAAO,YAAY,KAAI,OAAM,EAAE,GAAG,EAAE,EAAE;CACjF,IAAI,OAAO,kBAAkB,KAAK,mBAAmB,OAAO,iBAAiB,KAAI,OAAM,EAAE,GAAG,EAAE,EAAE;CAChG,IAAI,OAAO,aAAa,KAAK,cAAc,OAAO;CAClD,OAAO;AACT;;;AChDA,IAAa,oBAAb,cAAuC,MAAM;CAC3C;CAEA,YAAY,SAAiB,QAAwB;EACnD,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,SAAS;CAChB;AACF;AAoBA,eAAe,wBAAwB,QAAuC;CAC5E,IAAI;EAGF,MAAM,QAAQ,MAFO,OAAO,UAAA,CAEC,YAAY,iBAAiB;EAC1D,IAAI,MAAM,MAAM;GACd,KAAK,KAAK,aAAa,WAAW,MAAM;GACxC;EACF;EAGA,MAAM,cAAc,MADA,OAAO,gBAAA,CACO,iBAAiB;EACnD,IAAI,YAAY,MACd,WAAW,KAAK,aAAa,WAAW,MAAM;CAElD,Q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;AAC7G;AAEA,SAAS,gBAAgB,WAAoC;CAC3D,IAAI,OAAO,cAAc,UAAU,OAAO,OAAO;CACjD,OAAO,OAAO,QAAQ,SAAS,CAAC,CAC7B,KAAK,CAAC,KAAK,WAAW,GAAG,IAAI,GAAG,OAAO,CAAC,CACxC,KAAK,IAAI;AACd;AAGA,MAAM,eAAe;AAErB,SAAS,UAAU,MAAsB;CACvC,OAAO,KAAK,QAAQ,cAAc,EAAE;AACtC"}
|
package/dist/vitest/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { n as registerEvalMatchers, t as evalMatchers } from "../matchers-
|
|
1
|
+
import { n as registerEvalMatchers, t as evalMatchers } from "../matchers-CVIJYGVp.js";
|
|
2
2
|
import { runEvals } from "@mastra/core/evals";
|
|
3
|
-
|
|
3
|
+
// src/vitest/meta.ts
|
|
4
4
|
/**
|
|
5
5
|
* Flattens the `scores` record of a `RunEvalsResult` into `Record<string, number>`.
|
|
6
6
|
* Categorized results (`agent`, `workflow`, `steps`, `trajectory`) are flattened
|
|
@@ -29,8 +29,7 @@ function toEvalMeta(result) {
|
|
|
29
29
|
if (result.turnResults) meta.turnResults = result.turnResults;
|
|
30
30
|
return meta;
|
|
31
31
|
}
|
|
32
|
-
|
|
33
|
-
//#region src/vitest/expect-evals.ts
|
|
32
|
+
// src/vitest/expect-evals.ts
|
|
34
33
|
/** Thrown by `expectEval`/`expectEvals` `.toPass()` when the pass rate is not met. */
|
|
35
34
|
var EvalPassRateError = class extends Error {
|
|
36
35
|
result;
|
|
@@ -119,8 +118,7 @@ function expectEval(options) {
|
|
|
119
118
|
data: [options.data]
|
|
120
119
|
});
|
|
121
120
|
}
|
|
122
|
-
|
|
123
|
-
//#region src/vitest/reporter.ts
|
|
121
|
+
// src/vitest/reporter.ts
|
|
124
122
|
const GREEN = "\x1B[32m";
|
|
125
123
|
const RED = "\x1B[31m";
|
|
126
124
|
const YELLOW = "\x1B[33m";
|
|
@@ -256,7 +254,6 @@ const ANSI_PATTERN = /\u001b\[[0-9;]*m/g;
|
|
|
256
254
|
function stripAnsi(text) {
|
|
257
255
|
return text.replace(ANSI_PATTERN, "");
|
|
258
256
|
}
|
|
259
|
-
//#endregion
|
|
260
257
|
export { EvalPassRateError, MastraEvalsReporter, evalMatchers, expectEval, expectEvals, registerEvalMatchers, toEvalMeta };
|
|
261
258
|
|
|
262
259
|
//# sourceMappingURL=index.js.map
|
package/dist/vitest/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/vitest/meta.ts","../../src/vitest/expect-evals.ts","../../src/vitest/reporter.ts"],"sourcesContent":["import type { EvalVerdict, GateResult, RunEvalsResult, ThresholdConfig, TurnResult } from '@mastra/core/evals';\n\n/** Per-threshold-scorer result, as reported in `RunEvalsResult.thresholdResults`. */\nexport type EvalThresholdResult = {\n id: string;\n passed: boolean;\n averageScore: number;\n threshold: ThresholdConfig;\n};\n\n/**\n * Serializable projection of a `RunEvalsResult` stored in `task.meta.mastraEval`.\n *\n * This is the contract between the test worker (which runs `runEvals`) and the\n * `MastraEvalsReporter` running in the main process. It intentionally excludes\n * raw agent/workflow payloads: `task.meta` is structured-cloned from worker to\n * main, so only lightweight, serializable data belongs here.\n */\nexport type MastraEvalMeta = {\n /**\n * Average score per scorer id across all data items. Categorized scorer\n * configs are flattened into dot-separated keys (e.g. `agent.my-scorer`,\n * `steps.step-1.my-scorer`).\n */\n scores: Record<string, number>;\n /** Number of data items evaluated. */\n totalItems: number;\n /** Present when gates or threshold-bearing scorers were provided. */\n verdict?: EvalVerdict;\n /** Per-gate results (averaged across all data items). */\n gateResults?: GateResult[];\n /** Per-threshold-scorer results (averaged across all data items). */\n thresholdResults?: EvalThresholdResult[];\n /** Per-turn assertion results, present when data items use `turns`. */\n turnResults?: TurnResult[];\n};\n\ndeclare module 'vitest' {\n interface TaskMeta {\n mastraEval?: MastraEvalMeta;\n }\n}\n\n/**\n * Flattens the `scores` record of a `RunEvalsResult` into `Record<string, number>`.\n * Categorized results (`agent`, `workflow`, `steps`, `trajectory`) are flattened\n * into dot-separated keys, e.g. `agent.my-scorer` or `steps.step-1.my-scorer`.\n */\nfunction flattenScores(scores: Record<string, any>, prefix = '', out: Record<string, number> = {}) {\n for (const [id, value] of Object.entries(scores)) {\n const key = prefix ? `${prefix}.${id}` : id;\n if (typeof value === 'number') {\n out[key] = value;\n } else if (value && typeof value === 'object') {\n flattenScores(value, key, out);\n }\n }\n return out;\n}\n\n/**\n * Projects a `RunEvalsResult` into the serializable `MastraEvalMeta` shape\n * stored in `task.meta.mastraEval`.\n */\nexport function toEvalMeta(result: RunEvalsResult): MastraEvalMeta {\n const meta: MastraEvalMeta = {\n scores: flattenScores(result.scores),\n totalItems: result.summary.totalItems,\n };\n if (result.verdict !== undefined) meta.verdict = result.verdict;\n if (result.gateResults) meta.gateResults = result.gateResults.map(g => ({ ...g }));\n if (result.thresholdResults) meta.thresholdResults = result.thresholdResults.map(t => ({ ...t }));\n if (result.turnResults) meta.turnResults = result.turnResults;\n return meta;\n}\n","import type { RunEvalsConfig, RunEvalsResult } from '@mastra/core/evals';\nimport { runEvals } from '@mastra/core/evals';\n\nimport { toEvalMeta } from './meta';\n\n/**\n * Options accepted by `expectEvals`: exactly the `runEvals` configuration\n * (target, data items, scorers/gates/thresholds, etc.).\n */\nexport type ExpectEvalsOptions = RunEvalsConfig;\n\n/** A single eval data item, as accepted by `runEvals` in its `data` array. */\nexport type EvalDataItem = RunEvalsConfig['data'][number];\n\n/**\n * Options accepted by `expectEval`: same as `expectEvals`, but `data` is a single item.\n * Distributes over the config union so each target keeps its own data-item contract\n * (e.g. `turns` stays agent-only).\n */\nexport type ExpectEvalOptions = RunEvalsConfig extends infer T\n ? T extends RunEvalsConfig\n ? Omit<T, 'data'> & { data: T['data'][number] }\n : never\n : never;\n\n/** Thrown by `expectEval`/`expectEvals` `.toPass()` when the pass rate is not met. */\nexport class EvalPassRateError extends Error {\n readonly result: RunEvalsResult;\n\n constructor(message: string, result: RunEvalsResult) {\n super(message);\n this.name = 'EvalPassRateError';\n this.result = result;\n }\n}\n\n/** Fluent assertion returned by `expectEval` and `expectEvals`. */\nexport type EvalScoresAssertion = {\n /**\n * Runs the eval and asserts it passes.\n *\n * - Every gate's pass rate across data items must be `>= minPassRate`\n * (gates score 1 on pass and 0 on failure, so the averaged gate score\n * is exactly the fraction of items that passed the gate).\n * - Every scorer threshold must pass (thresholds compare the average\n * score across items and are not relaxed by `minPassRate`).\n *\n * @param minPassRate Minimum per-gate pass rate in `[0, 1]`. Defaults to 1\n * (all items must pass every gate).\n * @returns The full `RunEvalsResult` for further assertions.\n */\n toPass(minPassRate?: number): Promise<RunEvalsResult>;\n};\n\nasync function attachMetaToCurrentTest(result: RunEvalsResult): Promise<void> {\n try {\n const vitest = await import('vitest');\n // Vitest >= 4.1\n const task = (vitest as any).TestRunner?.getCurrentTest?.();\n if (task?.meta) {\n task.meta.mastraEval = toEvalMeta(result);\n return;\n }\n // Vitest 3.x / < 4.1\n const suite = await import('vitest/suite');\n const legacyTask = (suite as any).getCurrentTest?.();\n if (legacyTask?.meta) {\n legacyTask.meta.mastraEval = toEvalMeta(result);\n }\n } catch {\n // Outside a Vitest test context — assertion still works, reporter meta is skipped.\n }\n}\n\nfunction assertPassRate(result: RunEvalsResult, minPassRate: number): void {\n if (!Number.isFinite(minPassRate) || minPassRate < 0 || minPassRate > 1) {\n throw new Error(`toPass(minPassRate): minPassRate must be within [0, 1], got ${minPassRate}`);\n }\n\n const lines: string[] = [];\n\n for (const gate of result.gateResults ?? []) {\n if (gate.score < minPassRate) {\n lines.push(` ✗ gate ${gate.id}: pass rate ${formatRate(gate.score)} < required ${formatRate(minPassRate)}`);\n }\n }\n\n for (const t of result.thresholdResults ?? []) {\n if (!t.passed) {\n lines.push(` ✗ threshold ${t.id}: average score ${t.averageScore} (threshold: ${JSON.stringify(t.threshold)})`);\n }\n }\n\n for (const turn of result.turnResults ?? []) {\n for (const gate of turn.gateResults ?? []) {\n if (gate.score < minPassRate) {\n lines.push(\n ` ✗ turn ${turn.index} gate ${gate.id}: pass rate ${formatRate(gate.score)} < required ${formatRate(minPassRate)}`,\n );\n }\n }\n for (const t of turn.thresholdResults ?? []) {\n if (!t.passed) {\n lines.push(\n ` ✗ turn ${turn.index} threshold ${t.id}: average score ${t.averageScore} (threshold: ${JSON.stringify(t.threshold)})`,\n );\n }\n }\n }\n\n if (lines.length > 0) {\n throw new EvalPassRateError(\n [`Eval did not pass (required pass rate: ${formatRate(minPassRate)}).`, ...lines].join('\\n'),\n result,\n );\n }\n}\n\nfunction formatRate(rate: number): string {\n return `${Math.round(rate * 1000) / 10}%`;\n}\n\nfunction makeAssertion(options: ExpectEvalsOptions): EvalScoresAssertion {\n return {\n async toPass(minPassRate = 1): Promise<RunEvalsResult> {\n const result = await runEvals(options as Parameters<typeof runEvals>[0]);\n await attachMetaToCurrentTest(result);\n assertPassRate(result, minPassRate);\n return result;\n },\n };\n}\n\n/**\n * Fluent eval assertion over a dataset, for use inside a regular `test()`.\n *\n * Runs `runEvals` with the given options when awaited and asserts the outcome.\n * The run's scores are attached to the current test's meta so\n * `MastraEvalsReporter` displays them in the runner output.\n *\n * Must be awaited — otherwise the test finishes before the eval runs.\n *\n * @example\n * test('capitals agent answers with the expected city', async () => {\n * await expectEvals({\n * target: capitalsAgent,\n * data: [{ input: 'What is the capital of France?', groundTruth: 'Paris' }],\n * gates: [containsGroundTruth],\n * scorers: [{ scorer: createKeywordCoverageScorer(), threshold: 0.4 }],\n * }).toPass(0.8);\n * });\n */\nexport function expectEvals(options: ExpectEvalsOptions): EvalScoresAssertion {\n return makeAssertion(options);\n}\n\n/**\n * Single-item variant of `expectEvals`: `data` is one item instead of an array.\n *\n * Use it with `test.each`/`it.each` for matrix testing when you want one test\n * (and one reporter entry) per data item instead of one per dataset run.\n *\n * @example\n * test.each([\n * { input: 'What is the capital of France?', groundTruth: 'Paris' },\n * { input: 'What is the capital of Japan?', groundTruth: 'Tokyo' },\n * ])('capitals agent: $input', async item => {\n * await expectEval({\n * target: capitalsAgent,\n * data: item,\n * gates: [containsGroundTruth],\n * }).toPass();\n * });\n */\nexport function expectEval(options: ExpectEvalOptions): EvalScoresAssertion {\n return makeAssertion({ ...options, data: [options.data] } as ExpectEvalsOptions);\n}\n","import type { ThresholdConfig } from '@mastra/core/evals';\nimport type { Reporter, TestCase, TestModule } from 'vitest/node';\n\nimport type { MastraEvalMeta } from './meta';\n\ntype EvalEntry = {\n fullName: string;\n meta: MastraEvalMeta;\n};\n\nconst GREEN = '\\u001b[32m';\nconst RED = '\\u001b[31m';\nconst YELLOW = '\\u001b[33m';\nconst BOLD = '\\u001b[1m';\nconst DIM = '\\u001b[2m';\nconst RESET = '\\u001b[0m';\n\nfunction supportsColor(): boolean {\n return process.stdout.isTTY === true && process.env.NO_COLOR === undefined;\n}\n\n/**\n * Vitest reporter that prints a per-test score table for every eval run\n * using `expectEval`/`expectEvals` (or any test that populates `task.meta.mastraEval`).\n *\n * Usage in `vitest.config.ts`:\n * test: { reporters: ['default', new MastraEvalsReporter()] }\n */\nexport class MastraEvalsReporter implements Reporter {\n private readonly color: boolean;\n\n constructor(options: { color?: boolean } = {}) {\n this.color = options.color ?? supportsColor();\n }\n\n onTestRunEnd(testModules: ReadonlyArray<TestModule>): void {\n const entries: EvalEntry[] = [];\n for (const module of testModules) {\n for (const test of module.children.allTests()) {\n const meta = ((test as TestCase).meta() as { mastraEval?: MastraEvalMeta }).mastraEval;\n if (meta) {\n entries.push({ fullName: test.fullName, meta });\n }\n }\n }\n\n if (entries.length === 0) return;\n\n this.print(this.render(entries));\n }\n\n /** Renders the score report as plain lines. Exposed for testing. */\n render(entries: EvalEntry[]): string {\n const lines: string[] = [];\n lines.push('');\n lines.push(this.style(BOLD, ' Mastra Evals '));\n\n for (const { fullName, meta } of entries) {\n lines.push('');\n lines.push(\n `${this.verdictBadge(meta.verdict)} ${this.style(BOLD, fullName)} ${this.style(DIM, `(${meta.totalItems} item${meta.totalItems === 1 ? '' : 's'})`)}`,\n );\n\n const rows: Array<[string, string, string]> = [];\n for (const gate of meta.gateResults ?? []) {\n rows.push([`${gate.id} ${this.style(DIM, '(gate)')}`, formatScore(gate.score), this.passMark(gate.passed)]);\n }\n for (const t of meta.thresholdResults ?? []) {\n rows.push([\n `${t.id} ${this.style(DIM, `(threshold: ${formatThreshold(t.threshold)})`)}`,\n formatScore(t.averageScore),\n this.passMark(t.passed),\n ]);\n }\n const covered = new Set([\n ...(meta.gateResults ?? []).map(g => g.id),\n ...(meta.thresholdResults ?? []).map(t => t.id),\n ]);\n for (const [id, score] of Object.entries(meta.scores)) {\n if (covered.has(id)) continue;\n rows.push([id, formatScore(score), '']);\n }\n\n lines.push(...this.table(rows));\n\n for (const turn of meta.turnResults ?? []) {\n const turnRows: Array<[string, string, string]> = [];\n for (const gate of turn.gateResults ?? []) {\n turnRows.push([\n `${gate.id} ${this.style(DIM, '(gate)')}`,\n formatScore(gate.score),\n this.passMark(gate.passed),\n ]);\n }\n for (const t of turn.thresholdResults ?? []) {\n turnRows.push([\n `${t.id} ${this.style(DIM, `(threshold: ${formatThreshold(t.threshold)})`)}`,\n formatScore(t.averageScore),\n this.passMark(t.passed),\n ]);\n }\n const turnCovered = new Set([\n ...(turn.gateResults ?? []).map(g => g.id),\n ...(turn.thresholdResults ?? []).map(t => t.id),\n ]);\n for (const [id, score] of Object.entries(turn.scores ?? {})) {\n if (turnCovered.has(id)) continue;\n turnRows.push([id, formatScore(score), '']);\n }\n if (turnRows.length === 0) continue;\n lines.push(` ${this.style(DIM, `turn ${turn.index}`)}`);\n lines.push(...this.table(turnRows, ' '));\n }\n }\n\n const withVerdict = entries.filter(e => e.meta.verdict !== undefined);\n const passed = withVerdict.filter(e => e.meta.verdict === 'passed').length;\n const failed = withVerdict.filter(e => e.meta.verdict === 'failed').length;\n const scored = entries.length - passed - failed;\n lines.push('');\n const parts: string[] = [];\n if (passed > 0) parts.push(this.style(GREEN, `${passed} passed`));\n if (failed > 0) parts.push(this.style(RED, `${failed} failed`));\n if (scored > 0) parts.push(this.style(YELLOW, `${scored} scored`));\n lines.push(` Eval runs: ${entries.length} ${this.style(DIM, `(${parts.join(', ')})`)}`);\n lines.push('');\n\n return lines.join('\\n');\n }\n\n private table(rows: Array<[string, string, string]>, indent = ''): string[] {\n if (rows.length === 0) return [];\n const nameWidth = Math.max(...rows.map(([name]) => stripAnsi(name).length));\n const scoreWidth = Math.max(5, ...rows.map(([, score]) => score.length));\n return rows.map(([name, score, mark]) => {\n const namePad = ' '.repeat(nameWidth - stripAnsi(name).length);\n return `${indent} ${name}${namePad} ${score.padStart(scoreWidth)} ${mark}`.trimEnd();\n });\n }\n\n private verdictBadge(verdict: MastraEvalMeta['verdict']): string {\n if (verdict === 'passed') return this.style(GREEN, '✓');\n if (verdict === 'failed') return this.style(RED, '✗');\n return this.style(YELLOW, '•');\n }\n\n private passMark(passed: boolean): string {\n return passed ? this.style(GREEN, '✓') : this.style(RED, '✗');\n }\n\n private style(code: string, text: string): string {\n return this.color ? `${code}${text}${RESET}` : text;\n }\n\n private print(output: string): void {\n process.stdout.write(`${output}\\n`);\n }\n}\n\nfunction formatScore(score: number): string {\n return Number.isInteger(score) ? score.toFixed(1) : score.toFixed(3).replace(/0+$/, '').replace(/\\.$/, '.0');\n}\n\nfunction formatThreshold(threshold: ThresholdConfig): string {\n if (typeof threshold === 'number') return `min ${threshold}`;\n return Object.entries(threshold)\n .map(([key, value]) => `${key} ${value}`)\n .join(', ');\n}\n\n// eslint-disable-next-line no-control-regex\nconst ANSI_PATTERN = /\\u001b\\[[0-9;]*m/g;\n\nfunction stripAnsi(text: string): string {\n return text.replace(ANSI_PATTERN, '');\n}\n"],"mappings":";;;;;;;;AAgDA,SAAS,cAAc,QAA6B,SAAS,IAAI,MAA8B,CAAC,GAAG;CACjG,KAAK,MAAM,CAAC,IAAI,UAAU,OAAO,QAAQ,MAAM,GAAG;EAChD,MAAM,MAAM,SAAS,GAAG,OA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|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/vitest/meta.ts","../../src/vitest/expect-evals.ts","../../src/vitest/reporter.ts"],"sourcesContent":["import type { EvalVerdict, GateResult, RunEvalsResult, ThresholdConfig, TurnResult } from '@mastra/core/evals';\n\n/** Per-threshold-scorer result, as reported in `RunEvalsResult.thresholdResults`. */\nexport type EvalThresholdResult = {\n id: string;\n passed: boolean;\n averageScore: number;\n threshold: ThresholdConfig;\n};\n\n/**\n * Serializable projection of a `RunEvalsResult` stored in `task.meta.mastraEval`.\n *\n * This is the contract between the test worker (which runs `runEvals`) and the\n * `MastraEvalsReporter` running in the main process. It intentionally excludes\n * raw agent/workflow payloads: `task.meta` is structured-cloned from worker to\n * main, so only lightweight, serializable data belongs here.\n */\nexport type MastraEvalMeta = {\n /**\n * Average score per scorer id across all data items. Categorized scorer\n * configs are flattened into dot-separated keys (e.g. `agent.my-scorer`,\n * `steps.step-1.my-scorer`).\n */\n scores: Record<string, number>;\n /** Number of data items evaluated. */\n totalItems: number;\n /** Present when gates or threshold-bearing scorers were provided. */\n verdict?: EvalVerdict;\n /** Per-gate results (averaged across all data items). */\n gateResults?: GateResult[];\n /** Per-threshold-scorer results (averaged across all data items). */\n thresholdResults?: EvalThresholdResult[];\n /** Per-turn assertion results, present when data items use `turns`. */\n turnResults?: TurnResult[];\n};\n\ndeclare module 'vitest' {\n interface TaskMeta {\n mastraEval?: MastraEvalMeta;\n }\n}\n\n/**\n * Flattens the `scores` record of a `RunEvalsResult` into `Record<string, number>`.\n * Categorized results (`agent`, `workflow`, `steps`, `trajectory`) are flattened\n * into dot-separated keys, e.g. `agent.my-scorer` or `steps.step-1.my-scorer`.\n */\nfunction flattenScores(scores: Record<string, any>, prefix = '', out: Record<string, number> = {}) {\n for (const [id, value] of Object.entries(scores)) {\n const key = prefix ? `${prefix}.${id}` : id;\n if (typeof value === 'number') {\n out[key] = value;\n } else if (value && typeof value === 'object') {\n flattenScores(value, key, out);\n }\n }\n return out;\n}\n\n/**\n * Projects a `RunEvalsResult` into the serializable `MastraEvalMeta` shape\n * stored in `task.meta.mastraEval`.\n */\nexport function toEvalMeta(result: RunEvalsResult): MastraEvalMeta {\n const meta: MastraEvalMeta = {\n scores: flattenScores(result.scores),\n totalItems: result.summary.totalItems,\n };\n if (result.verdict !== undefined) meta.verdict = result.verdict;\n if (result.gateResults) meta.gateResults = result.gateResults.map(g => ({ ...g }));\n if (result.thresholdResults) meta.thresholdResults = result.thresholdResults.map(t => ({ ...t }));\n if (result.turnResults) meta.turnResults = result.turnResults;\n return meta;\n}\n","import type { RunEvalsConfig, RunEvalsResult } from '@mastra/core/evals';\nimport { runEvals } from '@mastra/core/evals';\n\nimport { toEvalMeta } from './meta';\n\n/**\n * Options accepted by `expectEvals`: exactly the `runEvals` configuration\n * (target, data items, scorers/gates/thresholds, etc.).\n */\nexport type ExpectEvalsOptions = RunEvalsConfig;\n\n/** A single eval data item, as accepted by `runEvals` in its `data` array. */\nexport type EvalDataItem = RunEvalsConfig['data'][number];\n\n/**\n * Options accepted by `expectEval`: same as `expectEvals`, but `data` is a single item.\n * Distributes over the config union so each target keeps its own data-item contract\n * (e.g. `turns` stays agent-only).\n */\nexport type ExpectEvalOptions = RunEvalsConfig extends infer T\n ? T extends RunEvalsConfig\n ? Omit<T, 'data'> & { data: T['data'][number] }\n : never\n : never;\n\n/** Thrown by `expectEval`/`expectEvals` `.toPass()` when the pass rate is not met. */\nexport class EvalPassRateError extends Error {\n readonly result: RunEvalsResult;\n\n constructor(message: string, result: RunEvalsResult) {\n super(message);\n this.name = 'EvalPassRateError';\n this.result = result;\n }\n}\n\n/** Fluent assertion returned by `expectEval` and `expectEvals`. */\nexport type EvalScoresAssertion = {\n /**\n * Runs the eval and asserts it passes.\n *\n * - Every gate's pass rate across data items must be `>= minPassRate`\n * (gates score 1 on pass and 0 on failure, so the averaged gate score\n * is exactly the fraction of items that passed the gate).\n * - Every scorer threshold must pass (thresholds compare the average\n * score across items and are not relaxed by `minPassRate`).\n *\n * @param minPassRate Minimum per-gate pass rate in `[0, 1]`. Defaults to 1\n * (all items must pass every gate).\n * @returns The full `RunEvalsResult` for further assertions.\n */\n toPass(minPassRate?: number): Promise<RunEvalsResult>;\n};\n\nasync function attachMetaToCurrentTest(result: RunEvalsResult): Promise<void> {\n try {\n const vitest = await import('vitest');\n // Vitest >= 4.1\n const task = (vitest as any).TestRunner?.getCurrentTest?.();\n if (task?.meta) {\n task.meta.mastraEval = toEvalMeta(result);\n return;\n }\n // Vitest 3.x / < 4.1\n const suite = await import('vitest/suite');\n const legacyTask = (suite as any).getCurrentTest?.();\n if (legacyTask?.meta) {\n legacyTask.meta.mastraEval = toEvalMeta(result);\n }\n } catch {\n // Outside a Vitest test context — assertion still works, reporter meta is skipped.\n }\n}\n\nfunction assertPassRate(result: RunEvalsResult, minPassRate: number): void {\n if (!Number.isFinite(minPassRate) || minPassRate < 0 || minPassRate > 1) {\n throw new Error(`toPass(minPassRate): minPassRate must be within [0, 1], got ${minPassRate}`);\n }\n\n const lines: string[] = [];\n\n for (const gate of result.gateResults ?? []) {\n if (gate.score < minPassRate) {\n lines.push(` ✗ gate ${gate.id}: pass rate ${formatRate(gate.score)} < required ${formatRate(minPassRate)}`);\n }\n }\n\n for (const t of result.thresholdResults ?? []) {\n if (!t.passed) {\n lines.push(` ✗ threshold ${t.id}: average score ${t.averageScore} (threshold: ${JSON.stringify(t.threshold)})`);\n }\n }\n\n for (const turn of result.turnResults ?? []) {\n for (const gate of turn.gateResults ?? []) {\n if (gate.score < minPassRate) {\n lines.push(\n ` ✗ turn ${turn.index} gate ${gate.id}: pass rate ${formatRate(gate.score)} < required ${formatRate(minPassRate)}`,\n );\n }\n }\n for (const t of turn.thresholdResults ?? []) {\n if (!t.passed) {\n lines.push(\n ` ✗ turn ${turn.index} threshold ${t.id}: average score ${t.averageScore} (threshold: ${JSON.stringify(t.threshold)})`,\n );\n }\n }\n }\n\n if (lines.length > 0) {\n throw new EvalPassRateError(\n [`Eval did not pass (required pass rate: ${formatRate(minPassRate)}).`, ...lines].join('\\n'),\n result,\n );\n }\n}\n\nfunction formatRate(rate: number): string {\n return `${Math.round(rate * 1000) / 10}%`;\n}\n\nfunction makeAssertion(options: ExpectEvalsOptions): EvalScoresAssertion {\n return {\n async toPass(minPassRate = 1): Promise<RunEvalsResult> {\n const result = await runEvals(options as Parameters<typeof runEvals>[0]);\n await attachMetaToCurrentTest(result);\n assertPassRate(result, minPassRate);\n return result;\n },\n };\n}\n\n/**\n * Fluent eval assertion over a dataset, for use inside a regular `test()`.\n *\n * Runs `runEvals` with the given options when awaited and asserts the outcome.\n * The run's scores are attached to the current test's meta so\n * `MastraEvalsReporter` displays them in the runner output.\n *\n * Must be awaited — otherwise the test finishes before the eval runs.\n *\n * @example\n * test('capitals agent answers with the expected city', async () => {\n * await expectEvals({\n * target: capitalsAgent,\n * data: [{ input: 'What is the capital of France?', groundTruth: 'Paris' }],\n * gates: [containsGroundTruth],\n * scorers: [{ scorer: createKeywordCoverageScorer(), threshold: 0.4 }],\n * }).toPass(0.8);\n * });\n */\nexport function expectEvals(options: ExpectEvalsOptions): EvalScoresAssertion {\n return makeAssertion(options);\n}\n\n/**\n * Single-item variant of `expectEvals`: `data` is one item instead of an array.\n *\n * Use it with `test.each`/`it.each` for matrix testing when you want one test\n * (and one reporter entry) per data item instead of one per dataset run.\n *\n * @example\n * test.each([\n * { input: 'What is the capital of France?', groundTruth: 'Paris' },\n * { input: 'What is the capital of Japan?', groundTruth: 'Tokyo' },\n * ])('capitals agent: $input', async item => {\n * await expectEval({\n * target: capitalsAgent,\n * data: item,\n * gates: [containsGroundTruth],\n * }).toPass();\n * });\n */\nexport function expectEval(options: ExpectEvalOptions): EvalScoresAssertion {\n return makeAssertion({ ...options, data: [options.data] } as ExpectEvalsOptions);\n}\n","import type { ThresholdConfig } from '@mastra/core/evals';\nimport type { Reporter, TestCase, TestModule } from 'vitest/node';\n\nimport type { MastraEvalMeta } from './meta';\n\ntype EvalEntry = {\n fullName: string;\n meta: MastraEvalMeta;\n};\n\nconst GREEN = '\\u001b[32m';\nconst RED = '\\u001b[31m';\nconst YELLOW = '\\u001b[33m';\nconst BOLD = '\\u001b[1m';\nconst DIM = '\\u001b[2m';\nconst RESET = '\\u001b[0m';\n\nfunction supportsColor(): boolean {\n return process.stdout.isTTY === true && process.env.NO_COLOR === undefined;\n}\n\n/**\n * Vitest reporter that prints a per-test score table for every eval run\n * using `expectEval`/`expectEvals` (or any test that populates `task.meta.mastraEval`).\n *\n * Usage in `vitest.config.ts`:\n * test: { reporters: ['default', new MastraEvalsReporter()] }\n */\nexport class MastraEvalsReporter implements Reporter {\n private readonly color: boolean;\n\n constructor(options: { color?: boolean } = {}) {\n this.color = options.color ?? supportsColor();\n }\n\n onTestRunEnd(testModules: ReadonlyArray<TestModule>): void {\n const entries: EvalEntry[] = [];\n for (const module of testModules) {\n for (const test of module.children.allTests()) {\n const meta = ((test as TestCase).meta() as { mastraEval?: MastraEvalMeta }).mastraEval;\n if (meta) {\n entries.push({ fullName: test.fullName, meta });\n }\n }\n }\n\n if (entries.length === 0) return;\n\n this.print(this.render(entries));\n }\n\n /** Renders the score report as plain lines. Exposed for testing. */\n render(entries: EvalEntry[]): string {\n const lines: string[] = [];\n lines.push('');\n lines.push(this.style(BOLD, ' Mastra Evals '));\n\n for (const { fullName, meta } of entries) {\n lines.push('');\n lines.push(\n `${this.verdictBadge(meta.verdict)} ${this.style(BOLD, fullName)} ${this.style(DIM, `(${meta.totalItems} item${meta.totalItems === 1 ? '' : 's'})`)}`,\n );\n\n const rows: Array<[string, string, string]> = [];\n for (const gate of meta.gateResults ?? []) {\n rows.push([`${gate.id} ${this.style(DIM, '(gate)')}`, formatScore(gate.score), this.passMark(gate.passed)]);\n }\n for (const t of meta.thresholdResults ?? []) {\n rows.push([\n `${t.id} ${this.style(DIM, `(threshold: ${formatThreshold(t.threshold)})`)}`,\n formatScore(t.averageScore),\n this.passMark(t.passed),\n ]);\n }\n const covered = new Set([\n ...(meta.gateResults ?? []).map(g => g.id),\n ...(meta.thresholdResults ?? []).map(t => t.id),\n ]);\n for (const [id, score] of Object.entries(meta.scores)) {\n if (covered.has(id)) continue;\n rows.push([id, formatScore(score), '']);\n }\n\n lines.push(...this.table(rows));\n\n for (const turn of meta.turnResults ?? []) {\n const turnRows: Array<[string, string, string]> = [];\n for (const gate of turn.gateResults ?? []) {\n turnRows.push([\n `${gate.id} ${this.style(DIM, '(gate)')}`,\n formatScore(gate.score),\n this.passMark(gate.passed),\n ]);\n }\n for (const t of turn.thresholdResults ?? []) {\n turnRows.push([\n `${t.id} ${this.style(DIM, `(threshold: ${formatThreshold(t.threshold)})`)}`,\n formatScore(t.averageScore),\n this.passMark(t.passed),\n ]);\n }\n const turnCovered = new Set([\n ...(turn.gateResults ?? []).map(g => g.id),\n ...(turn.thresholdResults ?? []).map(t => t.id),\n ]);\n for (const [id, score] of Object.entries(turn.scores ?? {})) {\n if (turnCovered.has(id)) continue;\n turnRows.push([id, formatScore(score), '']);\n }\n if (turnRows.length === 0) continue;\n lines.push(` ${this.style(DIM, `turn ${turn.index}`)}`);\n lines.push(...this.table(turnRows, ' '));\n }\n }\n\n const withVerdict = entries.filter(e => e.meta.verdict !== undefined);\n const passed = withVerdict.filter(e => e.meta.verdict === 'passed').length;\n const failed = withVerdict.filter(e => e.meta.verdict === 'failed').length;\n const scored = entries.length - passed - failed;\n lines.push('');\n const parts: string[] = [];\n if (passed > 0) parts.push(this.style(GREEN, `${passed} passed`));\n if (failed > 0) parts.push(this.style(RED, `${failed} failed`));\n if (scored > 0) parts.push(this.style(YELLOW, `${scored} scored`));\n lines.push(` Eval runs: ${entries.length} ${this.style(DIM, `(${parts.join(', ')})`)}`);\n lines.push('');\n\n return lines.join('\\n');\n }\n\n private table(rows: Array<[string, string, string]>, indent = ''): string[] {\n if (rows.length === 0) return [];\n const nameWidth = Math.max(...rows.map(([name]) => stripAnsi(name).length));\n const scoreWidth = Math.max(5, ...rows.map(([, score]) => score.length));\n return rows.map(([name, score, mark]) => {\n const namePad = ' '.repeat(nameWidth - stripAnsi(name).length);\n return `${indent} ${name}${namePad} ${score.padStart(scoreWidth)} ${mark}`.trimEnd();\n });\n }\n\n private verdictBadge(verdict: MastraEvalMeta['verdict']): string {\n if (verdict === 'passed') return this.style(GREEN, '✓');\n if (verdict === 'failed') return this.style(RED, '✗');\n return this.style(YELLOW, '•');\n }\n\n private passMark(passed: boolean): string {\n return passed ? this.style(GREEN, '✓') : this.style(RED, '✗');\n }\n\n private style(code: string, text: string): string {\n return this.color ? `${code}${text}${RESET}` : text;\n }\n\n private print(output: string): void {\n process.stdout.write(`${output}\\n`);\n }\n}\n\nfunction formatScore(score: number): string {\n return Number.isInteger(score) ? score.toFixed(1) : score.toFixed(3).replace(/0+$/, '').replace(/\\.$/, '.0');\n}\n\nfunction formatThreshold(threshold: ThresholdConfig): string {\n if (typeof threshold === 'number') return `min ${threshold}`;\n return Object.entries(threshold)\n .map(([key, value]) => `${key} ${value}`)\n .join(', ');\n}\n\n// eslint-disable-next-line no-control-regex\nconst ANSI_PATTERN = /\\u001b\\[[0-9;]*m/g;\n\nfunction stripAnsi(text: string): string {\n return text.replace(ANSI_PATTERN, '');\n}\n"],"mappings":";;;;;;;;AAgDA,SAAS,cAAc,QAA6B,SAAS,IAAI,MAA8B,CAAC,GAAG;CACjG,KAAK,MAAM,CAAC,IAAI,UAAU,OAAO,QAAQ,MAAM,GAAG;EAChD,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,OAAO;EACzC,IAAI,OAAO,UAAU,UACnB,IAAI,OAAO;OACN,IAAI,SAAS,OAAO,UAAU,UACnC,cAAc,OAAO,KAAK,GAAG;CAEjC;CACA,OAAO;AACT;;;;;AAMA,SAAgB,WAAW,QAAwC;CACjE,MAAM,OAAuB;EAC3B,QAAQ,cAAc,OAAO,MAAM;EACnC,YAAY,OAAO,QAAQ;CAC7B;CACA,IAAI,OAAO,YAAY,KAAA,GAAW,KAAK,UAAU,OAAO;CACxD,IA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;EACzF,CAAC;CACH;CAEA,aAAqB,SAA4C;EAC/D,IAAI,YAAY,UAAU,OAAO,KAAK,MAAM,OAAO,GAAG;EACtD,IAAI,YAAY,UAAU,OAAO,KAAK,MAAM,KAAK,GAAG;EACpD,OAAO,KAAK,MAAM,QAAQ,GAAG;CAC/B;CAEA,SAAiB,QAAyB;EACxC,OAAO,SAAS,KAAK,MAAM,OAAO,GAAG,IAAI,KAAK,MAAM,KAAK,GAAG;CAC9D;CAEA,MAAc,MAAc,MAAsB;EAChD,OAAO,KAAK,QAAQ,GAAG,OAAO,OAAO,UAAU;CACjD;CAEA,MAAc,QAAsB;EAClC,QAAQ,OAAO,MAAM,GAAG,OAAO,GAAG;CACpC;AACF;AAEA,SAAS,YAAY,OAAuB;CAC1C,OAAO,OAAO,UAAU,KAAK,IAAI,MAAM,QAAQ,CAAC,IAAI,MAAM,QAAQ,CAAC,CAAC,CAAC,QAAQ,OAAO,EAAE,CAAC,CAAC,QAAQ,OAAO,IAAI;AAC7G;AAEA,SAAS,gBAAgB,WAAoC;CAC3D,IAAI,OAAO,cAAc,UAAU,OAAO,OAAO;CACjD,OAAO,OAAO,QAAQ,SAAS,CAAC,CAC7B,KAAK,CAAC,KAAK,WAAW,GAAG,IAAI,GAAG,OAAO,CAAC,CACxC,KAAK,IAAI;AACd;AAGA,MAAM,eAAe;AAErB,SAAS,UAAU,MAAsB;CACvC,OAAO,KAAK,QAAQ,cAAc,EAAE;AACtC"}
|
package/dist/vitest/setup.cjs
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
// src/vitest/setup.ts
|
|
2
2
|
/**
|
|
3
3
|
* Vitest setup file that auto-registers the Mastra eval matchers.
|
|
4
4
|
*
|
|
5
5
|
* Usage in `vitest.config.ts`:
|
|
6
6
|
* test: { setupFiles: ['@mastra/evals/vitest/setup'] }
|
|
7
7
|
*/
|
|
8
|
-
require("../matchers-
|
|
9
|
-
//#endregion
|
|
8
|
+
require("../matchers-CL0xCK25.cjs").registerEvalMatchers();
|
|
10
9
|
|
|
11
10
|
//# sourceMappingURL=setup.cjs.map
|
package/dist/vitest/setup.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as registerEvalMatchers } from "../matchers-
|
|
2
|
-
|
|
1
|
+
import { n as registerEvalMatchers } from "../matchers-CVIJYGVp.js";
|
|
2
|
+
// src/vitest/setup.ts
|
|
3
3
|
/**
|
|
4
4
|
* Vitest setup file that auto-registers the Mastra eval matchers.
|
|
5
5
|
*
|
|
@@ -7,7 +7,6 @@ import { n as registerEvalMatchers } from "../matchers-D3c6f71B.js";
|
|
|
7
7
|
* test: { setupFiles: ['@mastra/evals/vitest/setup'] }
|
|
8
8
|
*/
|
|
9
9
|
registerEvalMatchers();
|
|
10
|
-
//#endregion
|
|
11
10
|
export {};
|
|
12
11
|
|
|
13
12
|
//# sourceMappingURL=setup.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/evals",
|
|
3
|
-
"version": "1.10.
|
|
3
|
+
"version": "1.10.9-alpha.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"author": "",
|
|
85
85
|
"license": "Apache-2.0",
|
|
86
86
|
"dependencies": {
|
|
87
|
-
"compromise": "^14.
|
|
87
|
+
"compromise": "^14.19.0",
|
|
88
88
|
"keyword-extractor": "^0.0.28",
|
|
89
89
|
"sentiment": "^5.0.2",
|
|
90
90
|
"string-similarity": "^4.0.4"
|
|
@@ -101,23 +101,23 @@
|
|
|
101
101
|
"devDependencies": {
|
|
102
102
|
"@ai-sdk/openai": "^1.3.24",
|
|
103
103
|
"@ai-sdk/openai-v6": "npm:@ai-sdk/openai@3.0.130",
|
|
104
|
-
"@copilotkit/aimock": "^1.
|
|
104
|
+
"@copilotkit/aimock": "^1.46.0",
|
|
105
105
|
"@types/sentiment": "^5.0.4",
|
|
106
106
|
"@types/string-similarity": "^4.0.2",
|
|
107
|
-
"@vitest/coverage-v8": "4.1.
|
|
108
|
-
"@vitest/ui": "4.1.
|
|
107
|
+
"@vitest/coverage-v8": "4.1.12",
|
|
108
|
+
"@vitest/ui": "4.1.12",
|
|
109
109
|
"dotenv": "^17.4.2",
|
|
110
|
-
"tsdown": "0.
|
|
111
|
-
"tsx": "^4.23.
|
|
110
|
+
"tsdown": "0.23.1",
|
|
111
|
+
"tsx": "^4.23.15",
|
|
112
112
|
"typescript": "^7.0.2",
|
|
113
|
-
"vitest": "4.1.
|
|
113
|
+
"vitest": "4.1.12",
|
|
114
114
|
"zod": "^4.6.7",
|
|
115
|
-
"@internal/llm-recorder": "0.0.81",
|
|
116
115
|
"@internal/ai-sdk-v5": "0.0.92",
|
|
116
|
+
"@internal/llm-recorder": "0.0.81",
|
|
117
117
|
"@internal/test-utils": "0.0.81",
|
|
118
|
-
"@internal/lint": "0.0.145",
|
|
119
118
|
"@internal/types-builder": "0.0.120",
|
|
120
|
-
"@
|
|
119
|
+
"@internal/lint": "0.0.145",
|
|
120
|
+
"@mastra/core": "1.80.0-alpha.4"
|
|
121
121
|
},
|
|
122
122
|
"engines": {
|
|
123
123
|
"node": ">=22.13.0"
|