Back to list
yonatangross

contract-testing

by yonatangross

The Complete AI Development Toolkit for Claude Code — 159 skills, 34 agents, 20 commands, 144 hooks. Production-ready patterns for FastAPI, React 19, LangGraph, security, and testing.

29🍴 4📅 Jan 23, 2026

SKILL.md


name: contract-testing description: Consumer-driven contract testing with Pact for API compatibility. Use when testing microservice integrations, verifying API contracts, preventing breaking changes, or implementing provider verification. context: fork agent: test-generator version: 1.0.0 tags: [pact, contract, consumer-driven, api, microservices, testing, 2026] author: OrchestKit user-invocable: false

Contract Testing with Pact

Ensure API compatibility between services with consumer-driven contracts.

Contract Testing vs Integration Testing

Integration TestingContract Testing
Requires all servicesEach service tests independently
Slow feedback loopFast feedback
Environment-dependentEnvironment-independent

Quick Reference

Consumer Test

from pact import Consumer, Provider, Like, EachLike

pact = Consumer("UserDashboard").has_pact_with(
    Provider("UserService"), pact_dir="./pacts"
)

def test_get_user(user_service):
    (
        user_service
        .given("a user with ID user-123 exists")
        .upon_receiving("a request to get user")
        .with_request("GET", "/api/users/user-123")
        .will_respond_with(200, body={
            "id": Like("user-123"),      # Any string
            "email": Like("test@example.com"),
        })
    )

    with user_service:
        client = UserServiceClient(base_url=user_service.uri)
        user = client.get_user("user-123")
        assert user.id == "user-123"

See consumer-tests.md for matchers and patterns.

Provider Verification

from pact import Verifier

def test_provider_honors_pact():
    verifier = Verifier(
        provider="UserService",
        provider_base_url="http://localhost:8000",
    )

    verifier.verify_with_broker(
        broker_url="https://pact-broker.example.com",
        consumer_version_selectors=[{"mainBranch": True}],
        publish_verification_results=True,
    )

See provider-verification.md for state setup.

Pact Broker CI/CD

# Publish consumer pacts
pact-broker publish ./pacts \
  --broker-base-url=$PACT_BROKER_URL \
  --consumer-app-version=$(git rev-parse HEAD)

# Check if safe to deploy
pact-broker can-i-deploy \
  --pacticipant=UserDashboard \
  --version=$(git rev-parse HEAD) \
  --to-environment=production

See pact-broker.md for CI/CD integration.

Key Decisions

DecisionRecommendation
Contract storagePact Broker (not git)
Consumer selectorsmainBranch + deployedOrReleased
Provider statesDedicated test endpoint
Verification timingAfter consumer publish
MatchersUse Like(), EachLike() for flexibility

Anti-Patterns (FORBIDDEN)

# NEVER specify exact values when structure matters
.will_respond_with(200, body={
    "id": "user-123",  # WRONG - too specific
})
# Use: "id": Like("user-123")

# NEVER test provider implementation details
.given("database has 5 rows")  # WRONG
# Use: "multiple users exist"

# NEVER skip provider state setup
.given("some state")  # Must be handled!

# NEVER commit pact files to git
# Use Pact Broker for versioning
  • integration-testing - API endpoint testing
  • api-design-framework - REST API design patterns
  • property-based-testing - Hypothesis integration

References

Capability Details

consumer-tests

Keywords: consumer, pact, expectations, mock server Solves: Write consumer-side tests, define expectations, generate pacts

provider-verification

Keywords: provider, verify, states, verification Solves: Verify provider honors contracts, set up provider states

pact-broker

Keywords: broker, can-i-deploy, publish, environments Solves: Share contracts, check deployment safety, manage versions

matchers

Keywords: Like, EachLike, Term, matching, flexible Solves: Write flexible expectations, match structure not values

message-contracts

Keywords: async, events, message, MessageConsumer Solves: Test async event contracts, verify event compatibility

Score

Total Score

75/100

Based on repository quality metrics

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

+10
説明文

100文字以上の説明がある

+10
人気

GitHub Stars 100以上

0/15
最近の活動

1ヶ月以内に更新

+10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

+5

Reviews

💬

Reviews coming soon