---
name: contract-testing-pact
description: "Write and review consumer-provider contract tests (Pact style) for Kotlin/Java services: interactions, matchers, provider states and verification. Reads sources and pact JSON files. Use when writing consumer contracts or verifying a provider against them."
---
# Contract testing (Pact style)
## When to use
- "Write a consumer contract" or "verify the provider".
- The project uses `au.com.dius.pact` or has `*.pact.json` files.
- Hand-written HTTP mocks duplicate a contract.
- Services broke each other after a deployment.
## Agent flow
1. Identify the consumer, the provider and the interactions the consumer really uses.
2. Run `sh scripts/lint.sh <path>` over the contracts and tests.
3. Loosen matchers so the contract does not over-specify (see `references/checklist.md`).
4. Define provider states for every interaction.
5. Review the provider-side verification test.
6. Deliver a report and a plan to publish the contract locally. Never publish to a broker.
## Scripts
The scripts need only `sh`, `grep`, `sed`, `awk` and `find`; they work without building anything.
- `sh scripts/lint.sh <path>`: runs R01 and R05 on a file or directory.
- `awk -f scripts/r01.awk <file>`: literal date or UUID where a type matcher belongs.
- `sh scripts/r05.sh <path>`: contracts whose provider has no verification test.
Findings print as `file:line: RULE message`. Exit codes: 0 no findings, 1 findings, 2 usage error.
The scripts read files only and judge the user's own code.
— ‹guest · 2026-12-03› —
این نسخه با نشانهگذاری اختصاصی حساب شما نمایش داده میشود. برای نصب سریع، به تب نصب و راهاندازی بروید.