pact
Installation
Review the source and dependencies with a prompt. A package is available to download.
Install with an AI assistant
Copy the prompt so your assistant can review the pinned revision and dependencies first.
View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "pact" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-c8b1efb4d2c3797b65e19eb7cb187bb6861324ecdbaec6fc4364676e5515315e. Verify the upstream source and version against https://github.com/TerminalSkills/skills before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.
Source and setup
github.com
Setup guidance pending
See the original source for supported tools, dependencies, and permissions.
Installation test pending
Pact: A tool for implementing consumer-driven contract testing (CDC) between microservices. Use when creating or verifying contracts, working with a Pact Broker, or when users mention “pact,” “contract testing,” “consumer-driven contract,” “CDC test,” or “provider verification.” For API mocking, see mockoon or wiremock.
Introduction source: third_party · TerminalSkills · 1.0.0 Reference
SkillPi interpretation
- Tasks
- When the user wants to implement consumer-driven contract testing between microservices using Pact. Also use when the user mentions "pact," "contract testing," "consumer-driven contracts," "CDC testing," "provider verification," or "Pact Broker." For API mocking, see mockoon or wiremock.
- Testing
- Not tested
Browse files
Frontmatter
name: pact
description: When the user wants to implement consumer-driven contract testing between microservices using Pact. Also use when the user mentions "pact," "contract testing," "consumer-driven contracts," "CDC testing," "provider verification," or "Pact Broker." For API mocking, see mockoon or wiremock.
metadata:
author: terminal-skills
version: "1.0.0"
category: development
tags:
- contract-testing
- microservices
- consumer-driven
- api-testingPact
Overview
You are an expert in Pact, the consumer-driven contract testing framework. You help users write consumer tests that generate pact files, set up provider verification, configure a Pact Broker for sharing contracts, and integrate the "can-i-deploy" workflow into CI/CD pipelines. You understand the contract testing philosophy: consumers define what they need, providers verify they can deliver.
Instructions
Initial Assessment
- Architecture — Which services need contract testing?
- Language — JavaScript, Java, Python, Go, or .NET?
- Broker — Self-hosted Pact Broker or Pactflow (SaaS)?
- CI — How are services deployed? Independent pipelines?
Consumer Test (JavaScript)
// tests/consumer.pact.test.ts — Consumer-side Pact test.
// Defines what the consumer expects from the user-service API.
import { PactV3, MatchersV3 } from '@pact-foundation/pact';
import { resolve } from 'path';
import { UserApiClient } from '../src/api/userClient';
const { like, eachLike, string, integer } = MatchersV3;
const provider = new PactV3({
consumer: 'order-service',
provider: 'user-service',
dir: resolve(__dirname, '../pacts'),
});
describe('User API - Consumer Tests', () => {
it('should return user by ID', async () => {
await provider
.given('a user with ID 1 exists')
.uponReceiving('a request for user 1')
.withRequest({
method: 'GET',
path: '/api/users/1',
headers: { Accept: 'application/json' },
})
.willRespondWith({
status: 200,
headers: { 'Content-Type': 'application/json' },
body: like({
id: integer(1),
name: string('Jane Doe'),
email: string('jane@example.com'),
}),
})
.executeTest(async (mockServer) => {
const client = new UserApiClient(mockServer.url);
const user = await client.getUser(1);
expect(user.id).toBe(1);
expect(user.name).toBeDefined();
expect(user.email).toBeDefined();
});
});
it('should return 404 for non-existent user', async () => {
await provider
.given('no user with ID 999 exists')
.uponReceiving('a request for non-existent user')
.withRequest({
method: 'GET',
path: '/api/users/999',
})
.willRespondWith({
status: 404,
body: like({ error: string('User not found') }),
})
.executeTest(async (mockServer) => {
const client = new UserApiClient(mockServer.url);
await expect(client.getUser(999)).rejects.toThrow('User not found');
});
});
});
Provider Verification
// tests/provider.pact.test.ts — Provider-side verification test.
// Verifies that user-service fulfills the contracts from all consumers.
import { Verifier } from '@pact-foundation/pact';
import { resolve } from 'path';
import { startApp } from '../src/app';
describe('User Service - Provider Verification', () => {
let server: any;
beforeAll(async () => {
server = await startApp(3456);
});
afterAll(async () => {
await server.close();
});
it('should fulfill all consumer contracts', async () => {
const verifier = new Verifier({
providerBaseUrl: 'http://localhost:3456',
provider: 'user-service',
pactUrls: [resolve(__dirname, '../pacts/order-service-user-service.json')],
stateHandlers: {
'a user with ID 1 exists': async () => {
await seedDatabase({ id: 1, name: 'Jane Doe', email: 'jane@example.com' });
},
'no user with ID 999 exists': async () => {
await clearDatabase();
},
},
});
await verifier.verifyProvider();
});
});
Pact Broker Integration
// tests/provider-broker.pact.test.ts — Provider verification against Pact Broker.
// Fetches contracts from the broker instead of local files.
import { Verifier } from '@pact-foundation/pact';
const verifier = new Verifier({
providerBaseUrl: 'http://localhost:3456',
provider: 'user-service',
pactBrokerUrl: process.env.PACT_BROKER_BASE_URL,
pactBrokerToken: process.env.PACT_BROKER_TOKEN,
publishVerificationResult: process.env.CI === 'true',
providerVersion: process.env.GIT_COMMIT,
providerVersionBranch: process.env.GIT_BRANCH,
consumerVersionSelectors: [
{ mainBranch: true },
{ deployedOrReleased: true },
],
});
Can-I-Deploy
# can-i-deploy.sh — Check if it's safe to deploy a service.
# Queries the Pact Broker to verify all contracts are satisfied.
# Check if consumer can deploy
npx pact-broker can-i-deploy \
--pacticipant order-service \
--version $(git rev-parse HEAD) \
--to-environment production \
--broker-base-url $PACT_BROKER_BASE_URL \
--broker-token $PACT_BROKER_TOKEN
# Record deployment
npx pact-broker record-deployment \
--pacticipant order-service \
--version $(git rev-parse HEAD) \
--environment production \
--broker-base-url $PACT_BROKER_BASE_URL \
--broker-token $PACT_BROKER_TOKEN
CI Integration
# .github/workflows/pact-consumer.yml — Consumer contract test pipeline.
# Runs consumer tests, publishes pacts to broker, checks can-i-deploy.
name: Consumer Contract Tests
on: [push]
jobs:
pact:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npm test -- --testPathPattern=pact
- name: Publish pacts
run: |
npx pact-broker publish pacts/ \
--consumer-app-version ${{ github.sha }} \
--branch ${{ github.ref_name }} \
--broker-base-url ${{ secrets.PACT_BROKER_URL }} \
--broker-token ${{ secrets.PACT_BROKER_TOKEN }}
- name: Can I deploy?
run: |
npx pact-broker can-i-deploy \
--pacticipant order-service \
--version ${{ github.sha }} \
--to-environment production \
--broker-base-url ${{ secrets.PACT_BROKER_URL }} \
--broker-token ${{ secrets.PACT_BROKER_TOKEN }}Current listing version
1.0.0
Safety and assessment details
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Highlights
- 提供完整的 Pact 契约测试端到端解决方案
- 覆盖消费者测试、提供者验证、Broker 集成、CI/CD 全流程
- 针对微服务架构中的高频刚需场景
Highlights
- 触发词覆盖完整且边界清晰
- 明确区分 Pact 与 API 模拟工具的使用场景
Areas to improve
-
缺少 When to Use 显式章节 Reported severity: Minor
文档结构完整,但缺少显式的 When to Use 章节标题
Recommendation: 建议在 Overview 后添加显式的 When to Use 章节,提升可读性
Highlights
- Phase/步骤划分清晰完整
- 包含端到端完整可执行示例
- frontmatter 完整规范
Highlights
- 工具来源明确,参数配置正确
- 覆盖主要异常场景处理
- 包含完整的 CI/CD 集成方案
The arithmetic mean of the first four original scores, rounded to a whole number.
Static text checks
100 / 100 · skillpi-20261123-no-r3-v1
No current rules matched the text.
This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.
Permissions and checks before use
Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.
-
Install or fetch external dependencies
Use official sources and pin versions. Check install scripts in an isolated environment. This document check does not cover code downloaded later.
Mentioned in main document · lines 164, 172, 199, 206
Domains or addresses referenced in the document
These addresses may be documentation links or examples, not an approved network allowlist. Verify actual destinations and outgoing data before use.
- localhost
Security rating and access scope
safe · Static evidence review; not a runtime safety guarantee.
Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.
User discussion
No verified reviews yet.