testing-core-processors

Writes integration tests for Mastra core error processors using MockLanguageModelV2.

27.6k|2.7k|Updated Aug 6, 2024
One-click install
npx skills add https://github.com/mastra-ai/mastra --skill testing-core-processors
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: testing-core-processors
Source: https://github.com/mastra-ai/mastra/tree/main/.claude/skills/testing-core-processors
Command: npx skills add https://github.com/mastra-ai/mastra --skill testing-core-processors

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Writing integration tests for error processors in Mastra's core package requires simulating API errors and verifying retry behavior, which is difficult without a consistent mock model pattern and knowledge of build prerequisites.

Core Features & Use Cases

  • Mock Model Pattern: Uses MockLanguageModelV2 from @internal/ai-sdk-v5/test to throw APICallError on demand and capture prompts for retry verification.
  • Stream Mock Guidance: Documents the full stream event sequence (stream-start, response-metadata, text-start, text-delta, text-end, finish) required to avoid empty text output.
  • Test Structure Template: Defines happy path, control, and selectivity tests for each error processor, plus message seeding with tool calls.
  • Use Case: When adding a new error processor to packages/core/src/processors/, follow this guide to write tests that verify the processor catches the target error, modifies messages, and retries successfully.

Quick Start

Ask the assistant to write an integration test for a new error processor in packages/core/src/processors/ using the MockLanguageModelV2 pattern.

Frequently Asked Questions about testing-core-processors

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I test error processors in Mastra core?▼

Use MockLanguageModelV2 from @internal/ai-sdk-v5/test to throw an APICallError on the first call and return a normal response on retry. Assert that agent.generate() succeeds, the mock was called twice, and the retry prompt contains the expected modifications.

How to mock streaming responses with MockLanguageModelV2?▼

Implement doStream returning a stream built with convertArrayToReadableStream containing stream-start, response-metadata, text-start, text-delta, text-end, and finish events. Using only text-delta and finish produces empty text output because the AI SDK expects the full event sequence.

Why do focused vitest runs fail to resolve @internal/test-utils/setup?▼

This failure means the core build step was skipped. Run pnpm build:core from the repository root before executing focused vitest runs so internal test utilities resolve correctly.

What tests should each error processor have?▼

Write at minimum three tests: a happy path where the processor catches the error and retries successfully, a control test without the processor where the error propagates, and a selectivity test confirming unrelated errors like 429 rate limits are ignored.

Do mock-based processor tests need API keys?▼

No secrets are needed for mock-based integration tests. Live API tests require ANTHROPIC_API_KEY for real Anthropic API testing and OPENROUTER_API_KEY for provider switching scenarios.