@mastra/evals 1.10.10 → 1.10.11-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.
@@ -3,7 +3,7 @@ name: mastra-evals
3
3
  description: Documentation for @mastra/evals. Use when working with @mastra/evals APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/evals"
6
- version: "1.10.10"
6
+ version: "1.10.11-alpha.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.10.10",
2
+ "version": "1.10.11-alpha.0",
3
3
  "package": "@mastra/evals",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -6,7 +6,7 @@
6
6
 
7
7
  The `@mastra/evals/vitest` module integrates [`runEvals`](https://mastra.ai/reference/evals/run-evals) with [Vitest](https://vitest.dev/) so evaluations behave like regular tests. Fluent assertions fail the test when the eval doesn't pass, and a reporter prints a score table in the runner output.
8
8
 
9
- To use it, install `@mastra/evals` and `vitest` (version 3 or 4):
9
+ To use it, install `@mastra/evals` and `vitest` (version 3, 4, or 5):
10
10
 
11
11
  ```bash
12
12
  npm install @mastra/evals vitest
@@ -1 +1 @@
1
- {"version":3,"file":"matchers-CL0xCK25.cjs","names":[],"sources":["../src/vitest/matchers.ts"],"sourcesContent":["import type { EvalVerdict, RunEvalsResult } from '@mastra/core/evals';\nimport { expect } from 'vitest';\n\n/**\n * Custom Vitest matchers operating on a `RunEvalsResult` (the return value of\n * `runEvals`). Registered via `registerEvalMatchers()` or by adding\n * `@mastra/evals/vitest/setup` to `setupFiles`.\n */\nexport interface EvalMatchers<R = unknown> {\n /** Asserts the run's verdict (`passed`, `scored`, or `failed`). */\n toHaveVerdict(verdict: EvalVerdict): R;\n /** Asserts the average score of a scorer is strictly above `min`. Supports dot-paths for categorized configs (e.g. `agent.my-scorer`). */\n toHaveScoreAbove(scorerName: string, min: number): R;\n /** Asserts the average score of a scorer is strictly below `max`. Supports dot-paths for categorized configs (e.g. `agent.my-scorer`). */\n toHaveScoreBelow(scorerName: string, max: number): R;\n /** Asserts that all gates passed (fails when no gates were configured). */\n toPassGates(): R;\n /** Asserts that all scorer thresholds passed (fails when no thresholds were configured). */\n toPassThresholds(): R;\n}\n\ndeclare module 'vitest' {\n interface Assertion<T = any> extends EvalMatchers<T> {}\n interface AsymmetricMatchersContaining extends EvalMatchers {}\n}\n\nfunction isRunEvalsResult(value: unknown): value is RunEvalsResult {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'scores' in value &&\n 'summary' in value &&\n typeof (value as RunEvalsResult).scores === 'object' &&\n (value as RunEvalsResult).scores !== null\n );\n}\n\nfunction invalidReceived(matcherName: string, received: unknown) {\n return {\n pass: false,\n message: () =>\n `${matcherName} expected a RunEvalsResult (the return value of runEvals), received: ${JSON.stringify(received)}`,\n };\n}\n\nfunction lookupScore(scores: Record<string, any>, scorerName: string): number | undefined {\n const direct = scorerName.split('.').reduce<any>((acc, key) => (acc == null ? undefined : acc[key]), scores);\n return typeof direct === 'number' ? direct : undefined;\n}\n\nfunction availableScorers(scores: Record<string, any>, prefix = ''): string[] {\n const names: string[] = [];\n for (const [key, value] of Object.entries(scores)) {\n const path = prefix ? `${prefix}.${key}` : key;\n if (typeof value === 'number') {\n names.push(path);\n } else if (value && typeof value === 'object') {\n names.push(...availableScorers(value, path));\n }\n }\n return names;\n}\n\nexport const evalMatchers = {\n toHaveVerdict(received: unknown, verdict: EvalVerdict) {\n if (!isRunEvalsResult(received)) return invalidReceived('toHaveVerdict', received);\n const actual = received.verdict;\n return {\n pass: actual === verdict,\n message: () =>\n actual === verdict\n ? `expected verdict not to be \"${verdict}\"`\n : `expected verdict \"${verdict}\", got ${actual === undefined ? 'no verdict (no gates or thresholds configured)' : `\"${actual}\"`}`,\n };\n },\n\n toHaveScoreAbove(received: unknown, scorerName: string, min: number) {\n if (!isRunEvalsResult(received)) return invalidReceived('toHaveScoreAbove', received);\n const score = lookupScore(received.scores, scorerName);\n if (score === undefined) {\n return {\n pass: false,\n message: () =>\n `scorer \"${scorerName}\" not found in result. Available scorers: ${availableScorers(received.scores).join(', ') || '(none)'}`,\n };\n }\n return {\n pass: score > min,\n message: () =>\n score > min\n ? `expected score of \"${scorerName}\" (${score}) not to be above ${min}`\n : `expected score of \"${scorerName}\" (${score}) to be above ${min}`,\n };\n },\n\n toHaveScoreBelow(received: unknown, scorerName: string, max: number) {\n if (!isRunEvalsResult(received)) return invalidReceived('toHaveScoreBelow', received);\n const score = lookupScore(received.scores, scorerName);\n if (score === undefined) {\n return {\n pass: false,\n message: () =>\n `scorer \"${scorerName}\" not found in result. Available scorers: ${availableScorers(received.scores).join(', ') || '(none)'}`,\n };\n }\n return {\n pass: score < max,\n message: () =>\n score < max\n ? `expected score of \"${scorerName}\" (${score}) not to be below ${max}`\n : `expected score of \"${scorerName}\" (${score}) to be below ${max}`,\n };\n },\n\n toPassGates(received: unknown) {\n if (!isRunEvalsResult(received)) return invalidReceived('toPassGates', received);\n const gates = [\n ...(received.gateResults ?? []),\n ...(received.turnResults ?? []).flatMap(\n turn => turn.gateResults?.map(g => ({ ...g, id: `turn ${turn.index} ${g.id}` })) ?? [],\n ),\n ];\n if (gates.length === 0) {\n return {\n pass: false,\n message: () => `no gates were configured on this eval run`,\n };\n }\n const failed = gates.filter(g => !g.passed);\n return {\n pass: failed.length === 0,\n message: () =>\n failed.length === 0\n ? `expected at least one gate to fail, but all ${gates.length} passed`\n : `expected all gates to pass, but ${failed.length} failed:\\n${failed.map(g => ` ✗ ${g.id} (score: ${g.score})`).join('\\n')}`,\n };\n },\n\n toPassThresholds(received: unknown) {\n if (!isRunEvalsResult(received)) return invalidReceived('toPassThresholds', received);\n const thresholds = [\n ...(received.thresholdResults ?? []),\n ...(received.turnResults ?? []).flatMap(\n turn => turn.thresholdResults?.map(t => ({ ...t, id: `turn ${turn.index} ${t.id}` })) ?? [],\n ),\n ];\n if (thresholds.length === 0) {\n return {\n pass: false,\n message: () => `no scorer thresholds were configured on this eval run`,\n };\n }\n const failed = thresholds.filter(t => !t.passed);\n return {\n pass: failed.length === 0,\n message: () =>\n failed.length === 0\n ? `expected at least one threshold to fail, but all ${thresholds.length} passed`\n : `expected all thresholds to pass, but ${failed.length} failed:\\n${failed\n .map(t => ` ✗ ${t.id} (average score: ${t.averageScore}, threshold: ${JSON.stringify(t.threshold)})`)\n .join('\\n')}`,\n };\n },\n};\n\n/** Registers the Mastra eval matchers on Vitest's `expect`. */\nexport function registerEvalMatchers() {\n expect.extend(evalMatchers);\n}\n"],"mappings":";;AA0BA,SAAS,iBAAiB,OAAyC;CACjE,OACE,OAAO,UAAU,YACjB,UAAU,QACV,YAAY,SACZ,aAAa,SACb,OAAQ,MAAyB,WAAW,YAC3C,MAAyB,WAAW;AAEzC;AAEA,SAAS,gBAAgB,aAAqB,UAAmB;CAC/D,OAAO;EACL,MAAM;EACN,eACE,GAAG,YAAY,uEAAuE,KAAK,UAAU,QAAQ;CACjH;AACF;AAEA,SAAS,YAAY,QAA6B,YAAwC;CACxF,MAAM,SAAS,WAAW,MAAM,GAAG,CAAC,CAAC,QAAa,KAAK,QAAS,OAAO,OAAO,KAAA,IAAY,IAAI,MAAO,MAAM;CAC3G,OAAO,OAAO,WAAW,WAAW,SAAS,KAAA;AAC/C;AAEA,SAAS,iBAAiB,QAA6B,SAAS,IAAc;CAC5E,MAAM,QAAkB,CAAC;CACzB,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,MAAM,GAAG;EACjD,MAAM,OAAO,SAAS,GAAG,OAAO,GAAG,QAAQ;EAC3C,IAAI,OAAO,UAAU,UACnB,MAAM,KAAK,IAAI;OACV,IAAI,SAAS,OAAO,UAAU,UACnC,MAAM,KAAK,GAAG,iBAAiB,OAAO,IAAI,CAAC;CAE/C;CACA,OAAO;AACT;AAEA,MAAa,eAAe;CAC1B,cAAc,UAAmB,SAAsB;EACrD,IAAI,CAAC,iBAAiB,QAAQ,GAAG,OAAO,gBAAgB,iBAAiB,QAAQ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.ts"],"sourcesContent":["import type { EvalVerdict, RunEvalsResult } from '@mastra/core/evals';\nimport { expect } from 'vitest';\n\n/**\n * Custom Vitest matchers operating on a `RunEvalsResult` (the return value of\n * `runEvals`). Registered via `registerEvalMatchers()` or by adding\n * `@mastra/evals/vitest/setup` to `setupFiles`.\n */\nexport interface EvalMatchers<R = unknown> {\n /** Asserts the run's verdict (`passed`, `scored`, or `failed`). */\n toHaveVerdict(verdict: EvalVerdict): R;\n /** Asserts the average score of a scorer is strictly above `min`. Supports dot-paths for categorized configs (e.g. `agent.my-scorer`). */\n toHaveScoreAbove(scorerName: string, min: number): R;\n /** Asserts the average score of a scorer is strictly below `max`. Supports dot-paths for categorized configs (e.g. `agent.my-scorer`). */\n toHaveScoreBelow(scorerName: string, max: number): R;\n /** Asserts that all gates passed (fails when no gates were configured). */\n toPassGates(): R;\n /** Asserts that all scorer thresholds passed (fails when no thresholds were configured). */\n toPassThresholds(): R;\n}\n\n// Vitest's `Assertion`/`Matchers` type parameters differ between majors (v3/v4 `<T>`, v5 `<R, T>`),\n// and augmentations must repeat them exactly, so one declaration can't target all versions.\n// `Chai.Assertion` is identical across Vitest 3–5, and Vitest maps its function members onto\n// `Assertion` (including `.not`, `.resolves`/`.rejects` and `expect.soft`).\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace Chai {\n interface Assertion extends EvalMatchers<void> {}\n }\n}\n\ndeclare module 'vitest' {\n interface AsymmetricMatchersContaining extends EvalMatchers {}\n}\n\nfunction isRunEvalsResult(value: unknown): value is RunEvalsResult {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'scores' in value &&\n 'summary' in value &&\n typeof (value as RunEvalsResult).scores === 'object' &&\n (value as RunEvalsResult).scores !== null\n );\n}\n\nfunction invalidReceived(matcherName: string, received: unknown) {\n return {\n pass: false,\n message: () =>\n `${matcherName} expected a RunEvalsResult (the return value of runEvals), received: ${JSON.stringify(received)}`,\n };\n}\n\nfunction lookupScore(scores: Record<string, any>, scorerName: string): number | undefined {\n const direct = scorerName.split('.').reduce<any>((acc, key) => (acc == null ? undefined : acc[key]), scores);\n return typeof direct === 'number' ? direct : undefined;\n}\n\nfunction availableScorers(scores: Record<string, any>, prefix = ''): string[] {\n const names: string[] = [];\n for (const [key, value] of Object.entries(scores)) {\n const path = prefix ? `${prefix}.${key}` : key;\n if (typeof value === 'number') {\n names.push(path);\n } else if (value && typeof value === 'object') {\n names.push(...availableScorers(value, path));\n }\n }\n return names;\n}\n\nexport const evalMatchers = {\n toHaveVerdict(received: unknown, verdict: EvalVerdict) {\n if (!isRunEvalsResult(received)) return invalidReceived('toHaveVerdict', received);\n const actual = received.verdict;\n return {\n pass: actual === verdict,\n message: () =>\n actual === verdict\n ? `expected verdict not to be \"${verdict}\"`\n : `expected verdict \"${verdict}\", got ${actual === undefined ? 'no verdict (no gates or thresholds configured)' : `\"${actual}\"`}`,\n };\n },\n\n toHaveScoreAbove(received: unknown, scorerName: string, min: number) {\n if (!isRunEvalsResult(received)) return invalidReceived('toHaveScoreAbove', received);\n const score = lookupScore(received.scores, scorerName);\n if (score === undefined) {\n return {\n pass: false,\n message: () =>\n `scorer \"${scorerName}\" not found in result. Available scorers: ${availableScorers(received.scores).join(', ') || '(none)'}`,\n };\n }\n return {\n pass: score > min,\n message: () =>\n score > min\n ? `expected score of \"${scorerName}\" (${score}) not to be above ${min}`\n : `expected score of \"${scorerName}\" (${score}) to be above ${min}`,\n };\n },\n\n toHaveScoreBelow(received: unknown, scorerName: string, max: number) {\n if (!isRunEvalsResult(received)) return invalidReceived('toHaveScoreBelow', received);\n const score = lookupScore(received.scores, scorerName);\n if (score === undefined) {\n return {\n pass: false,\n message: () =>\n `scorer \"${scorerName}\" not found in result. Available scorers: ${availableScorers(received.scores).join(', ') || '(none)'}`,\n };\n }\n return {\n pass: score < max,\n message: () =>\n score < max\n ? `expected score of \"${scorerName}\" (${score}) not to be below ${max}`\n : `expected score of \"${scorerName}\" (${score}) to be below ${max}`,\n };\n },\n\n toPassGates(received: unknown) {\n if (!isRunEvalsResult(received)) return invalidReceived('toPassGates', received);\n const gates = [\n ...(received.gateResults ?? []),\n ...(received.turnResults ?? []).flatMap(\n turn => turn.gateResults?.map(g => ({ ...g, id: `turn ${turn.index} ${g.id}` })) ?? [],\n ),\n ];\n if (gates.length === 0) {\n return {\n pass: false,\n message: () => `no gates were configured on this eval run`,\n };\n }\n const failed = gates.filter(g => !g.passed);\n return {\n pass: failed.length === 0,\n message: () =>\n failed.length === 0\n ? `expected at least one gate to fail, but all ${gates.length} passed`\n : `expected all gates to pass, but ${failed.length} failed:\\n${failed.map(g => ` ✗ ${g.id} (score: ${g.score})`).join('\\n')}`,\n };\n },\n\n toPassThresholds(received: unknown) {\n if (!isRunEvalsResult(received)) return invalidReceived('toPassThresholds', received);\n const thresholds = [\n ...(received.thresholdResults ?? []),\n ...(received.turnResults ?? []).flatMap(\n turn => turn.thresholdResults?.map(t => ({ ...t, id: `turn ${turn.index} ${t.id}` })) ?? [],\n ),\n ];\n if (thresholds.length === 0) {\n return {\n pass: false,\n message: () => `no scorer thresholds were configured on this eval run`,\n };\n }\n const failed = thresholds.filter(t => !t.passed);\n return {\n pass: failed.length === 0,\n message: () =>\n failed.length === 0\n ? `expected at least one threshold to fail, but all ${thresholds.length} passed`\n : `expected all thresholds to pass, but ${failed.length} failed:\\n${failed\n .map(t => ` ✗ ${t.id} (average score: ${t.averageScore}, threshold: ${JSON.stringify(t.threshold)})`)\n .join('\\n')}`,\n };\n },\n};\n\n/** Registers the Mastra eval matchers on Vitest's `expect`. */\nexport function registerEvalMatchers() {\n expect.extend(evalMatchers);\n}\n"],"mappings":";;AAoCA,SAAS,iBAAiB,OAAyC;CACjE,OACE,OAAO,UAAU,YACjB,UAAU,QACV,YAAY,SACZ,aAAa,SACb,OAAQ,MAAyB,WAAW,YAC3C,MAAyB,WAAW;AAEzC;AAEA,SAAS,gBAAgB,aAAqB,UAAmB;CAC/D,OAAO;EACL,MAAM;EACN,eACE,GAAG,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oB,CAAC,GAClC,IAAI,SAAS,eAAe,CAAC,EAAA,CAAG,SAC9B,SAAQ,KAAK,kBAAkB,KAAI,OAAM;GAAE,GAAG;GAAG,IAAI,QAAQ,KAAK,MAAM,GAAG,EAAE;EAAK,EAAE,KAAK,CAAC,CAC5F,CACF;EACA,IAAI,WAAW,WAAW,GACxB,OAAO;GACL,MAAM;GACN,eAAe;EACjB;EAEF,MAAM,SAAS,WAAW,QAAO,MAAK,CAAC,EAAE,MAAM;EAC/C,OAAO;GACL,MAAM,OAAO,WAAW;GACxB,eACE,OAAO,WAAW,IACd,oDAAoD,WAAW,OAAO,WACtE,wCAAwC,OAAO,OAAO,YAAY,OAC/D,KAAI,MAAK,OAAO,EAAE,GAAG,mBAAmB,EAAE,aAAa,eAAe,KAAK,UAAU,EAAE,SAAS,EAAE,EAAE,CAAC,CACrG,KAAK,IAAI;EACpB;CACF;AACF;;AAGA,SAAgB,uBAAuB;CACrC,OAAA,OAAO,OAAO,YAAY;AAC5B"}
@@ -1 +1 @@
1
- {"version":3,"file":"matchers-CVIJYGVp.js","names":[],"sources":["../src/vitest/matchers.ts"],"sourcesContent":["import type { EvalVerdict, RunEvalsResult } from '@mastra/core/evals';\nimport { expect } from 'vitest';\n\n/**\n * Custom Vitest matchers operating on a `RunEvalsResult` (the return value of\n * `runEvals`). Registered via `registerEvalMatchers()` or by adding\n * `@mastra/evals/vitest/setup` to `setupFiles`.\n */\nexport interface EvalMatchers<R = unknown> {\n /** Asserts the run's verdict (`passed`, `scored`, or `failed`). */\n toHaveVerdict(verdict: EvalVerdict): R;\n /** Asserts the average score of a scorer is strictly above `min`. Supports dot-paths for categorized configs (e.g. `agent.my-scorer`). */\n toHaveScoreAbove(scorerName: string, min: number): R;\n /** Asserts the average score of a scorer is strictly below `max`. Supports dot-paths for categorized configs (e.g. `agent.my-scorer`). */\n toHaveScoreBelow(scorerName: string, max: number): R;\n /** Asserts that all gates passed (fails when no gates were configured). */\n toPassGates(): R;\n /** Asserts that all scorer thresholds passed (fails when no thresholds were configured). */\n toPassThresholds(): R;\n}\n\ndeclare module 'vitest' {\n interface Assertion<T = any> extends EvalMatchers<T> {}\n interface AsymmetricMatchersContaining extends EvalMatchers {}\n}\n\nfunction isRunEvalsResult(value: unknown): value is RunEvalsResult {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'scores' in value &&\n 'summary' in value &&\n typeof (value as RunEvalsResult).scores === 'object' &&\n (value as RunEvalsResult).scores !== null\n );\n}\n\nfunction invalidReceived(matcherName: string, received: unknown) {\n return {\n pass: false,\n message: () =>\n `${matcherName} expected a RunEvalsResult (the return value of runEvals), received: ${JSON.stringify(received)}`,\n };\n}\n\nfunction lookupScore(scores: Record<string, any>, scorerName: string): number | undefined {\n const direct = scorerName.split('.').reduce<any>((acc, key) => (acc == null ? undefined : acc[key]), scores);\n return typeof direct === 'number' ? direct : undefined;\n}\n\nfunction availableScorers(scores: Record<string, any>, prefix = ''): string[] {\n const names: string[] = [];\n for (const [key, value] of Object.entries(scores)) {\n const path = prefix ? `${prefix}.${key}` : key;\n if (typeof value === 'number') {\n names.push(path);\n } else if (value && typeof value === 'object') {\n names.push(...availableScorers(value, path));\n }\n }\n return names;\n}\n\nexport const evalMatchers = {\n toHaveVerdict(received: unknown, verdict: EvalVerdict) {\n if (!isRunEvalsResult(received)) return invalidReceived('toHaveVerdict', received);\n const actual = received.verdict;\n return {\n pass: actual === verdict,\n message: () =>\n actual === verdict\n ? `expected verdict not to be \"${verdict}\"`\n : `expected verdict \"${verdict}\", got ${actual === undefined ? 'no verdict (no gates or thresholds configured)' : `\"${actual}\"`}`,\n };\n },\n\n toHaveScoreAbove(received: unknown, scorerName: string, min: number) {\n if (!isRunEvalsResult(received)) return invalidReceived('toHaveScoreAbove', received);\n const score = lookupScore(received.scores, scorerName);\n if (score === undefined) {\n return {\n pass: false,\n message: () =>\n `scorer \"${scorerName}\" not found in result. Available scorers: ${availableScorers(received.scores).join(', ') || '(none)'}`,\n };\n }\n return {\n pass: score > min,\n message: () =>\n score > min\n ? `expected score of \"${scorerName}\" (${score}) not to be above ${min}`\n : `expected score of \"${scorerName}\" (${score}) to be above ${min}`,\n };\n },\n\n toHaveScoreBelow(received: unknown, scorerName: string, max: number) {\n if (!isRunEvalsResult(received)) return invalidReceived('toHaveScoreBelow', received);\n const score = lookupScore(received.scores, scorerName);\n if (score === undefined) {\n return {\n pass: false,\n message: () =>\n `scorer \"${scorerName}\" not found in result. Available scorers: ${availableScorers(received.scores).join(', ') || '(none)'}`,\n };\n }\n return {\n pass: score < max,\n message: () =>\n score < max\n ? `expected score of \"${scorerName}\" (${score}) not to be below ${max}`\n : `expected score of \"${scorerName}\" (${score}) to be below ${max}`,\n };\n },\n\n toPassGates(received: unknown) {\n if (!isRunEvalsResult(received)) return invalidReceived('toPassGates', received);\n const gates = [\n ...(received.gateResults ?? []),\n ...(received.turnResults ?? []).flatMap(\n turn => turn.gateResults?.map(g => ({ ...g, id: `turn ${turn.index} ${g.id}` })) ?? [],\n ),\n ];\n if (gates.length === 0) {\n return {\n pass: false,\n message: () => `no gates were configured on this eval run`,\n };\n }\n const failed = gates.filter(g => !g.passed);\n return {\n pass: failed.length === 0,\n message: () =>\n failed.length === 0\n ? `expected at least one gate to fail, but all ${gates.length} passed`\n : `expected all gates to pass, but ${failed.length} failed:\\n${failed.map(g => ` ✗ ${g.id} (score: ${g.score})`).join('\\n')}`,\n };\n },\n\n toPassThresholds(received: unknown) {\n if (!isRunEvalsResult(received)) return invalidReceived('toPassThresholds', received);\n const thresholds = [\n ...(received.thresholdResults ?? []),\n ...(received.turnResults ?? []).flatMap(\n turn => turn.thresholdResults?.map(t => ({ ...t, id: `turn ${turn.index} ${t.id}` })) ?? [],\n ),\n ];\n if (thresholds.length === 0) {\n return {\n pass: false,\n message: () => `no scorer thresholds were configured on this eval run`,\n };\n }\n const failed = thresholds.filter(t => !t.passed);\n return {\n pass: failed.length === 0,\n message: () =>\n failed.length === 0\n ? `expected at least one threshold to fail, but all ${thresholds.length} passed`\n : `expected all thresholds to pass, but ${failed.length} failed:\\n${failed\n .map(t => ` ✗ ${t.id} (average score: ${t.averageScore}, threshold: ${JSON.stringify(t.threshold)})`)\n .join('\\n')}`,\n };\n },\n};\n\n/** Registers the Mastra eval matchers on Vitest's `expect`. */\nexport function registerEvalMatchers() {\n expect.extend(evalMatchers);\n}\n"],"mappings":";;AA0BA,SAAS,iBAAiB,OAAyC;CACjE,OACE,OAAO,UAAU,YACjB,UAAU,QACV,YAAY,SACZ,aAAa,SACb,OAAQ,MAAyB,WAAW,YAC3C,MAAyB,WAAW;AAEzC;AAEA,SAAS,gBAAgB,aAAqB,UAAmB;CAC/D,OAAO;EACL,MAAM;EACN,eACE,GAAG,YAAY,uEAAuE,KAAK,UAAU,QAAQ;CACjH;AACF;AAEA,SAAS,YAAY,QAA6B,YAAwC;CACxF,MAAM,SAAS,WAAW,MAAM,GAAG,CAAC,CAAC,QAAa,KAAK,QAAS,OAAO,OAAO,KAAA,IAAY,IAAI,MAAO,MAAM;CAC3G,OAAO,OAAO,WAAW,WAAW,SAAS,KAAA;AAC/C;AAEA,SAAS,iBAAiB,QAA6B,SAAS,IAAc;CAC5E,MAAM,QAAkB,CAAC;CACzB,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,MAAM,GAAG;EACjD,MAAM,OAAO,SAAS,GAAG,OAAO,GAAG,QAAQ;EAC3C,IAAI,OAAO,UAAU,UACnB,MAAM,KAAK,IAAI;OACV,IAAI,SAAS,OAAO,UAAU,UACnC,MAAM,KAAK,GAAG,iBAAiB,OAAO,IAAI,CAAC;CAE/C;CACA,OAAO;AACT;AAEA,MAAa,eAAe;CAC1B,cAAc,UAAmB,SAAsB;EACrD,IAAI,CAAC,iBAAiB,QAAQ,GAAG,OAAO,gBAAgB,iBAAiB,QAAQ;EACjF,MAAM,SAAS,SAAS;EACxB,OAAO;GACL,MAAM,WAAW;GACjB,eACE,WAAW,UACP,+BAA+B,QAAQ,KACvC,qBAAqB,QAAQ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AW,GACnB,OAAO;GACL,MAAM;GACN,eAAe;EACjB;EAEF,MAAM,SAAS,MAAM,QAAO,MAAK,CAAC,EAAE,MAAM;EAC1C,OAAO;GACL,MAAM,OAAO,WAAW;GACxB,eACE,OAAO,WAAW,IACd,+CAA+C,MAAM,OAAO,WAC5D,mCAAmC,OAAO,OAAO,YAAY,OAAO,KAAI,MAAK,OAAO,EAAE,GAAG,WAAW,EAAE,MAAM,EAAE,CAAC,CAAC,KAAK,IAAI;EACjI;CACF;CAEA,iBAAiB,UAAmB;EAClC,IAAI,CAAC,iBAAiB,QAAQ,GAAG,OAAO,gBAAgB,oBAAoB,QAAQ;EACpF,MAAM,aAAa,CACjB,GAAI,SAAS,oBAAoB,CAAC,GAClC,IAAI,SAAS,eAAe,CAAC,EAAA,CAAG,SAC9B,SAAQ,KAAK,kBAAkB,KAAI,OAAM;GAAE,GAAG;GAAG,IAAI,QAAQ,KAAK,MAAM,GAAG,EAAE;EAAK,EAAE,KAAK,CAAC,CAC5F,CACF;EACA,IAAI,WAAW,WAAW,GACxB,OAAO;GACL,MAAM;GACN,eAAe;EACjB;EAEF,MAAM,SAAS,WAAW,QAAO,MAAK,CAAC,EAAE,MAAM;EAC/C,OAAO;GACL,MAAM,OAAO,WAAW;GACxB,eACE,OAAO,WAAW,IACd,oDAAoD,WAAW,OAAO,WACtE,wCAAwC,OAAO,OAAO,YAAY,OAC/D,KAAI,MAAK,OAAO,EAAE,GAAG,mBAAmB,EAAE,aAAa,eAAe,KAAK,UAAU,EAAE,SAAS,EAAE,EAAE,CAAC,CACrG,KAAK,IAAI;EACpB;CACF;AACF;;AAGA,SAAgB,uBAAuB;CACrC,OAAO,OAAO,YAAY;AAC5B"}
1
+ {"version":3,"file":"matchers-CVIJYGVp.js","names":[],"sources":["../src/vitest/matchers.ts"],"sourcesContent":["import type { EvalVerdict, RunEvalsResult } from '@mastra/core/evals';\nimport { expect } from 'vitest';\n\n/**\n * Custom Vitest matchers operating on a `RunEvalsResult` (the return value of\n * `runEvals`). Registered via `registerEvalMatchers()` or by adding\n * `@mastra/evals/vitest/setup` to `setupFiles`.\n */\nexport interface EvalMatchers<R = unknown> {\n /** Asserts the run's verdict (`passed`, `scored`, or `failed`). */\n toHaveVerdict(verdict: EvalVerdict): R;\n /** Asserts the average score of a scorer is strictly above `min`. Supports dot-paths for categorized configs (e.g. `agent.my-scorer`). */\n toHaveScoreAbove(scorerName: string, min: number): R;\n /** Asserts the average score of a scorer is strictly below `max`. Supports dot-paths for categorized configs (e.g. `agent.my-scorer`). */\n toHaveScoreBelow(scorerName: string, max: number): R;\n /** Asserts that all gates passed (fails when no gates were configured). */\n toPassGates(): R;\n /** Asserts that all scorer thresholds passed (fails when no thresholds were configured). */\n toPassThresholds(): R;\n}\n\n// Vitest's `Assertion`/`Matchers` type parameters differ between majors (v3/v4 `<T>`, v5 `<R, T>`),\n// and augmentations must repeat them exactly, so one declaration can't target all versions.\n// `Chai.Assertion` is identical across Vitest 3–5, and Vitest maps its function members onto\n// `Assertion` (including `.not`, `.resolves`/`.rejects` and `expect.soft`).\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace Chai {\n interface Assertion extends EvalMatchers<void> {}\n }\n}\n\ndeclare module 'vitest' {\n interface AsymmetricMatchersContaining extends EvalMatchers {}\n}\n\nfunction isRunEvalsResult(value: unknown): value is RunEvalsResult {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'scores' in value &&\n 'summary' in value &&\n typeof (value as RunEvalsResult).scores === 'object' &&\n (value as RunEvalsResult).scores !== null\n );\n}\n\nfunction invalidReceived(matcherName: string, received: unknown) {\n return {\n pass: false,\n message: () =>\n `${matcherName} expected a RunEvalsResult (the return value of runEvals), received: ${JSON.stringify(received)}`,\n };\n}\n\nfunction lookupScore(scores: Record<string, any>, scorerName: string): number | undefined {\n const direct = scorerName.split('.').reduce<any>((acc, key) => (acc == null ? undefined : acc[key]), scores);\n return typeof direct === 'number' ? direct : undefined;\n}\n\nfunction availableScorers(scores: Record<string, any>, prefix = ''): string[] {\n const names: string[] = [];\n for (const [key, value] of Object.entries(scores)) {\n const path = prefix ? `${prefix}.${key}` : key;\n if (typeof value === 'number') {\n names.push(path);\n } else if (value && typeof value === 'object') {\n names.push(...availableScorers(value, path));\n }\n }\n return names;\n}\n\nexport const evalMatchers = {\n toHaveVerdict(received: unknown, verdict: EvalVerdict) {\n if (!isRunEvalsResult(received)) return invalidReceived('toHaveVerdict', received);\n const actual = received.verdict;\n return {\n pass: actual === verdict,\n message: () =>\n actual === verdict\n ? `expected verdict not to be \"${verdict}\"`\n : `expected verdict \"${verdict}\", got ${actual === undefined ? 'no verdict (no gates or thresholds configured)' : `\"${actual}\"`}`,\n };\n },\n\n toHaveScoreAbove(received: unknown, scorerName: string, min: number) {\n if (!isRunEvalsResult(received)) return invalidReceived('toHaveScoreAbove', received);\n const score = lookupScore(received.scores, scorerName);\n if (score === undefined) {\n return {\n pass: false,\n message: () =>\n `scorer \"${scorerName}\" not found in result. Available scorers: ${availableScorers(received.scores).join(', ') || '(none)'}`,\n };\n }\n return {\n pass: score > min,\n message: () =>\n score > min\n ? `expected score of \"${scorerName}\" (${score}) not to be above ${min}`\n : `expected score of \"${scorerName}\" (${score}) to be above ${min}`,\n };\n },\n\n toHaveScoreBelow(received: unknown, scorerName: string, max: number) {\n if (!isRunEvalsResult(received)) return invalidReceived('toHaveScoreBelow', received);\n const score = lookupScore(received.scores, scorerName);\n if (score === undefined) {\n return {\n pass: false,\n message: () =>\n `scorer \"${scorerName}\" not found in result. Available scorers: ${availableScorers(received.scores).join(', ') || '(none)'}`,\n };\n }\n return {\n pass: score < max,\n message: () =>\n score < max\n ? `expected score of \"${scorerName}\" (${score}) not to be below ${max}`\n : `expected score of \"${scorerName}\" (${score}) to be below ${max}`,\n };\n },\n\n toPassGates(received: unknown) {\n if (!isRunEvalsResult(received)) return invalidReceived('toPassGates', received);\n const gates = [\n ...(received.gateResults ?? []),\n ...(received.turnResults ?? []).flatMap(\n turn => turn.gateResults?.map(g => ({ ...g, id: `turn ${turn.index} ${g.id}` })) ?? [],\n ),\n ];\n if (gates.length === 0) {\n return {\n pass: false,\n message: () => `no gates were configured on this eval run`,\n };\n }\n const failed = gates.filter(g => !g.passed);\n return {\n pass: failed.length === 0,\n message: () =>\n failed.length === 0\n ? `expected at least one gate to fail, but all ${gates.length} passed`\n : `expected all gates to pass, but ${failed.length} failed:\\n${failed.map(g => ` ✗ ${g.id} (score: ${g.score})`).join('\\n')}`,\n };\n },\n\n toPassThresholds(received: unknown) {\n if (!isRunEvalsResult(received)) return invalidReceived('toPassThresholds', received);\n const thresholds = [\n ...(received.thresholdResults ?? []),\n ...(received.turnResults ?? []).flatMap(\n turn => turn.thresholdResults?.map(t => ({ ...t, id: `turn ${turn.index} ${t.id}` })) ?? [],\n ),\n ];\n if (thresholds.length === 0) {\n return {\n pass: false,\n message: () => `no scorer thresholds were configured on this eval run`,\n };\n }\n const failed = thresholds.filter(t => !t.passed);\n return {\n pass: failed.length === 0,\n message: () =>\n failed.length === 0\n ? `expected at least one threshold to fail, but all ${thresholds.length} passed`\n : `expected all thresholds to pass, but ${failed.length} failed:\\n${failed\n .map(t => ` ✗ ${t.id} (average score: ${t.averageScore}, threshold: ${JSON.stringify(t.threshold)})`)\n .join('\\n')}`,\n };\n },\n};\n\n/** Registers the Mastra eval matchers on Vitest's `expect`. */\nexport function registerEvalMatchers() {\n expect.extend(evalMatchers);\n}\n"],"mappings":";;AAoCA,SAAS,iBAAiB,OAAyC;CACjE,OACE,OAAO,UAAU,YACjB,UAAU,QACV,YAAY,SACZ,aAAa,SACb,OAAQ,MAAyB,WAAW,YAC3C,MAAyB,WAAW;AAEzC;AAEA,SAAS,gBAAgB,aAAqB,UAAmB;CAC/D,OAAO;EACL,MAAM;EACN,eACE,GAAG,YAAY,uEAAuE,KAAK,UAAU,QAAQ;CACjH;AACF;AAEA,SAAS,YAAY,QAA6B,YAAwC;CACxF,MAAM,SAAS,WAAW,MAAM,GAAG,CAAC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AAQ,KAAK,MAAM,GAAG,EAAE;EAAK,EAAE,KAAK,CAAC,CAC5F,CACF;EACA,IAAI,WAAW,WAAW,GACxB,OAAO;GACL,MAAM;GACN,eAAe;EACjB;EAEF,MAAM,SAAS,WAAW,QAAO,MAAK,CAAC,EAAE,MAAM;EAC/C,OAAO;GACL,MAAM,OAAO,WAAW;GACxB,eACE,OAAO,WAAW,IACd,oDAAoD,WAAW,OAAO,WACtE,wCAAwC,OAAO,OAAO,YAAY,OAC/D,KAAI,MAAK,OAAO,EAAE,GAAG,mBAAmB,EAAE,aAAa,eAAe,KAAK,UAAU,EAAE,SAAS,EAAE,EAAE,CAAC,CACrG,KAAK,IAAI;EACpB;CACF;AACF;;AAGA,SAAgB,uBAAuB;CACrC,OAAO,OAAO,YAAY;AAC5B"}
@@ -42,13 +42,12 @@ var EvalPassRateError = class extends Error {
42
42
  };
43
43
  async function attachMetaToCurrentTest(result) {
44
44
  try {
45
- const task = (await import("vitest")).TestRunner?.getCurrentTest?.();
46
- if (task?.meta) {
47
- task.meta.mastraEval = toEvalMeta(result);
48
- return;
49
- }
50
- const legacyTask = (await import("vitest/suite")).getCurrentTest?.();
51
- if (legacyTask?.meta) legacyTask.meta.mastraEval = toEvalMeta(result);
45
+ let task = (await import("vitest")).TestRunner?.getCurrentTest?.();
46
+ if (!task) task = (await import(
47
+ /* @vite-ignore */
48
+ "vitest/suite"
49
+ )).getCurrentTest?.();
50
+ if (task?.meta) task.meta.mastraEval = toEvalMeta(result);
52
51
  } catch {}
53
52
  }
54
53
  function assertPassRate(result, minPassRate) {
@@ -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,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B;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"}
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 (including 5)\n let task = (vitest as any).TestRunner?.getCurrentTest?.();\n if (!task) {\n // Vitest 3.x / 4.0. `vitest/suite` doesn't exist in Vitest 5, so keep the specifier\n // out of reach of TypeScript and the bundler.\n const suiteEntry = 'vitest/suite';\n const suite = await import(/* @vite-ignore */ suiteEntry);\n task = suite.getCurrentTest?.();\n }\n if (task?.meta) {\n task.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,IAAI,QAAQ,MAFS,OAAO,UAAA,CAED,YAAY,iBAAiB;EACxD,IAAI,CAAC,MAKH,Q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,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"}
@@ -41,13 +41,12 @@ var EvalPassRateError = class extends Error {
41
41
  };
42
42
  async function attachMetaToCurrentTest(result) {
43
43
  try {
44
- const task = (await import("vitest")).TestRunner?.getCurrentTest?.();
45
- if (task?.meta) {
46
- task.meta.mastraEval = toEvalMeta(result);
47
- return;
48
- }
49
- const legacyTask = (await import("vitest/suite")).getCurrentTest?.();
50
- if (legacyTask?.meta) legacyTask.meta.mastraEval = toEvalMeta(result);
44
+ let task = (await import("vitest")).TestRunner?.getCurrentTest?.();
45
+ if (!task) task = (await import(
46
+ /* @vite-ignore */
47
+ "vitest/suite"
48
+ )).getCurrentTest?.();
49
+ if (task?.meta) task.meta.mastraEval = toEvalMeta(result);
51
50
  } catch {}
52
51
  }
53
52
  function assertPassRate(result, minPassRate) {
@@ -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,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;C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,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.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 (including 5)\n let task = (vitest as any).TestRunner?.getCurrentTest?.();\n if (!task) {\n // Vitest 3.x / 4.0. `vitest/suite` doesn't exist in Vitest 5, so keep the specifier\n // out of reach of TypeScript and the bundler.\n const suiteEntry = 'vitest/suite';\n const suite = await import(/* @vite-ignore */ suiteEntry);\n task = suite.getCurrentTest?.();\n }\n if (task?.meta) {\n task.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,IAAI,QAAQ,MAFS,OAAO,UAAA,CAED,YAAY,iBAAiB;EACxD,IAAI,CAAC,MAKH,QAAO,MADa;;GAA0B;EAClC,CAAC,iBAAiB;EAEhC,IAAI,MAAM,MACR,KAAK,KAAK,aAAa,WAAW,MAAM;CAE5C,QAAQ,CAER;AACF;AAEA,SAAS,eAAe,QAAwB,aAA2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AAO,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"}
@@ -16,9 +16,13 @@ export interface EvalMatchers<R = unknown> {
16
16
  /** Asserts that all scorer thresholds passed (fails when no thresholds were configured). */
17
17
  toPassThresholds(): R;
18
18
  }
19
- declare module 'vitest' {
20
- interface Assertion<T = any> extends EvalMatchers<T> {
19
+ declare global {
20
+ namespace Chai {
21
+ interface Assertion extends EvalMatchers<void> {
22
+ }
21
23
  }
24
+ }
25
+ declare module 'vitest' {
22
26
  interface AsymmetricMatchersContaining extends EvalMatchers {
23
27
  }
24
28
  }
@@ -1 +1 @@
1
- {"version":3,"file":"matchers.d.ts","sourceRoot":"","sources":["../../src/vitest/matchers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAkB,MAAM,oBAAoB,CAAC;AAGtE;;;;GAIG;AACH,MAAM,WAAW,YAAY,CAAC,CAAC,GAAG,OAAO;IACvC,mEAAmE;IACnE,aAAa,CAAC,OAAO,EAAE,WAAW,GAAG,CAAC,CAAC;IACvC,0IAA0I;IAC1I,gBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,CAAC;IACrD,0IAA0I;IAC1I,gBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,CAAC;IACrD,2EAA2E;IAC3E,WAAW,IAAI,CAAC,CAAC;IACjB,4FAA4F;IAC5F,gBAAgB,IAAI,CAAC,CAAC;CACvB;AAED,OAAO,QAAQ,QAAQ,CAAC;IACtB,UAAU,SAAS,CAAC,CAAC,GAAG,GAAG,CAAE,SAAQ,YAAY,CAAC,CAAC,CAAC;KAAG;IACvD,U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B,WAAW,OAAO,cAAc,MAAM,OAAO,MAAM;;;;IAmBnE,WAAW,WAAW,OAAO;;;;IAwB7B,gBAAgB,WAAW,OAAO;;;;CAyBnC,CAAC;AAEF,+DAA+D;AAC/D,wBAAgB,oBAAoB,SAEnC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/evals",
3
- "version": "1.10.10",
3
+ "version": "1.10.11-alpha.0",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "files": [
@@ -91,7 +91,7 @@
91
91
  },
92
92
  "peerDependencies": {
93
93
  "@mastra/core": ">=1.0.0-0 <2.0.0-0",
94
- "vitest": ">=3.0.0 <5.0.0"
94
+ "vitest": ">=3.0.0 <6.0.0"
95
95
  },
96
96
  "peerDependenciesMeta": {
97
97
  "vitest": {
@@ -100,24 +100,24 @@
100
100
  },
101
101
  "devDependencies": {
102
102
  "@ai-sdk/openai": "^1.3.24",
103
- "@ai-sdk/openai-v6": "npm:@ai-sdk/openai@3.0.132",
103
+ "@ai-sdk/openai-v6": "npm:@ai-sdk/openai@3.0.135",
104
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.12",
108
- "@vitest/ui": "4.1.12",
109
- "dotenv": "^17.4.2",
107
+ "@vitest/coverage-v8": "5.1.0",
108
+ "@vitest/ui": "5.1.0",
109
+ "dotenv": "^18.0.9",
110
110
  "tsdown": "0.23.1",
111
111
  "tsx": "^4.23.15",
112
112
  "typescript": "^7.0.2",
113
- "vitest": "4.1.12",
113
+ "vitest": "5.1.0",
114
114
  "zod": "^4.6.7",
115
115
  "@internal/ai-sdk-v5": "0.0.94",
116
116
  "@internal/lint": "0.0.147",
117
117
  "@internal/llm-recorder": "0.0.83",
118
- "@internal/types-builder": "0.0.122",
119
118
  "@internal/test-utils": "0.0.83",
120
- "@mastra/core": "1.81.0"
119
+ "@internal/types-builder": "0.0.122",
120
+ "@mastra/core": "1.82.0-alpha.3"
121
121
  },
122
122
  "engines": {
123
123
  "node": ">=22.13.0"