> REQUIRED and PRIMARY testing approach for packages/playground and packages/playground-ui. React Query interactions, or any test work in these packages. Generates Vitest tests that drive the real @mastra/client-js + React Query stack through MSW handlers and typed fixtures derived from @mastra/client-js response types. This is the #1 way to test the playground packages — ABOVE Playwright E2E. Use Playwright only for cross-page user journeys that MSW cannot model.
npx skills add https://github.com/mastra-ai/mastra --skill playground-msw-tests
Drive the real transport, mock the network.
Tests in packages/playground and packages/playground-ui MUST be written as
Vitest tests that exercise the real @mastra/client-js SDK, the real React Query
cache, and the real component/hook code paths. The only seam we mock is the
network boundary, via MSW.
This catches contract drift between the playground and @mastra/client-js at
typecheck time and at test time — something vi.mock('@/hooks/...') style tests
cannot do.
When you write or refactor a test for these packages, choose in this order:
data-fetching, gating, redirect logic, query/mutation flows, error paths.
e2e-tests-studio skill) — only for genuine cross-pageuser journeys, real browser concerns (focus/keyboard/viewport), or anything
that requires a real running Mastra server.
network, no React Query, no router involvement.
If the same behavior can be covered by both #1 and #2, prefer #1. MSW tests
are faster, deterministic, run in CI without browsers, and assert the real wire
contract.
vi.mock('@/domains/.../hooks/use-agents') — mocking our own hooks hidescache, gating and transport bugs.
branch logic, generated shapes, or calculations without asserting a real
behavior or regression.
expect(node.className).toContain(...)usually just tests that the implementation string exists. Prefer no test over
a className duplication test; use computed style, user-visible behavior, or a
browser/Storybook check unless the class string itself is the public API.
type AgentLite = { id: string }) —these drift silently from the real SDK.
as any / as unknown as ListAgentsResponse on fixture data, MSWresponses, request payloads, hook inputs, or component event inputs.
@mastra/client-js response. If a field is optional, include it as optional
in the fixture, don't omit the type.
__tests__/fixtures/ folder next to the test file.@mastra/client-js(e.g. ListStoredAgentsResponse, GetAgentResponse, BuilderSettingsResponse,
GetToolResponse, GetWorkflowResponse, ListStoredSkillsResponse).
or Testing Library APIs for MSW payloads, request payloads, hook inputs, and
component events.
server.use(...) so handlers resetbetween tests via the global afterEach.
MastraReactProvider + QueryClientProvider + MemoryRouterso the real client SDK is the transport.
vi.fn() wrappers inside MSW handlers to assert which endpoints werehit (great for testing enabled: ... gating without mocking hooks).
// @vitest-environment jsdom
import { MastraReactProvider } from '@mastra/react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { cleanup, render, screen } from '@testing-library/react';
import { http, HttpResponse } from 'msw';
import { MemoryRouter } from 'react-router';
import { afterEach, describe, expect, it } from 'vitest';
import { server } from '@/test/msw-server';
import { Subject } from '../subject';
import { happyPathResponse } from './fixtures/subject';
const BASE_URL = 'http://localhost:4111';
const renderSubject = () => {
const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } });
return render(
<MastraReactProvider baseUrl={BASE_URL}>
<QueryClientProvider client={queryClient}>
<MemoryRouter>
<Subject />
</MemoryRouter>
</QueryClientProvider>
</MastraReactProvider>,
);
};
afterEach(() => cleanup());
describe('Subject', () => {
it('renders the happy path', async () => {
server.use(http.get(`${BASE_URL}/api/agents`, () => HttpResponse.json(happyPathResponse)));
renderSubject();
expect(await screen.findByText('Expected behavior')).not.toBeNull();
});
});
// packages/playground/src/.../__tests__/fixtures/subject.ts
import type { ListStoredAgentsResponse } from '@mastra/client-js';
export const emptyStoredAgents: ListStoredAgentsResponse = {
agents: [],
total: 0,
page: 1,
perPage: 50,
hasMore: false,
};
export const oneDraftAgent: ListStoredAgentsResponse = {
...emptyStoredAgents,
agents: [
{
id: 'agent-1',
name: 'Draft Agent',
instructions: '',
model: { provider: 'openai', name: 'gpt-4o-mini' },
status: 'draft',
// ...other required fields from StoredAgentResponse
},
],
total: 1,
};
**If a required field on the SDK response type is missing from your fixture,
that's a real test failure — fix the fixture, never as any it.** The same
applies to hook inputs, component events, and request payloads: type the helper
at the real boundary instead of casting the test into compiling.
packages/playground/src/test/msw-server.ts — exports server. The globalvitest.setup.ts calls server.listen({ onUnhandledRequest: 'error' }),
server.resetHandlers() after each test, and server.close() at the end.
This means unhandled requests fail tests loudly — that's the contract.
packages/playground/vitest.setup.ts — already wires MSW lifecycle, jsdompolyfills (matchMedia, Element.prototype.scrollTo), so test files just
add their own server.use(...) per case.
Defer the MSW handler's resolution with a promise gate:
const gate = (() => {
let resolve: () => void = () => {};
const promise = new Promise<void>(r => {
resolve = r;
});
return { promise, resolve };
})();
server.use(
http.get(`${BASE_URL}/api/stored/agents`, async () => {
await gate.promise;
return HttpResponse.json(emptyStoredAgents);
}),
);
renderSubject();
expect(screen.getByTestId('spinner')).not.toBeNull();
gate.resolve();
await waitFor(() => expect(screen.queryByTestId('spinner')).toBeNull());
enabled: false)Wrap the handler in a vi.fn and assert it was never called:
const onAgents = vi.fn<() => void>();
server.use(
http.get(`${BASE_URL}/api/agents`, () => {
onAgents();
return HttpResponse.json(emptyAgents);
}),
);
renderSubject(); // user has no write access → hook should not fire
await new Promise(resolve => setTimeout(resolve, 50));
expect(onAgents).not.toHaveBeenCalled();
Use a single MSW handler per endpoint and one vi.fn per endpoint, then
toggle the builder-settings response to flip features on/off and assert which
handlers were hit.
Read request.url inside the handler:
server.use(
http.get(`${BASE_URL}/api/stored/agents`, ({ request }) => {
const status = new URL(request.url).searchParams.get('status');
return HttpResponse.json(status === 'draft' ? oneDraftAgent : emptyStoredAgents);
}),
);
You may replace these with very thin stubs:
AgentBuilderStarter to <div data-testid="agent-builder-starter" />).
react-router's Navigate so you can assert the redirect target insteadof letting it actually navigate.
Button / Spinner style atoms from @mastra/playground-ui only when thereal component requires more global context than the test needs.
Never mock our own data hooks, services, or auth gating logic — drive those
through their real implementations against MSW.
Before considering a test done:
@mastra/client-js; MSW payloads,request payloads, hook inputs, and component events use direct imports or
inferred production boundary types; no bespoke test-only shapes and no
as any / as unknown as casts.
vi.mock of @/domains/.../hooks/*, @/domains/.../services/*,@mastra/client-js, or @mastra/react.
pnpm --filter ./packages/playground typecheck passes — proves fixturesconform to the live SDK shape.
onUnhandledRequest: 'error' failures.
for hooks/pages, since MSW makes every branch reachable).
Reach for e2e-tests-studio only when at least one is true:
real model providers).
viewport, file uploads).
Everything else — fetching, caching, redirects, gating, optimistic updates,
error states, empty states, pagination, search params — belongs in this skill.
Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.
Use when implementation is complete, all tests pass, and you need to decide how to integrate the work - guides completion of development work by presenting structured options for merge, PR, or cleanup
Use when implementing any feature or bugfix, before writing implementation code
Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes
Use when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions always
Expert guidance for systematic backtesting of trading strategies. Use when developing, testing, stress-testing, or validating quantitative trading strategies. Covers "beating ideas to death" methodology, parameter robustness testing, slippage modeling, bias prevention, and interpreting backtest results. Applicable when user asks about backtesting, strategy validation, robustness testing, avoiding overfitting, or systematic trading development.
Cloud laboratory platform for automated protein testing and validation. Use when designing proteins and needing experimental validation including binding assays, expression testing, thermostability measurements, enzyme activity assays, or protein sequence optimization. Also use for submitting experiments via API, tracking experiment status, downloading results, optimizing protein sequences for better expression using computational tools (NetSolP, SoluProt, SolubleMPNN, ESM), or managing protein design workflows with wet-lab validation.
This skill should be used for time series machine learning tasks including classification, regression, clustering, forecasting, anomaly detection, segmentation, and similarity search. Use when working with temporal data, sequential patterns, or time-indexed observations requiring specialized algorithms beyond standard ML approaches. Particularly suited for univariate and multivariate time series analysis with scikit-learn compatible APIs.
Take mastra-ai/playground-msw-tests from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.