contract-testing
Skill9 starsChanged 5 months agoApache-2.0View on GitHub
Implements consumer-driven contract testing so services deploy independently without a full integration environment — the consumer's unit tests record concrete request/response expectations against a stub (Pact `pact-jvm`/`pact-js`/`pact-python`, or Spring Cloud Contract DSL), the resulting contract (pact file / Spring stub jar) is published to a broker (Pact Broker / PactFlow) tagged by consumer version + branch + environment, the provider replays every expectation against its real app in CI with provider states (`@State` / `Given`) seeding data, and `pact-broker can-i-deploy --pacticipant X --version <git-sha> --to-environment production` gates the pipeline — plus webhook-triggered provider verification on contract change, bi-directional contracts (verify a provider's OpenAPI against consumer pacts without running the provider), pending/WIP pacts so a new consumer expectation never breaks the provider build, and version pinning via the consumer's git SHA with `record-deployment`/`record-release`.
3 other projects use a version of this.
Adopted by
Most recently taken up by
- mejbaurbahar/faguntheir own version, first seen Jul 5, 2026
- roanbrasil/engineer-grade-agent-skillstheir own version, first seen Jun 17, 2026
- petrkindlmann/qa-skillstheir own version, first seen Mar 23, 2026
Other versions3 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 3
- petrkindlmann/qa-skills★ 160same name
- roanbrasil/engineer-grade-agent-skills★ 8same name
- mejbaurbahar/fagun★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository147 other files it gives its agents.
- second-brain/AGENTS.mdAGENTS.md
- second-brain/CLAUDE.mdCLAUDE.md
- agent-tool-mcp-builderSkill
- api-design-reviewSkill
- async-concurrency-correctnessSkill
- audit-accessibility-wcagSkill
- audit-license-complianceSkill
- audit-technical-seoSkill
- auth-jwt-sessionSkill
- author-codemodSkill
- brainstorm-designSkill
- build-audit-loggingSkill
- build-cdc-streaming-pipelineSkill
- build-cli-toolSkill
- build-data-tableSkill
- build-etl-pipelineSkill
- build-form-validationSkill
- build-native-mobile-uiSkill
- build-office-docsSkill
- build-offline-first-syncSkill
- build-react-componentSkill
- build-realtime-channelSkill
- build-spreadsheetSkill
- build-vector-searchSkill
- caching-strategySkill
- cicd-pipeline-authorSkill
- cloud-cost-optimizeSkill
- code-commentsSkill
- code-reviewSkill
- compose-local-dev-stackSkill
- configure-bundler-buildSkill
- configure-dns-tlsSkill
- configure-reverse-proxy-lbSkill
- configure-security-headers-cspSkill
- datetime-timezone-correctnessSkill
- db-migration-safetySkill
- debug-ci-pipeline-failureSkill
- debug-flaky-testsSkill
- debug-frontend-browserSkill
- debug-root-causeSkill
- defend-llm-prompt-injectionSkill
- deliver-webhooksSkill
- dependency-upgradeSkill
- deploy-releaseSkill
- design-api-paginationSkill
- design-authorization-modelSkill
- design-backup-dr-recoverySkill
- design-event-sourcing-cqrsSkill
- design-multi-tenancySkill
- design-protobuf-grpc-serviceSkill
- design-relational-schemaSkill
- design-search-index-infraSkill
- design-state-machineSkill
- design-token-systemSkill
- diff-table-paritySkill
- distributed-locks-leasesSkill
- dockerfile-optimizeSkill
- encrypt-sensitive-dataSkill
- error-messageSkill
- estimate-workSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
4 rules. 0 are common, 2 are distinctive, and 2 are very specific to this project.
0
Common
Most of the 3 edited versions we read keep these.
2
Distinctive
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 38
Default to consumer-driven Pact for polyglot HTTP/message estates.
- Very specific: line 106
Use record-deployment for environments you replace-in-place (one version live), record-release/record-support-ended for things like mobile …
- Distinctive: line 134
Additive change is safe: add a new optional field on the provider → consumer pact still verifies green and can-i-deploy passes (proves …
- Very specific: line 136
Versions are git SHAs: every publish/verify/record uses git rev-parse versions.
“Common” is measured: kept by at least 6 in 10 of the 3 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
When to Use
Reach for this skill when two or more independently deployed services integrate and you want integration confidence at unit-test speed, not via a fragile end-to-end stack:
- "Provider changed a field and a consumer broke in prod — catch it in CI before merge"
- "Our shared staging/E2E env is flaky and slow; we want to test integration without it"
- "Add Pact / Spring Cloud Contract between our frontend/BFF and the API"
- "Gate the deploy: don't ship the provider until every consumer's contract still passes"
- "We already have an OpenAPI spec — verify the provider matches it AND the consumers (bi-directional)"
- "A new consumer's expectation shouldn't be able to red the provider's build (pending pacts)"
- "Mobile app v3 is still live; how do we know the provider didn't drop a field v3 needs?"
NOT this skill:
- Authoring the API spec/schema (OpenAPI, GraphQL SDL, JSON Schema, field types, pagination shape) → rest-graphql-contract (defines what the API is; this skill proves two running versions agree on it)
- The back/forward-compatibility rules (additive-only, never-remove-required, default-on-new-optional) → schema-evolution-compatibility (the policy; this skill is the per-pair CI enforcement of it)
- gRPC/protobuf service definition and codegen → design-protobuf-grpc-service (you can still Pact-test gRPC via message pacts, but the
.protoitself lives there) - General API design / breaking-change review of a diff → api-design-review
- Browser/UI end-to-end flows across the whole app → write-playwright-e2e (this skill replaces most cross-service E2E with isolated pair contracts)
- Structuring the unit-test suite itself / assertions / fixtures → write-tests, test-data-factories (this skill specifies the contract interactions; those build the surrounding suite/data)
- Wiring the CI stages / runners / caching → cicd-pipeline-author; the deploy gate's release flow → deploy-release (this skill supplies the can-i-deploy check those stages run)
Steps
Pick consumer-driven (Pact) when consumers know what they need; bi-directional/spec-driven when the provider already owns an OpenAPI/GraphQL spec. They are not interchangeable:
Approach How it works Use when Limitation Consumer-driven (Pact) consumer's tests generate expectations; provider replays them against the real app consumers drive the API; you want to know exactly which fields are used provider must run verification against real code; needs provider states Bi-directional (PactFlow) provider's OpenAPI is verified as a "provider contract"; consumer pacts compared statically against it — provider need not run provider already has a trustworthy spec; can't run full provider verification only as good as the spec; a spec that lies passes Spring Cloud Contract contracts in Groovy/YAML DSL live with the provider; generate provider tests + a stub jar consumers run against JVM-heavy estate, provider-owned contracts, message + HTTP JVM-centric; less natural for polyglot consumers Default to consumer-driven Pact for polyglot HTTP/message estates; Spring Cloud Contract for an all-JVM shop; add bi-directional when a provider can't feasibly run verification but has a real OpenAPI.
Write the consumer test against a Pact mock — assert on the request you send and matchers (not literals) for the response. The consumer test spins up Pact's local mock server, you exercise your real client code against it, and Pact records the interaction. Use matchers so the contract pins structure/type, not brittle example values:
// pact-js v3+ (V3/V4 spec) const { PactV3, MatchersV3: M } = require('@pact-foundation/pact'); const provider = new PactV3({ consumer: 'web-bff', provider: 'orders-api' }); provider .given('order 42 exists') // provider state — seeds data later .uponReceiving('a request for order 42') .withRequest({ method: 'GET', path: '/orders/42', headers: { Accept: 'application/json' } }) .willRespondWith({ status: 200, headers: { 'Content-Type': M.regex('application/json.*', 'application/json') }, body: { id: M.integer(42), total: M.decimal(19.99), status: M.regex('PAID|PENDING', 'PAID'), items: M.eachLike({ sku: M.string('ABC'), qty: M.integer(1) }) } }); await provider.executeTest(mock => new OrdersClient(mock.url).getOrder(42));Rules: assert only on fields the consumer actually reads (Pact verifies the provider returns at least these — extra provider fields are fine; that's how providers stay free to add). Use
integer/decimal/string/regex/eachLike/like, never hardcoded values, or any data change reds the provider. Onegiven(...)per distinct precondition; the string must match a provider state handler exactly.- Run the consumer test in normal unit CI; it emits a pact JSON file as a side effect — there is no provider involved here.
npm test/mvn test/pytestproducespacts/web-bff-orders-api.json. This runs at unit speed, no network, no provider deployed. The pact file is the deliverable. Publish the pact to a broker, tagged with the consumer's git SHA + branch + (later) environments. The broker is the exchange point; never email pact files around.
pact-broker publish ./pacts \ --consumer-app-version $(git rev-parse --short HEAD) \ --branch $GIT_BRANCH \ --broker-base-url $PACT_BROKER_URL --broker-token $PACT_BROKER_TOKENVersion MUST be the git SHA (or
<semver>+<sha>), not a timestamp or "latest" — can-i-deploy reasons about specific versions, and a non-unique version corrupts the matrix.--branchenables WIP/pending-pact selection. Self-host the OSS Pact Broker (Docker, Postgres-backed) or use hosted PactFlow (adds bi-directional + WIP UI).Provider verification: replay every consumer's pact against the real running provider, seeding data via provider-state handlers. The provider pulls pacts from the broker by consumer version selectors (not "all pacts ever") and runs them against a real instance:
// pact-jvm JUnit5 @Provider("orders-api") @PactBroker(url="${PACT_BROKER_URL}", selectors = { @VersionSelector(deployedOrReleased = true), // pacts live in any env @VersionSelector(mainBranch = true) }) // + main branch class OrdersApiPactTest { @State("order 42 exists") // matches given(...) string EXACTLY void seedOrder42() { db.insertOrder(42, "PAID"); } // arrange real data @TestTemplate @ExtendWith(PactVerificationInvocationContextProvider.class) void verify(PactVerificationContext ctx) { ctx.verifyInteraction(); } }Verify against the real app + a test DB, not mocks — the point is to prove the actual provider satisfies the expectation.
@Statehandlers are mandatory and must be idempotent; they set up exactly the data the interaction needs and clean up after. A missing/misnamed state handler fails verification with "state not found".- Publish verification results back to the broker so the matrix is complete on both sides. Set
pact.verifier.publishResults=true(pact-jvm) /publishVerificationResult: true(pact-js) only in CI, keyed to the provider's git SHA. This is what lets can-i-deploy answer "has provider@sha verified consumer@sha?" — without it the matrix has holes and the gate fails open or stuck. Gate every deploy with
can-i-deployagainst the target environment — this is the whole payoff. Before shipping either side, ask the broker whether this version is compatible with everything currently in the target env:pact-broker can-i-deploy \ --pacticipant orders-api --version $(git rev-parse --short HEAD) \ --to-environment production --retry-while-unknown 30 --retry-interval 10 # exit 0 = safe to deploy; non-zero = a consumer in prod would break → fail the stage--retry-while-unknownwaits for in-flight verifications instead of failing on a race. After a successful deploy, record it so the matrix tracks what's live:pact-broker record-deployment --pacticipant orders-api \ --version $(git rev-parse --short HEAD) --environment productionUse
record-deploymentfor environments you replace-in-place (one version live),record-release/record-support-endedfor things like mobile apps where multiple versions are live at once — that's how you stop the provider dropping a field old app builds still need.- Trigger provider re-verification automatically on contract change via broker webhooks. Configure a broker webhook on
contract_content_changed/contract_requiring_verification_publishedto POST to the provider's CI (GitHub Actionsrepository_dispatch, GitLab pipeline trigger). New consumer expectation published → provider pipeline runs verification → result published → consumer's can-i-deploy unblocks. Without this the loop is manual and contracts rot. - Use pending pacts + WIP pacts so a new/changed consumer expectation can't red the provider's main build. Enable
enablePending: trueandincludeWipPactsSince: <date>in the provider's selectors. A brand-new consumer expectation is verified but reported as pending — failures are visible but non-blocking for the provider — until it verifies green once, at which point it becomes blocking. This decouples teams: a consumer can publish a forward-looking contract without breaking the provider's release, and the provider opts in when ready. Pair with branch-based selectors so you verify againstmain+deployedOrReleased, not every stale feature-branch pact. - For async/messaging, use message pacts; for the provider's own spec, optionally add a bi-directional contract. Message pacts: the consumer asserts on a message body it can handle (no HTTP mock); the provider verifies its producer function emits a matching message — same broker, same can-i-deploy. Bi-directional: publish the provider's OpenAPI as a provider contract (
pactflow-cli publish-provider-contract openapi.yaml); PactFlow statically cross-validates consumer pacts against it, so the provider needn't run verification — accept the tradeoff that a wrong spec passes (mitigate by also asserting the spec in the provider's own tests).
Common Errors
- Asserting on literal example values instead of matchers. Hardcoding
total: 19.99means any data change reds provider verification. Fix:M.decimal()/integer()/regex()/eachLike()— pin type/structure, not the example. - Consumer over-specifies fields it doesn't use. Asserting on every response field couples you to the provider's full shape and blocks its additive changes. Fix: assert only the fields the consumer reads; extra provider fields must pass.
- Provider state string ≠
@State/Givenhandler.given('order exists')vs@State("order 42 exists")→ "no state handler" verification failure. Fix: keep the strings byte-identical; treat them as a shared contract. - Verifying the provider against mocks/in-memory stubs. Defeats the purpose — you prove the mock matches, not the real app. Fix: run verification against the real provider + test DB seeded by state handlers.
- Versioning pacts with
latest/timestamps instead of the git SHA. can-i-deploy's matrix needs unique, reproducible versions; "latest" makes the gate meaningless. Fix:--consumer-app-version <git-sha>, branch via--branch. - Not publishing verification results (or publishing from local dev). Holes in the matrix → can-i-deploy can't answer → gate fails open or hangs. Fix: publish results only from CI, keyed to the provider SHA.
- Skipping can-i-deploy and just deploying. Contracts that aren't gated provide false safety. Fix: make can-i-deploy a required pipeline stage that fails the deploy on non-zero exit; add
record-deploymentafter. - No pending pacts → new consumer expectation reds the provider main build. Teams get blocked on each other and disable Pact in frustration. Fix:
enablePending+ WIP pacts; new expectations are non-blocking until first green. - Treating Pact as full-coverage E2E. Pact verifies the request/response shape per interaction, not business correctness or multi-hop flows. Fix: keep a thin layer of true E2E for critical journeys; Pact replaces the broad, flaky middle.
- Forgetting multi-version providers (mobile).
record-deploymentassumes one live version; old app builds still in the wild get dropped. Fix:record-release/record-support-endedso can-i-deploy keeps every supported app version in the matrix. - Webhook not configured → manual verification loop. Contracts published but provider never re-verifies, so the broker shows stale green. Fix:
contract_requiring_verification_publishedwebhook → provider CI dispatch.
Verify
- Consumer test produces a pact at unit speed: running the consumer suite emits
pacts/<consumer>-<provider>.jsonwith matchers (not literals), no provider or network involved. - Provider verification replays real interactions: the provider's verification task pulls pacts from the broker, runs against the real app + seeded DB via every
@State/Givenhandler, and all interactions pass (or are explicitly pending). - Matrix is complete both ways: the broker shows the consumer pact and a published verification result for the provider's version — no "unverified" holes.
- Gate actually blocks: introduce a breaking provider change (drop/rename a consumed field), run
can-i-deploy --to-environment production→ it exits non-zero and the deploy stage fails; revert → exit 0. - Additive change is safe: add a new optional field on the provider → consumer pact still verifies green and can-i-deploy passes (proves extra fields don't break consumers).
- Pending pacts don't red main: publish a new consumer expectation the provider doesn't yet satisfy → provider build reports it pending/non-blocking, not failed; once provider implements it and verifies, it becomes blocking.
- Versions are git SHAs: every publish/verify/record uses
git rev-parseversions; grep CI forlatest/timestamp versions and remove them. - Webhook closes the loop: publishing a changed contract auto-triggers the provider's verification pipeline; the broker reflects the fresh result without manual intervention.
- Multi-version handled (if applicable):
record-releasekeeps every supported mobile/app version in the matrix; can-i-deploy refuses a provider change that breaks any still-supported version.
Done = consumers generate matcher-based pacts at unit speed, the provider replays them against the real app with idempotent state handlers, verification results and deployments are recorded to the broker keyed by git SHA, every deploy is gated by can-i-deploy against the target environment, new expectations land as non-blocking pending pacts, and contract changes auto-trigger provider re-verification via webhook — proven by the breaking-change-blocks / additive-change-passes / pending-doesn't-red tests in checks 4–6.
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
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.

