testing-core-processors
БесплатноБез исполняемых скриптовНе проверенUse when writing or debugging integration tests for error processors in packages/core/src/processors/. Covers the MockLanguageModelV2 pattern for simulating…
от mastra-ai★ 29 944 звезды на GitHubОб этом скилле
Testing Core Error Processors
How to write integration tests for error processors in packages/core/src/processors/.
Prerequisites
- No build needed: Vitest resolves
@mastra/coreand@internal/test-utilsfrom source
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:
- Happy path: Processor catches the target error, modifies messages, retries successfully
- Assert:
agent.generate()succeeds, mock called 2x, retry prompt has expected modifications
- Assert:
- Control test: Same scenario without the processor — error propagates
- Assert:
agent.generate()throws the expected error
- Assert:
- 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 APIOPENROUTER_API_KEY— for testing provider switching scenarios
Установить testing-core-processors в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл testing-core-processors?
Use when writing or debugging integration tests for error processors in packages/core/src/processors/. Covers the MockLanguageModelV2 pattern for simulating API errors and verifying retry behavior, plus how to run focused vitest runs.
Как установить скилл testing-core-processors?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл testing-core-processors запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic