AGENT
Use when designing a new HTTP/GraphQL API or changing an existing one — modeling resources, defining endpoint contracts, choosing status codes, pagination,…
Tests must be **isolated** (independent of each other) and **deterministic** (same result every run). That means controlling everything that crosses a boundary or varies between runs: time, randomness, network, filesystem, and shared collaborators.
$ npx -y skills add vanara-agents/skills --agent claude-codeHow it fires
How this agent gets triggered: by you, by Claude, or both.
Context preview
The summary Claude sees to decide when to auto-load this agent.
Tests must be **isolated** (independent of each other) and **deterministic** (same result every run). That means controlling everything that crosses a boundary or varies between runs: time, randomness, network, filesystem, and shared collaborators.
Tests must be **isolated** (independent of each other) and **deterministic** (same result every run). That means controlling everything that crosses a boundary or varies between runs: time, randomness, network, filesystem, and shared collaborators.
| Double | Purpose | |---|---| | **Dummy** | Filler passed to satisfy a signature; never used. | | **Stub** | Returns canned answers to calls made during the test. | | **Spy** | A stub that also records how it was called. | | **Mock** | A double with pre-set expectations that verifies interactions. | | **Fake** | A working but lightweight implementation (in-memory DB, fake clock). |
Reach for the **simplest** double that does the job. Prefer **fakes and stubs** over strict mocks: asserting on exact call sequences couples the test to implementation and makes refactoring break green tests.
// GOOD: mock the HTTP client (a true external boundary)
const httpGet = vi.fn().mockResolvedValue({ status: 200, body: { rate: 1.1 } });
const rate = await fetchExchangeRate(httpGet, 'USD', 'EUR');
expect(rate).toBe(1.1);// BAD: mocking the function under test leaves nothing real to verify const fetchExchangeRate = vi.fn().mockResolvedValue(1.1); // tests the mock, not the code
Over-mocking is a top cause of tests that pass while the system is broken. If a test is almost entirely mock setup, you are testing the mock framework. Either widen the unit or move the check to an integration test with a real collaborator.
Wall-clock time is the most common flakiness source. Inject a clock or freeze it:
import { vi } from 'vitest';
vi.useFakeTimers();
vi.setSystemTime(new Date('2026-06-29T12:00:00Z'));
expect(isExpired(token)).toBe(false);
vi.advanceTimersByTime(60_000); // jump 60s deterministically
expect(isExpired(token)).toBe(true);
vi.useRealTimers(); // always restoreNever assert on `Date.now()` or sleep with real timeouts — that makes tests slow and racy.
Seed the RNG or inject it. A test that depends on `Math.random()` passes-then-fails at random:
const rng = () => 0.42; // injected, deterministic
expect(pickWinner(players, rng)).toBe('alice');resilient — when a required field is added, you change the factory once, not 50 tests.
let the factory default the rest. This makes the *intent* of each test obvious.
`beforeEach`/`afterEach` so tests can run in any order. Order-dependent tests are a bug.
function makeOrder(overrides = {}) {
return { id: 'ord_1', status: 'open', total: 100, createdAt: new Date(0), ...overrides };
}
it('marks a paid order as fulfilled', () => {
const order = makeOrder({ status: 'paid' }); // only the relevant field is set
expect(fulfill(order).status).toBe('fulfilled');
});🐒 Free agents, skills & packs for Claude Code One subscription. An army of Claude Code agents. 30 production-grade agents, skills, and packs for Claude Code — free, Apache-2.0, install with one command.
Repo: vanara-agents/skills
Use when designing a new HTTP/GraphQL API or changing an existing one — modeling resources, defining endpoint contracts, choosing status codes, pagination,…
This shows how the api-designer agent reviews a flawed draft. Findings are severity-ranked so the implementer fixes the contract-breakers first. Severity…
The contract is the deliverable. Express it as an **OpenAPI 3.1** document so it is human-readable *and* machine-checkable. This reference covers how to…
Run through this before declaring an API contract done. It is ordered the way you should *design*: resources first, cross-cutting rules last. Every box is a…
APIs are forever once published: a consumer you've never met may depend on any field you expose. Design so you can **add without breaking**, and version…
Copy-paste templates for leaving review comments. Keep each comment to one finding: an anchor, the problem, and the fix.