home / skills / proffesor-for-testing / agentic-qe / qe-contract-testing

qe-contract-testing skill

/v3/assets/skills/qe-contract-testing

This skill guides consumer-driven contract testing and schema validation across REST, GraphQL, and event schemas to ensure compatibility.

npx playbooks add skill proffesor-for-testing/agentic-qe --skill qe-contract-testing

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
4.6 KB
---
name: "QE Contract Testing"
description: "Consumer-driven contract testing for APIs including REST, GraphQL, and event-driven systems with schema validation."
---

# QE Contract Testing

## Purpose

Guide the use of v3's contract testing capabilities including consumer-driven contracts, schema validation, backward compatibility checking, and API versioning verification.

## Activation

- When testing API contracts
- When validating schema changes
- When checking backward compatibility
- When testing GraphQL APIs
- When verifying event schemas

## Quick Start

```bash
# Generate contract from API
aqe contract generate --api openapi.yaml --output contracts/

# Verify provider against contracts
aqe contract verify --provider http://localhost:3000 --contracts contracts/

# Check breaking changes
aqe contract breaking --old api-v1.yaml --new api-v2.yaml

# Test GraphQL schema
aqe contract graphql --schema schema.graphql --operations queries/
```

## Agent Workflow

```typescript
// Contract generation
Task("Generate API contracts", `
  Analyze the REST API and generate consumer contracts:
  - Parse OpenAPI specification
  - Identify critical endpoints
  - Generate Pact contracts
  - Include example requests/responses
  Output to contracts/ directory.
`, "qe-api-contract")

// Breaking change detection
Task("Check API compatibility", `
  Compare API v2.0 against v1.0:
  - Detect removed endpoints
  - Check parameter changes
  - Verify response schema changes
  - Identify deprecations
  Report breaking vs non-breaking changes.
`, "qe-api-compatibility")
```

## Contract Testing Types

### 1. Consumer-Driven Contracts (Pact)

```typescript
await contractTester.consumerDriven({
  consumer: 'web-app',
  provider: 'user-service',
  contracts: 'contracts/web-app-user-service.json',
  verification: {
    providerBaseUrl: 'http://localhost:3000',
    providerStates: providerStateHandlers,
    publishResults: true
  }
});
```

### 2. Schema Validation

```typescript
await contractTester.validateSchema({
  type: 'openapi',
  schema: 'api/openapi.yaml',
  requests: actualRequests,
  validation: {
    requestBody: true,
    responseBody: true,
    headers: true,
    statusCodes: true
  }
});
```

### 3. GraphQL Contract Testing

```typescript
await graphqlTester.testContracts({
  schema: 'schema.graphql',
  operations: 'queries/**/*.graphql',
  validation: {
    queryValidity: true,
    responseShapes: true,
    nullability: true,
    deprecations: true
  }
});
```

### 4. Event Contract Testing

```typescript
await contractTester.eventContracts({
  schema: 'events/schemas/',
  events: {
    'user.created': {
      schema: 'UserCreatedEvent.json',
      examples: ['examples/user-created.json']
    },
    'order.completed': {
      schema: 'OrderCompletedEvent.json',
      examples: ['examples/order-completed.json']
    }
  },
  compatibility: 'backward'
});
```

## Breaking Change Detection

```yaml
breaking_changes:
  always_breaking:
    - endpoint_removed
    - required_param_added
    - response_field_removed
    - type_changed

  potentially_breaking:
    - optional_param_removed
    - response_field_added
    - enum_value_removed

  non_breaking:
    - endpoint_added
    - optional_param_added
    - response_field_made_optional
    - documentation_changed
```

## Contract Report

```typescript
interface ContractReport {
  summary: {
    contracts: number;
    passed: number;
    failed: number;
    warnings: number;
  };
  consumers: {
    name: string;
    contracts: ContractResult[];
    compatibility: 'compatible' | 'breaking' | 'unknown';
  }[];
  breakingChanges: {
    type: string;
    location: string;
    description: string;
    impact: 'high' | 'medium' | 'low';
    migration: string;
  }[];
  deprecations: {
    item: string;
    deprecatedIn: string;
    removeIn: string;
    replacement: string;
  }[];
}
```

## CI/CD Integration

```yaml
contract_verification:
  consumer_side:
    - generate_contracts
    - publish_to_broker
    - can_i_deploy_check

  provider_side:
    - fetch_contracts_from_broker
    - verify_against_provider
    - publish_results

  pre_release:
    - check_breaking_changes
    - verify_all_consumers
    - update_compatibility_matrix
```

## Pact Broker Integration

```typescript
await contractTester.withBroker({
  brokerUrl: 'https://pact-broker.example.com',
  auth: { token: process.env.PACT_TOKEN },
  operations: {
    publish: true,
    canIDeploy: true,
    webhooks: true
  }
});
```

## Coordination

**Primary Agents**: qe-api-contract, qe-api-compatibility, qe-graphql-tester
**Coordinator**: qe-contract-coordinator
**Related Skills**: qe-test-generation, qe-security-compliance

Overview

This skill provides consumer-driven contract testing for APIs, covering REST, GraphQL, and event-driven systems with schema validation and breaking-change detection. It helps teams generate, verify, and publish contracts, and integrates with CI/CD pipelines and Pact Broker workflows. The goal is to catch API compatibility issues early and automate contract checks across the SDLC. It produces actionable reports that highlight breaking changes, deprecations, and compatibility status for consumers and providers.

How this skill works

The skill analyzes API definitions (OpenAPI, GraphQL schema, or event schemas) to generate consumer contracts and example requests/responses. It runs verification against providers using generated contracts or contracts fetched from a broker, validates requests/responses against schemas, and performs breaking-change detection between API versions. Results are output as contract reports and can be published to a Pact Broker or integrated into CI/CD gates to enforce compatibility and deployment decisions.

When to use it

  • When validating schema changes before merging or releasing a new API version.
  • When verifying provider behavior against consumer expectations in integration tests.
  • When testing GraphQL queries and response shapes for backward compatibility.
  • When validating event payloads and ensuring event schema compatibility.
  • When automating contract checks in CI/CD pipelines or deployment gates.

Best practices

  • Generate contracts from both consumer tests and API specifications to capture real usage and intended behavior.
  • Run contract verification in CI for provider branches and publish results to a broker for traceability.
  • Use breaking-change detection on every API version change and classify impacts with migration guidance.
  • Include provider state handlers and example payloads to make verifications deterministic and debuggable.
  • Enforce a compatibility matrix and use can-i-deploy checks to prevent incompatible deployments.

Example use cases

  • Generate Pact contracts from OpenAPI and verify a running service before a release.
  • Compare api-v1.yaml and api-v2.yaml to detect removed endpoints or changed response fields.
  • Validate GraphQL schema plus queries to catch nullability and deprecated field issues.
  • Test event-driven systems by validating example events against JSON Schemas and enforcing backward compatibility.
  • Publish contracts to a Pact Broker and run can-i-deploy checks in CI to gate deployments.

FAQ

Can this skill validate both OpenAPI and GraphQL schemas?

Yes. It supports OpenAPI schema validation for REST, GraphQL schema and operation validation, and event schema checks.

How does it detect breaking changes?

It compares old and new API descriptions to flag always-breaking, potentially-breaking, and non-breaking changes and reports impact and migration guidance.