contract-testing-builder
БесплатноБез исполняемых скриптовНе проверенImplements API contract testing to ensure provider-consumer compatibility using Pact or similar tools. Prevents breaking changes with contract specifications…
от patricio0312rev★ 64 звезды на GitHubОб этом скилле
Contract Testing Builder
Ensure API contracts don't break consumers.
Contract Testing Concepts
Consumer → Defines expected contract → Provider must satisfy
Benefits:
- Catch breaking changes early
- Independent development
- Fast feedback (no integration env needed)
- Documentation as code
Pact Setup (Consumer Side)
// consumer/tests/pacts/user-api.pact.test.ts
import { PactV3 } from "@pact-foundation/pact";
import { userApi } from "../api/userApi";
const provider = new PactV3({
consumer: "UserWebApp",
provider: "UserAPI",
dir: path.resolve(__dirname, "../../pacts"),
});
describe("User API Contract", () => {
it("should get user by ID", async () => {
// Define expected interaction
await provider
.given("user 123 exists")
.uponReceiving("a request for user 123")
.withRequest({
method: "GET",
path: "/api/users/123",
headers: {
Authorization: "Bearer token123",
},
})
.willRespondWith({
status: 200,
headers: {
"Content-Type": "application/json",
},
body: {
id: "123",
email: "[email protected]",
name: "John Doe",
role: "USER",
createdAt: like("2024-01-01T00:00:00Z"),
},
})
.executeTest(async (mockServer) => {
// Make actual API call against mock server
const user = await userApi.getUser("123", mockServer.url);
// Verify consumer can handle response
expect(user.id).toBe("123");
expect(user.email).toBe("[email protected]");
});
});
it("should return 404 when user not found", async () => {
await provider
.given("user 999 does not exist")
.uponReceiving("a request for non-existent user")
.withRequest({
method: "GET",
path: "/api/users/999",
})
.willRespondWith({
status: 404,
headers: {
"Content-Type": "application/json",
},
body: {
error: "User not found",
},
})
.executeTest(async (mockServer) => {
await expect(userApi.getUser("999", mockServer.url)).rejects.toThrow(
"User not found"
);
});
});
});
Pact Verification (Provider Side)
// provider/tests/pacts/verify.test.ts
import { Verifier } from "@pact-foundation/pact";
import { app } from "../src/app";
describe("Pact Verification", () => {
let server: Server;
beforeAll(async () => {
server = app.listen(3000);
});
afterAll(() => {
server.close();
});
it("should validate consumer contracts", async () => {
const verifier = new Verifier({
provider: "UserAPI",
providerBaseUrl: "http://localhost:3000",
// Fetch pacts from broker or local files
pactUrls: [
path.resolve(__dirname, "../../pacts/UserWebApp-UserAPI.json"),
],
// Provider states setup
stateHandlers: {
"user 123 exists": async () => {
// Seed database with user 123
await db.user.create({
id: "123",
email: "[email protected]",
name: "John Doe",
role: "USER",
});
},
"user 999 does not exist": async () => {
// Ensure user 999 doesn't exist
await db.user.deleteMany({ where: { id: "999" } });
},
},
// Teardown after each test
afterEach: async () => {
await db.$executeRaw`TRUNCATE TABLE users CASCADE`;
},
});
await verifier.verifyProvider();
});
});
OpenAPI Contract Testing
# contracts/user-api.yaml
openapi: 3.0.0
info:
title: User API
version: 1.0.0
paths:
/api/users/{id}:
get:
parameters:
- name: id
in: path
required: true
schema:
type: string
responses:
"200":
description: User found
content:
application/json:
schema:
$ref: "#/components/schemas/User"
"404":
description: User not found
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
components:
schemas:
User:
type: object
required:
- id
- email
- name
- role
properties:
id:
type: string
email:
type: string
format: email
name:
type: string
role:
type: string
enum: [USER, ADMIN]
createdAt:
type: string
format: date-time
Contract Validation (OpenAPI)
// tests/contract-validation.test.ts
import * as OpenAPIValidator from "express-openapi-validator";
import * as fs from "fs";
import * as yaml from "js-yaml";
describe("API Contract Validation", () => {
it("should match OpenAPI spec", async () => {
const spec = yaml.
Установить contract-testing-builder в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл contract-testing-builder?
Implements API contract testing to ensure provider-consumer compatibility using Pact or similar tools. Prevents breaking changes with contract specifications and bi-directional verification. Use for "contract testing", "API contracts", "Pact", or "consumer-driven contracts".
Как установить скилл contract-testing-builder?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл contract-testing-builder запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic