Skills DirectorySkills Directory
SkillsLearnSecurityCategoriesDocsBlogPro
Sign InSubmit Skill
Skills Directory

Security-tested agent skills for Claude, coding agents, and AI workflows.

Directory

  • Browse Skills
  • All Skills A–Z
  • Claude Skills
  • Claude Code Skills
  • Agent Skills
  • Categories
  • Authors
  • Submit a Skill

Learn

  • Learn Hub
  • Install Claude Skills
  • Write SKILL.md
  • Skills vs MCP
  • Directories Compared

Security

  • Security
  • Methodology
  • Secure Claude Skills
  • Security Badges
  • Chrome Extension
  • Skill Manager

Company

  • About
  • Community
  • Blog
  • API Docs
  • Advertise

2026 Skills Directory. All rights reserved.

ProTermsPrivacyRefunds
Back to skills

Api Contract Testing

ASecurity

Playbook for implementing consumer-driven contract tests (Pact) between backend services so API contract breaks surface in CI before they reach integration environments.

7 stars
0 votes
0 copies
0 views
Added 9/23/2026
ai-agentspythonbashdockertestinggitapibackend

Works with

api

Security Analysis

A100/100

Scanned 9/23/2026

$npx -y skills add mcorbett51090/RavenClaude --skill api-contract-testing --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Api Contract Testing?

Add the live security badge to your README — it updates automatically with every re-scan.

Security grade badge for Api Contract Testing
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/mcorbett51090-api-contract-testing/badge)](https://www.skillsdirectory.com/skills/mcorbett51090-api-contract-testing)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
Files
SKILL.md
---
name: api-contract-testing
description: "Playbook for implementing consumer-driven contract tests (Pact) between backend services so API contract breaks surface in CI before they reach integration environments."
---

# API Contract Testing

## When to invoke

Use when two or more services communicate over HTTP/messaging and you want to catch contract breaks (missing fields, changed types, removed endpoints) in the individual service's CI pipeline rather than in a shared integration environment.

## Concepts in 30 seconds

| Term | Meaning |
|---|---|
| Consumer | The service that calls the API |
| Provider | The service that serves the API |
| Pact | A JSON file of recorded interactions the consumer depends on |
| Pact Broker | Central registry that matches consumers to providers |
| Verification | Provider re-runs each pact interaction against its real code |

## Step 1 — Consumer writes the pact

In the consumer's test suite (using the Pact SDK for your language):

```python
# Python example (pact-python)
pact = Consumer("order-service").has_pact_with(Provider("inventory-service"))

(pact
 .given("item SKU-99 exists in inventory")
 .upon_receiving("a stock-check request")
 .with_request(method="GET", path="/inventory/SKU-99")
 .will_respond_with(
     status=200,
     body={"sku": "SKU-99", "quantity": Like(10)},  # Like = type-only match
 ))
```

Key matchers:
- `Like(value)` — type only (any integer, not exactly 10)
- `EachLike(template)` — non-empty array of matching elements
- `Term(regex, example)` — value matches regex

Commit the generated `pact.json` to the Pact Broker in the consumer CI job.

## Step 2 — Provider verifies

In the provider's test suite, replay every known pact against the real application (started in-process or via Docker):

```python
# provider verification (pytest-pact)
@pytest.fixture
def provider_opts():
    return {
        "provider": "inventory-service",
        "pact_broker_url": os.environ["PACT_BROKER_URL"],
        "publish_verification_results": True,
        "provider_version": os.environ["GIT_SHA"],
    }
```

The provider CI job fetches all consumer pacts, runs each interaction, and publishes a pass/fail result. **A failed verification blocks the provider's deploy.**

## Step 3 — Can-I-Deploy gate

Before any deploy, query the Broker:

```bash
pact-broker can-i-deploy \
  --pacticipant inventory-service \
  --version $GIT_SHA \
  --to-environment production
```

Returns exit 0 only if every consumer whose pact is marked "required for production" has a passing verification against this provider version. Wire this as a required CI step before the deploy job.

## Step 4 — Provider states (test data setup)

Provider state handlers set up the preconditions described in `given(...)`:

```python
@provider_state("item SKU-99 exists in inventory")
def setup_sku99():
    db.seed(sku="SKU-99", quantity=10)

@provider_state("item SKU-99 is out of stock")
def setup_sku99_oos():
    db.seed(sku="SKU-99", quantity=0)
```

Keep states minimal — only what the consumer interaction needs, not a full fixture set.

## Decision: Pact vs schema sharing vs integration tests

| Approach | Catches contract break in | Team coupling |
|---|---|---|
| Pact (consumer-driven) | Each service's CI | Consumer drives the spec |
| Shared OpenAPI schema | PR lint | Both teams must coordinate |
| Integration environment | Shared test run | Slowest, most flaky |

Use Pact when teams deploy independently. Use schema sharing as a complement (not a replacement) — the schema documents intent; the pact proves the consumer's actual usage.

## Pitfalls

- **Over-specifying the pact body** — using exact-match on every field means any additive change by the provider fails the pact, even though the consumer doesn't care. Use `Like` and `EachLike` for fields the consumer doesn't depend on.
- **Skipping provider states** — without state setup, the provider can't reproduce the scenario and the test is meaningless noise.
- **Not publishing verification results** — the can-i-deploy gate only works when results are in the Broker; a provider that verifies locally but doesn't publish blocks nothing.
- **One monolith pact** — a single pact for an entire consumer tests too much; split by interaction group so a single-field change shows exactly what broke.

Attribution

mcorbett51090mcorbett51090
View sourceSee grades on GitHubMore from mcorbett51090 →
SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments (0)

No comments yet. Be the first to comment!

SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Related Skills

Caveman

Terse caveman voice: answer first, fluff gone, every technical fact kept. Use for /caveman, "caveman mode", "talk like caveman", "be brief", "less tokens". Stays on until "stop caveman" or "normal mode".

1100021 votes

Hyperplan

Adversarial multi-agent planning skill. Self-orchestrates 5 hostile category members (unspecified-low, unspecified-high, deep, ultrabrain, artistry) via team-mode for ruthless cross-critique debate, distills only the defensible insights, then MANDATORILY hands the distilled insight bundle to the `plan` agent for executable plan formalization. Use when planning needs maximum rigor and surfacing of weak assumptions, blind spots, and over-engineering. Triggers: 'hyperplan', 'hpp', '/hyperplan', ...

698431 votes

Writing Skills

Create and manage Claude Code skills in HASH repository following Anthropic best practices. Use when creating new skills, modifying skill-rules.json, understanding trigger patterns, working with hooks, debugging skill activation, or implementing progressive disclosure. Covers skill structure, YAML frontmatter, trigger types (keywords, intent patterns), UserPromptSubmit hook, and the 500-line rule. Includes validation and debugging with SKILL_DEBUG. Examples include rust-error-stack, cargo-dep...

3931 votes

Mcp Code Execution

Routes multi-tool workflows through MCP servers for large datasets and pipelines. Use when Bash tool overhead is limiting throughput on data-heavy tasks.

3421 votes

catchup

Recovers the conversation and failed tool calls of a previous Codex, Amp, Claude Code, Antigravity, Cline, Copilot CLI, Cursor, DeepSeek Harness, Grok Build, Kimi, OpenCode, Pi Agent, or ZCode session. Use when the user says "catch up", "what did the last session do", "get me up to speed", "I switched agents", asks to recover/summarize a previous session before continuing, or asks to diagnose or report a catchup failure. Do NOT use for the current conversation, git history, or any non-agent log.

741 votes
View all in ai-agents →