Contract Testing Pact
Contract testing validates that service consumers and providers agree on request/response expectations. Pact implements consumer-driven contracts (CDC) with shareable pact files and provider verificat
Best use case
Contract Testing Pact is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Contract testing validates that service consumers and providers agree on request/response expectations. Pact implements consumer-driven contracts (CDC) with shareable pact files and provider verificat
Teams using Contract Testing Pact should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/contract-testing-pact/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How Contract Testing Pact Compares
| Feature / Agent | Contract Testing Pact | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Contract testing validates that service consumers and providers agree on request/response expectations. Pact implements consumer-driven contracts (CDC) with shareable pact files and provider verificat
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# Contract Testing Pact
## Skill Profile
*(Select at least one profile to enable specific modules)*
- [ ] **DevOps**
- [x] **Backend**
- [ ] **Frontend**
- [ ] **AI-RAG**
- [ ] **Security Critical**
## Overview
Contract testing validates that service consumers and providers agree on request/response expectations. Pact implements consumer-driven contracts (CDC) with shareable pact files and provider verification, enabling teams to develop services independently while ensuring API compatibility.
## Why This Matters
Contract testing is critical for microservices because it:
- **Prevents breaking changes** by validating API expectations
- **Enables independent development** of consumer and provider services
- **Provides faster feedback** on API compatibility issues
- **Reduces integration surprises** by catching issues early
- **Documents API contracts** explicitly and versioned
- **Supports continuous delivery** with automated contract verification
---
## Core Concepts & Rules
### 1. Core Principles
- Follow established patterns and conventions
- Maintain consistency across codebase
- Document decisions and trade-offs
### 2. Implementation Guidelines
- Start with the simplest viable solution
- Iterate based on feedback and requirements
- Test thoroughly before deployment
## Inputs / Outputs / Contracts
#
## Skill Composition
* **Depends on**: None
* **Compatible with**: None
* **Conflicts with**: None
* **Related Skills**: None
## Quick Start / Implementation Example
1. Review requirements and constraints
2. Set up development environment
3. Implement core functionality following patterns
4. Write tests for critical paths
5. Run tests and fix issues
6. Document any deviations or decisions
```python
# Example implementation following best practices
def example_function():
# Your implementation here
pass
```
## Assumptions
- Teams can independently develop consumer and provider services
- Pact broker is accessible for publishing and retrieving contracts
- CI/CD pipeline is available for automated testing
- Services have defined API contracts
- Team has basic testing knowledge
## Compatibility & Prerequisites
* **Supported Versions**:
- Python 3.8+
- Node.js 16+
- Modern browsers (Chrome, Firefox, Safari, Edge)
* **Required AI Tools**:
- Code editor (VS Code recommended)
- Testing framework appropriate for language
- Version control (Git)
* **Dependencies**:
- Language-specific package manager
- Build tools
- Testing libraries
* **Environment Setup**:
- `.env.example` keys: `API_KEY`, `DATABASE_URL` (no values)
## Test Scenario Matrix (QA Strategy)
| Type | Focus Area | Required Scenarios / Mocks |
| :--- | :--- | :--- |
| **Unit** | Core Logic | Must cover primary logic and at least 3 edge/error cases. Target minimum 80% coverage |
| **Integration** | DB / API | All external API calls or database connections must be mocked during unit tests |
| **E2E** | User Journey | Critical user flows to test |
| **Performance** | Latency / Load | Benchmark requirements |
| **Security** | Vuln / Auth | SAST/DAST or dependency audit |
| **Frontend** | UX / A11y | Accessibility checklist (WCAG), Performance Budget (Lighthouse score) |
## Technical Guardrails & Security Threat Model
### 1. Security & Privacy (Threat Model)
* **Top Threats**: Injection attacks, authentication bypass, data exposure
- [ ] **Data Handling**: Sanitize all user inputs to prevent Injection attacks. Never log raw PII
- [ ] **Secrets Management**: No hardcoded API keys. Use Env Vars/Secrets Manager
- [ ] **Authorization**: Validate user permissions before state changes
### 2. Performance & Resources
- [ ] **Execution Efficiency**: Consider time complexity for algorithms
- [ ] **Memory Management**: Use streams/pagination for large data
- [ ] **Resource Cleanup**: Close DB connections/file handlers in finally blocks
### 3. Architecture & Scalability
- [ ] **Design Pattern**: Follow SOLID principles, use Dependency Injection
- [ ] **Modularity**: Decouple logic from UI/Frameworks
### 4. Observability & Reliability
- [ ] **Logging Standards**: Structured JSON, include trace IDs `request_id`
- [ ] **Metrics**: Track `error_rate`, `latency`, `queue_depth`
- [ ] **Error Handling**: Standardized error codes, no bare except
- [ ] **Observability Artifacts**:
- **Log Fields**: timestamp, level, message, request_id
- **Metrics**: request_count, error_count, response_time
- **Dashboards/Alerts**: High Error Rate > 5%
## Agent Directives
When implementing contract testing:
1. **Start with consumer tests** to define expectations
2. **Use flexible matchers** to avoid brittle tests
3. **Implement state handlers** for provider verification
4. **Publish pacts** to broker for sharing
5. **Verify pacts** in CI/CD pipeline
6. **Monitor compliance** and alert on failures
7. **Use pending pacts** for safe changes
## Definition of Done (DoD) Checklist
- [ ] Tests passed + coverage met
- [ ] Lint/Typecheck passed
- [ ] Logging/Metrics/Trace implemented
- [ ] Security checks passed
- [ ] Documentation/Changelog updated
- [ ] Accessibility/Performance requirements met (if frontend)
## Anti-patterns
1. **Over-specifying exact values**: Using exact matchers instead of flexible ones
2. **One contract for multiple cases**: Combining unrelated interactions
3. **Ignoring state handlers**: Not implementing proper test state setup
4. **Skipping verification**: Not verifying pacts in CI/CD
5. **Breaking changes without versioning**: Modifying contracts without versioning
6. **Ignoring pending pacts**: Not using pending pacts for safe changes
## Reference Links & Examples
* Internal documentation and examples
* Official documentation and best practices
* Community resources and discussions
## Versioning & Changelog
* **Version**: 1.0.0
* **Changelog**:
- 2026-02-22: Initial version with complete template structureRelated Skills
contract-review-pro
专业合同审核 Skill,基于《合同审核方法论体系》提供合同类型指引和详细审核服务
ai-powered-pentesting
Guide for AI-powered penetration testing tools, red teaming frameworks, and autonomous security agents.
add-bc-contract
Add Contract for inter-BC communication using Provider pattern. Use when one Bounded Context needs to access data from another BC (e.g., Inventory needs Articles from Admin). Creates Contract interface, Provider implementation, and configuration.
ab-testing-analyzer
全面的AB测试分析工具,支持实验设计、统计检验、用户分群分析和可视化报告生成。用于分析产品改版、营销活动、功能优化等AB测试结果,提供统计显著性检验和深度洞察。
cli-e2e-testing
CLI E2E testing patterns with BATS - parallelization, state sharing, and timeout management
bats-testing-patterns
Comprehensive guide for writing shell script tests using Bats (Bash Automated Testing System). Use when writing or improving tests for Bash/shell scripts, creating test fixtures, mocking commands, or setting up CI/CD for shell script testing. Includes patterns for assertions, setup/teardown, mocking, fixtures, and integration with GitHub Actions.
adb-device-testing
Use when testing Android apps on ADB-connected devices/emulators - UI automation, screenshots, location spoofing, navigation, app management. Triggers on ADB, emulator, Android testing, location mock, UI test, screenshot walkthrough.
u01874-handoff-contracting-for-marketing-and-storytelling
Operate the "Handoff Contracting for marketing and storytelling" capability in production for marketing and storytelling workflows. Use when mission execution explicitly requires this capability and outcomes must be reproducible, policy-gated, and handoff-ready.
sqlmap-database-pentesting
This skill should be used when the user asks to "automate SQL injection testing," "enumerate database structure," "extract database credentials using sqlmap," "dump tables and columns...
sql-injection-testing
This skill should be used when the user asks to "test for SQL injection vulnerabilities", "perform SQLi attacks", "bypass authentication using SQL injection", "extract database inform...
Smart Contracts
Smart contracts are self-executing programs on blockchain. This guide covers Solidity basics, contract deployment, interaction, and frontend integration for building decentralized applications with au
Schema Evolution Impact Analysis
Analyze the impact of model/schema changes on downstream code — affected repositories, services, handlers, tests, and migration requirements