/mattpocock-skills:contract-concurrencyfrom mattpocock-skills
Test adapter contract parity across multiple implementations and stress-test concurrent state mutations. Use when building seams with InMemory and real database/cache adapters (Postgres, Redis), testing race conditions, writing concurrent Promise.all stress tests, verifying transaction isolation, or testing row locking.
Ships in mattpocock-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Discipline for adapter contract parity and concurrent stress testing.
The codebase-design and tdd skills recommend isolating external systems behind clean seams (such as OrderStoreAdapter) and writing business logic tests against fast in-memory adapters (InMemoryOrderStore).
However, in-memory adapters run synchronously in single-threaded JavaScript, masking production realities: transaction isolation levels, connection pooling limits, foreign key constraints, deadlocks, and race conditions. A test suite that passes 100% on an in-memory adapter can fail catastrophically when deployed against PostgreSQL or Redis.
contract-concurrency extends tdd with two mandatory testing practices.
Whenever a seam has two or more implementations (for example, InMemoryStore for local development and unit tests, and PostgresStore for production), both adapters must pass the exact same contract test suite.
Define the test suite inside a shared factory function that accepts an adapter factory:
export function describeStoreContract(createStore: () => Promise<Store>) {
describe("Store Contract Parity", () => {
let store: Store;
beforeEach(async () => {
store = await createStore();
});
it("returns null when item does not exist", async () => {
const result = await store.getById("non-existent");
expect(result).toBeNull();
});
it("rejects duplicate keys with a typed EntityConflictError", async () => {
await store.insert({ id: "item-1", name: "Alpha" });
await expect(store.insert({ id: "item-1", name: "Beta" })).rejects.toThrow(
EntityConflictError
);
});
it("preserves ordering and handles boundary pagination", async () => {
// Verifies identical sorting and offset behavior across both adapters
});
});
}
describeStoreContract(() => new InMemoryStore()) during rapid red-green loops. It runs in milliseconds.describeStoreContract(() => createTestPostgresStore()) against a real database instance before closing the ticket.InMemoryStore and PostgresStore disagree on behavior (such as error types, null vs undefined, or sorting order), fix the drift immediately.For deep modules that manage contested state (such as account balances, inventory reservation, ticket allocations, or auction bids), unit tests with sequential calls are insufficient. You must write at least one concurrent stress test against the real infrastructure adapter.
Use Promise.all to launch concurrent operations simultaneously against the shared resource:
it("prevents inventory overselling under concurrent load", async () => {
const store = await createTestPostgresStore();
const itemId = "limited-item";
const initialStock = 10;
await store.initItem(itemId, initialStock);
// Attempt 50 simultaneous purchases for 10 available items
const attempts = Array.from({ length: 50 }, (_, i) => ({
userId: `user-${i}`,
quantity: 1,
}));
const results = await Promise.allSettled(
attempts.map((req) => store.purchase(itemId, req.userId, req.quantity))
);
const successfulPurchases = results.filter((r) => r.status === "fulfilled");
const failedPurchases = results.filter((r) => r.status === "rejected");
// Invariant verification:
expect(successfulPurchases).toHaveLength(10);
expect(failedPurchases).toHaveLength(40);
const finalItem = await store.getItem(itemId);
expect(finalItem.remainingStock).toBe(0);
});
SELECT ... FOR UPDATE) cleanly handle lock contention without unhandled database driver crashes.What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
50 skills in this plugin
/ask-mattAsk which skill or flow fits your situation. A router over the skills in this repo./brownfield-onboardSurvey an existing brownfield codebase, detect conflicting domain terminology, and bootstrap GLOSSARY.md and foundational ADRs./chief-of-staffPursue a long-running goal in a single session by co-ordinating subagents./claude-handoffHand the current conversation off to a fresh background agent that picks up the work immediately./codebase-designShared vocabulary for designing deep modules. Use when the user wants to design or improve a module's interface, find deepening opportunities, decide where a seam goes, make code more testable or AI-navigable, or when another skill needs the deep-module vocabulary./code-reviewReview the changes since a fixed point (commit, branch, tag, or merge-base) along three axes: Standards (does the code follow this repo's documented coding standards?), Spec (does the code match what the originating issue/spec asked for?), and Security (does the code protect authorization, concurrency, DTOs, and input validation?). Runs all reviews in parallel sub-agents and reports them side by side. Use when the user wants to review a branch, a PR, work-in-progress changes, or asks to "review since X".npx claudepluginhub op3616windows/superskills --plugin mattpocock-skills