agentleFS
kienbui1995kienbui1995/magic-powers/skills/api-contract-testing/SKILL.md

api-contract-testing

Skill0 starsChanged 8 months agoMITView on GitHub

Use when validating API schemas, detecting breaking changes, or setting up consumer-driven contract testing

3 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 3 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When multiple services or teams consume an API and you need to catch breaking changes before they reach production.

    line 9
  2. Distinctive:

    Use OpenAPI spec as the source of truth.

    line 19
  3. Very specific:

    Use tools: Spectral (OpenAPI linting), Optic, or Bump.sh for automated detection.

    line 47
  4. Distinctive:

    No contract tests — discovering breakage in production

    line 63

≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

API Contract Testing

When to Use

When multiple services or teams consume an API and you need to catch breaking changes before they reach production.

Core Jobs

1. Define the Contract

A contract = what the consumer expects:

  • Request format: method, path, required headers, body schema
  • Response format: status code, body schema, required fields
  • Error responses: what errors can occur, in what format

Use OpenAPI spec as the source of truth. Every endpoint must be documented.

2. Consumer-Driven Contract Testing (Pact)

Let consumers define what they expect:

# Consumer test (Python Pact)
@consumer('FrontendApp')
@provider('UserAPI')
def test_get_user(pact):
    pact.given('user 123 exists').upon_receiving('a request for user 123').with_request(
        method='GET', path='/api/v1/users/123'
    ).will_respond_with(200, body=Like({'id': '123', 'email': like('string')}))

Provider verifies it can satisfy all consumer contracts before deploying.

3. Breaking Change Detection

Breaking changes (always require major version bump):

  • Removing a field
  • Changing a field type
  • Changing an endpoint path
  • Making an optional field required
  • Changing error format

Non-breaking (safe to add):

  • Adding new optional fields
  • Adding new endpoints
  • Adding new optional parameters

Use tools: Spectral (OpenAPI linting), Optic, or Bump.sh for automated detection.

4. Contract Testing in CI

  • Consumer pushes contract to Pact Broker on test pass
  • Provider verifies contracts before merge
  • Deploy only when all consumer contracts pass

Key Outputs

  • OpenAPI spec (source of truth)
  • Consumer-driven contract tests (Pact or equivalent)
  • Breaking change detection CI step
  • Versioning policy

Anti-Patterns

  • Manual API documentation (drifts from implementation)
  • Breaking changes with no version bump
  • No contract tests — discovering breakage in production
  • Consumer contract tests only — provider never verifies

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.