testing-core-processors

द्वारा mastra-ai

Use when writing or debugging integration tests for error processors in packages/core/src/processors/. Covers the MockLanguageModelV2 pattern for simulating…

npx skills add https://github.com/mastra-ai/mastra --skill testing-core-processors

Testing Core Error Processors

How to write integration tests for error processors in packages/core/src/processors/.

Prerequisites

  • Build core before running tests: pnpm build:core (from repo root)
  • If focused vitest runs fail to resolve @internal/test-utils/setup, the build step was skipped

Mock Model Pattern

Use MockLanguageModelV2 from @internal/ai-sdk-v5/test to simulate API errors and verify retry behavior.

import { APICallError } from '@internal/ai-sdk-v5';
import { convertArrayToReadableStream, MockLanguageModelV2 } from '@internal/ai-sdk-v5/test';

// Track calls and captured prompts
let callCount = 0;
const receivedPrompts: any[] = [];

const model = new MockLanguageModelV2({
  doGenerate: async ({ prompt }) => {
    callCount++;
    receivedPrompts.push(JSON.parse(JSON.stringify(prompt)));
    if (callCount === 1) {
      throw new APICallError({
        message: '...',
        url: '...',
        requestBodyValues: {},
        statusCode: 400,
        responseBody: '...',
        isRetryable: false,
      });
    }
    return {
      rawCall: { rawPrompt: null, rawSettings: {} },
      finishReason: 'stop',
      usage: { inputTokens: 10, outputTokens: 20, totalTokens: 30 },
      content: [{ type: 'text', text: 'response' }],
      warnings: [],
    };
  },
  doStream: async ({ prompt }) => {
    // Same error logic as doGenerate
    // IMPORTANT: Stream response must include all event types:
    return {
      rawCall: { rawPrompt: null, rawSettings: {} },
      warnings: [],
      stream: convertArrayToReadableStream([
        { type: 'stream-start', warnings: [] },
        { type: 'response-metadata', id: 'id-0', modelId: 'mock-model', timestamp: new Date(0) },
        { type: 'text-start', id: 'text-1' },
        { type: 'text-delta', id: 'text-1', delta: 'response text' },
        { type: 'text-end', id: 'text-1' },
        { type: 'finish', finishReason: 'stop', usage: { inputTokens: 10, outputTokens: 20, totalTokens: 30 } },
      ]),
    };
  },
});

Stream Mock Gotcha

The stream mock format requires stream-start, response-metadata, text-start, text-delta, text-end, and finish events. Using only text-delta + finish (the minimal format) will result in empty text output because the AI SDK expects the full event sequence. See prefill-error-recovery.test.ts for the reference pattern.

Test Structure

For each error processor, write at minimum:

  1. Happy path: Processor catches the target error, modifies messages, retries successfully
    • Assert: agent.generate() succeeds, mock called 2x, retry prompt has expected modifications
  2. Control test: Same scenario without the processor — error propagates
    • Assert: agent.generate() throws the expected error
  3. Selectivity test: Processor ignores unrelated errors (e.g. rate limit 429)
    • Assert: Error propagates, mock called only 1x

Passing Messages with Tool Calls

When seeding conversation history for tool-related tests, pass messages as the second argument to agent.generate() or agent.stream() using the AI SDK message format:

const messages = [
  { role: 'user', content: 'Do something' },
  { role: 'assistant', content: [{ type: 'tool-call', toolCallId: 'some-id', toolName: 'myTool', args: {} }] },
  { role: 'tool', content: [{ type: 'tool-result', toolCallId: 'some-id', toolName: 'myTool', result: 'done' }] },
];
await agent.generate(messages);

Running Tests

# Run focused processor tests
npx vitest run packages/core/src/processors/my-processor.test.ts

# Run all processor tests
npx vitest run packages/core/src/processors/

# Full core test suite (slower)
pnpm test:core

Devin Secrets Needed

None for mock-based integration tests. For live API tests:

  • ANTHROPIC_API_KEY — for testing against real Anthropic API
  • OPENROUTER_API_KEY — for testing provider switching scenarios

mastra-ai की और Skills

testing-mastracode-tui
mastra-ai
कोन्सोल में मास्ट्राकोड TUI सुविधाओं का इंटरैक्टिव परीक्षण। मॉडल कॉन्फ़िगरेशन, थ्रेड जीवनचक्र, कार्य स्थिति पृथक्करण और सामान्य अवरोधकों को शामिल करता है।
official
mastra-smoke-test
mastra-ai
मास्ट्रा प्रोजेक्ट्स का स्थानीय रूप से स्मोक टेस्ट करें या स्टेजिंग/प्रोडक्शन पर डिप्लॉय करें। स्टूडियो UI, एजेंट, टूल्स, वर्कफ़्लो, ट्रेस, मेमोरी और अधिक का परीक्षण करता है। स्थानीय और दोनों का समर्थन करता है…
official
security-review
mastra-ai
सुरक्षा-केंद्रित कोड समीक्षा जाँचसूची जो कमजोरियों की पहचान करने के लिए है
official
technical-writing
mastra-ai
स्पष्ट, सुव्यवस्थित तकनीकी दस्तावेज़ीकरण बनाने के लिए दिशानिर्देश
official
code-standards
mastra-ai
कोड गुणवत्ता मानक और पुल रिक्वेस्ट की समीक्षा के लिए शैली मार्गदर्शिका
official
debugging-difficult-bugs
mastra-ai
मध्यम या कठिन बग को डीबग करते समय शुरुआत में ही उपयोग करें, विशेषकर जब अकेले परीक्षण वास्तविक रनटाइम विफलता को उजागर नहीं कर सकते। विस्तारित TDD पुनरावृत्ति से पहले इसे सक्रिय करें…
official
e2e-frontend-validation
mastra-ai
प्ले Playwright MCP का उपयोग करके प्लेग्राउंड पैकेजों में फ्रंटएंड बदलावों के लिए E2E सत्यापन वर्कफ़्लो
official
e2e-tests-studio
mastra-ai
आवश्यक जब packages/playground-ui या packages/playground में किसी भी फ़ाइल को संशोधित किया जाए। ट्रिगर होता है: React कंपोनेंट निर्माण/संशोधन/रीफैक्टरिंग, UI परिवर्तन,…
official