# API Contract CI

> Wires contract testing into CI/CD: broker pipelines, deploy gates, and breaking-change detection for every release. Use when working with ci integration, breaking change gates or when the user mentions ci integration, breaking change gates.

- Skill: `opknock/api-contract-ci` (Agent Skill)
- Install (CLI): `npx get-skill add opknock/api-contract-ci`
- Raw SKILL.md: https://api.skillmd.com/api/skills/opknock/api-contract-ci/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: DevOps & Infra
- License: MIT
- Author: OpKnock (https://skillmd.com/u/opknock)
- Updated: 2026-11-23
- Page: https://skillmd.com/skills/opknock/api-contract-ci

---


Wires contract testing into CI/CD: broker pipelines, deploy gates, and breaking-change detection for every release.

## Agentic Workflow: Read -> Reason -> Act (api-contract-ci)

You are **Api Contract Ci** (testing) — a sub-agent that **Reads, Reasons, and Acts** via `allowed-tools`.

### 1. Read — testing context for `api-contract-ci`
- Domain: Wires contract testing into CI/CD: broker pipelines, deploy gates, and breaking-change detection for every release.
- **ci-integration**: Add Pact publish, verify, and can-i-deploy steps to pipelines — `npx pact-broker publish ./pacts --consumer-version $BUILD_NUMBER --broker-base-u`
- **breaking-change-gates**: Block incompatible spec changes with automated diffs — `openapi-diff --fail-on-incompatible main.yaml pr.yaml`
- Check `knowledge` and `prerequisites: pact, openapi, node.js, python`

### 2. Reason — think for `api-contract-ci`
- For `ci-integration`: Add Pact publish, verify, and can-i-deploy steps to pipelines — decide which checks to run
- For `breaking-change-gates`: Block incompatible spec changes with automated diffs — decide which checks to run
- Evaluate trust/policy: `kdesk trust` + `kdesk doctor` patterns for your inputs

### 3. Act — execute with `api-contract-ci` tools
- Tools: `Glob`, `Grep`, `Read`, `Npx`, `Openapi-diff` (see frontmatter `tools`/`allowed-tools`)
- Use `safe_path` for any write; record evidence (paths, checksums)
- Fingerprint: `api-contract-ci:e92a68e4`

# API Contract (CI/CD)

Makes contract tests a release gate, not an afterthought.

## When to Use
- Releases break consumers silently
- Multiple teams share one API
- Need deploy-time confidence

## Real Commands

```bash
# In the consumer pipeline
npx pact-broker publish ./pacts --consumer-version $BUILD_NUMBER --broker-base-url http://localhost:9292

# In the provider pipeline
npx pact-provider-verifier --provider-base-url http://localhost:8080 --pact-broker-base-url http://localhost:9292 --provider api

# Gate the release
npx pact-broker can-i-deploy --pacticipant api --version $BUILD_NUMBER --to prod --broker-base-url http://localhost:9292

# Record the deployment
npx pact-broker record-deployment --pacticipant api --version $BUILD_NUMBER --environment prod --broker-base-url http://localhost:9292

# Spec diff gate
openapi-diff --fail-on-incompatible main.yaml pr.yaml
```

## Pipeline Layout
- Consumer: test, publish, can-i-deploy
- Provider: verify, can-i-deploy
- Release: record-deployment

## Testing
Break a contract on purpose and confirm the gate blocks the release.

## Best Practices
- Version every build
- Record deployments so the broker knows prod state

## Capabilities

### ci-integration
Add Pact publish, verify, and can-i-deploy steps to pipelines

**Parameters:**
- `broker` (string): Broker base URL
- `environment` (string): Deployment environment
- `buildNumber` (string): Build/version identifier

**Commands:**
- `npx pact-broker publish ./pacts --consumer-version $BUILD_NUMBER --broker-base-url http://localhost:9292`
- `npx pact-provider-verifier --provider-base-url http://localhost:8080 --pact-broker-base-url http://localhost:9292 --provider api --consumer-version-selector '{"branch":"main"}'`
- `npx pact-broker can-i-deploy --pacticipant api --version $BUILD_NUMBER --to prod --broker-base-url http://localhost:9292`
- `npx pact-broker record-deployment --pacticipant api --version $BUILD_NUMBER --environment prod --broker-base-url http://localhost:9292`
- `npx pact-broker list-environments --broker-base-url http://localhost:9292`

**Examples:**
- npx pact-broker publish ./pacts --consumer-version $BUILD_NUMBER --broker-base-url http://localhost:9292
- npx pact-broker can-i-deploy --pacticipant api --version $BUILD_NUMBER --to prod --broker-base-url http://localhost:9292
- npx pact-broker record-deployment --pacticipant api --version $BUILD_NUMBER --environment prod --broker-base-url http://localhost:9292

### breaking-change-gates
Block incompatible spec changes with automated diffs

**Parameters:**
- `base` (string): Baseline spec
- `candidate` (string): PR spec

**Commands:**
- `openapi-diff --fail-on-incompatible main.yaml pr.yaml`
- `git diff main.yaml pr.yaml --stat`
- `npx @stoplight/spectral-cli lint pr.yaml`
- `swagger-cli validate pr.yaml`
- `openapi-diff --fail-on-changed main.yaml pr.yaml`

**Examples:**
- openapi-diff --fail-on-incompatible main.yaml pr.yaml
- git diff main.yaml pr.yaml --stat && openapi-diff --fail-on-incompatible main.yaml pr.yaml
- swagger-cli validate pr.yaml && npx @stoplight/spectral-cli lint pr.yaml

## References
- [Pact Broker can-i-deploy](https://docs.pact.io/pact_broker/can_i_deploy)
- [Pact Broker Environments](https://docs.pact.io/pact_broker/recording_deployments)

