Skip to content

๐Ÿ“œ Contract Testing Agent Specification

๐ŸŽฏ Purpose

The Contract Testing Agent is responsible for:

Consumer-driven contract validation, backward compatibility verification, and Pact-style contract testing across microservice boundaries โ€” ensuring that API producers never break their consumers, and that every contract change is verified before deployment.

In a distributed microservice architecture, each service exposes APIs consumed by other services. The Contract Testing Agent guarantees that:

  • โœ… API contracts between producers and consumers are formally defined and verified
  • ๐Ÿ” Breaking changes are detected before deployment, not after
  • ๐Ÿ“œ Consumer expectations are captured as executable contract test suites
  • ๐Ÿงช Every API update triggers automated compatibility validation
  • ๐Ÿ“Š Results are traceable, observable, and integrated into CI/CD quality gates

๐Ÿงฑ What Sets It Apart from Other QA Agents?

Agent Primary Role
๐Ÿงช Test Automation Engineer Executes tests across roles, editions, and environments
๐Ÿ“ˆ Test Coverage Validator Measures static and dynamic test coverage
๐Ÿž Bug Investigator Diagnoses root causes of test failures
๐Ÿ“œ Contract Testing Agent Validates API contracts between producers and consumers at build time
๐ŸŒ E2E Testing Agent Tests complete user journeys across the full stack

๐Ÿงญ Role in Platform

The Contract Testing Agent sits at the boundary between API design and service deployment, ensuring that changes to producer APIs are safe for all registered consumers.

๐Ÿ“Š Positioning Diagram

flowchart LR
    APIDesigner[API Designer Agent]
    Backend[Backend Developer Agent]
    Contract[Contract Testing Agent]
    TestAuto[Test Automation Engineer Agent]
    QA[QA Engineer Agent]
    DevOps[DevOps Engineer Agent]

    APIDesigner --> Contract
    Backend --> Contract
    Contract --> TestAuto
    Contract --> QA
    Contract --> DevOps
Hold "Alt" / "Option" to enable pan & zoom

The Contract Testing Agent validates that producer changes are compatible with all registered consumer expectations before any deployment proceeds.


๐Ÿง  Why It Exists

Without this agent, the factory would suffer from:

  • Silent breaking changes โ€” producer API updates break downstream consumers undetected
  • Integration test fragility โ€” end-to-end tests catch contract issues too late and too expensively
  • Deployment rollbacks โ€” incompatible services deployed together cause cascading failures
  • Consumer drift โ€” consumers assume API shapes that no longer exist
  • Untraceable compatibility โ€” no audit trail of which consumer depends on which contract

This agent makes API compatibility verified, enforced, and traceable by design.


๐Ÿ“‹ Triggering Events

The Contract Testing Agent activates in response to the following platform events:

Event Description
api_contract_updated An OpenAPI spec, gRPC proto, or AsyncAPI document was modified by the API Designer Agent
microservice_deployed A producer service was deployed โ€” triggers verification against all consumer contracts
consumer_registration_changed A new consumer registered interest in a producer API, or an existing consumer updated
pull_request_with_api_changes A PR includes changes to API controllers, DTOs, or route definitions
schema_migration_detected Database or message schema changes that may affect API response shapes

๐Ÿ“‹ Responsibilities and Deliverables

โœ… Core Responsibilities

Responsibility Description
Generate Consumer Contract Tests Creates Pact-style contract tests from consumer expectations and producer OpenAPI/proto definitions
Validate Producer Compatibility Verifies that producer API changes satisfy all registered consumer contracts
Detect Breaking Changes Identifies removed endpoints, changed response schemas, modified status codes, or renamed fields
Maintain Contract Registry Tracks all producer-consumer contract pairs with versioning and dependency graphs
Emit Compatibility Reports Produces detailed reports showing which contracts pass/fail and why
Enforce Backward Compatibility Policies Blocks deployments when breaking changes are detected unless explicitly overridden
Support Schema Evolution Strategies Validates additive-only changes, deprecation patterns, and versioned endpoint migrations
Integrate with CI/CD Quality Gates Fails pipelines when contract violations are detected, emits results to PR annotations
Track Contract Coverage Measures which producer endpoints have consumer contracts and identifies coverage gaps
Emit ContractValidationCompleted Event Signals downstream agents that contract verification is finished with pass/fail status

๐Ÿ“ค Output Deliverables

Output Type Format Description
contract-test-suite .cs, .json, .yaml Generated Pact-style contract tests for each consumer-producer pair
compatibility-report .md, .json Detailed breakdown of contract validation results per endpoint
contract-registry.yaml .yaml Registry of all active contracts, versions, and consumer dependencies
breaking-change-alert .json Structured alert identifying specific breaking changes detected
execution-metadata.json .json Trace-tagged metadata of the contract validation run

๐Ÿ“˜ Example: compatibility-report.md

### ๐Ÿ“œ Contract Compatibility Report โ€” BookingService v2.3.1

๐Ÿ“Ž Trace: contract-2026-0329-booking
๐Ÿท๏ธ Producer: BookingService
๐Ÿ”— Consumers: NotificationService, BillingService, MobileGateway

โœ… Passed:
- GET /api/bookings/{id} โ€” all consumer expectations met
- POST /api/bookings โ€” response schema compatible

โŒ Failed:
- DELETE /api/bookings/{id} โ€” **endpoint removed**, consumed by NotificationService
  Breaking change: consumer expects 204 No Content response

๐Ÿ” Action Required: Restore endpoint or negotiate deprecation with consumer

๐Ÿค Collaboration Patterns

๐Ÿ”— Direct Agent Collaborations

Collaborating Agent Interaction Summary
๐ŸŽจ API Designer Agent Provides OpenAPI/AsyncAPI specs; notified when contracts are updated or new versions published
๐Ÿง  Backend Developer Agent Produces the API implementations that must satisfy contracts; receives breaking change alerts
โš™๏ธ Test Automation Engineer Agent Executes generated contract test suites as part of CI/CD pipelines
๐Ÿ‘ค QA Engineer Agent Reviews contract coverage reports and approves contract-related quality gates
๐Ÿ”ง DevOps Engineer Agent Receives deployment-blocking signals when contract violations are detected
๐Ÿ“ฆ Documentation Writer Agent Consumes contract registry data to generate API compatibility documentation

๐Ÿ“ฌ Events Emitted & Consumed

Event Name Role
api_contract_updated ๐Ÿ”„ Consumed โ†’ triggers contract test regeneration and validation
microservice_deployed ๐Ÿ”„ Consumed โ†’ triggers post-deployment contract verification
consumer_registration_changed ๐Ÿ”„ Consumed โ†’ updates contract registry and re-validates
ContractValidationCompleted โœ… Emitted โ†’ signals pass/fail to CI/CD, QA, and DevOps agents
BreakingChangeDetected โŒ Emitted โ†’ blocks deployment, notifies API Designer and consumers

๐Ÿงญ Coordination Flow

sequenceDiagram
    participant APIDesigner as API Designer Agent
    participant Contract as Contract Testing Agent
    participant TestAuto as Test Automation Engineer
    participant DevOps as DevOps Engineer Agent
    participant Studio as Studio Agent

    APIDesigner->>Contract: api_contract_updated
    Contract->>Contract: Generate contract tests
    Contract->>Contract: Validate producer compatibility
    Contract->>TestAuto: Execute contract test suite
    Contract->>DevOps: Emit ContractValidationCompleted
    Contract->>Studio: Publish compatibility report
Hold "Alt" / "Option" to enable pan & zoom

๐Ÿง  Memory and Knowledge

The Contract Testing Agent maintains a persistent knowledge base to support:

  • ๐Ÿ“š Historical contract versions and evolution tracking
  • ๐Ÿ” Reuse of contract patterns across similar service topologies
  • ๐Ÿ“Š Contract coverage metrics over time
  • ๐Ÿง  Semantic understanding of API schemas for intelligent diff analysis

๐Ÿงฉ Memory Components

Memory Store Content
๐Ÿ“‚ Contract Registry All active producer-consumer contract pairs, versions, and dependency graphs
๐Ÿ“š Contract Version History Historical snapshots of contracts enabling diff and evolution tracking
๐Ÿง  Schema Embedding Index Vector embeddings of API schemas for similarity search and drift detection
๐Ÿ“Š Compatibility Result Cache Past validation results indexed by producer version and consumer contract version
๐Ÿ” Breaking Change Pattern DB Known patterns of breaking changes (field removal, type change, enum restriction)

๐Ÿ“˜ Example Memory Entry

{
  "producerId": "booking-service",
  "producerVersion": "2.3.1",
  "consumerId": "notification-service",
  "contractVersion": "1.2.0",
  "status": "Compatible",
  "validatedAt": "2026-03-29T10:15:00Z",
  "traceId": "contract-2026-0329-booking",
  "endpointsCovered": 5,
  "breakingChanges": []
}

โœ… Validation Mechanisms

๐Ÿ” What Is Validated?

Component Validation Criteria
Response Schema All fields expected by consumers must be present with correct types and nullability
Status Codes Producer must return status codes that consumers handle; removed codes are flagged
Endpoint Availability All endpoints consumed must still exist; removed or renamed endpoints are breaking changes
Request Schema Changes to required request fields that consumers send must be backward-compatible
Header Contracts Required headers (auth, content-type, custom) must remain consistent
Event/Message Contracts AsyncAPI message schemas must satisfy subscriber expectations
Deprecation Compliance Deprecated endpoints must have migration paths documented and sunset dates respected

๐Ÿงช Validation Workflow

flowchart TD
    Start[API Contract Change Detected]
    LoadRegistry[Load Consumer Contracts from Registry]
    GenerateTests[Generate Pact-Style Tests per Consumer]
    ExecuteTests[Execute Contract Tests Against Producer]
    CompareSchemas[Compare Response Schemas]
    CheckEndpoints[Verify Endpoint Availability]
    StatusCheck{All Contracts Satisfied?}
    EmitSuccess[Emit ContractValidationCompleted โœ…]
    EmitFailure[Emit BreakingChangeDetected โŒ]

    Start --> LoadRegistry --> GenerateTests --> ExecuteTests
    ExecuteTests --> CompareSchemas --> CheckEndpoints --> StatusCheck
    StatusCheck -->|Yes| EmitSuccess
    StatusCheck -->|No| EmitFailure
Hold "Alt" / "Option" to enable pan & zoom

๐Ÿ“„ Example Validation Report (JSON)

{
  "traceId": "contract-2026-0329-booking",
  "producerId": "booking-service",
  "producerVersion": "2.3.1",
  "status": "Failed",
  "consumers": [
    {
      "consumerId": "notification-service",
      "contractVersion": "1.2.0",
      "result": "Failed",
      "violations": [
        {
          "type": "EndpointRemoved",
          "endpoint": "DELETE /api/bookings/{id}",
          "severity": "Critical",
          "message": "Consumer expects 204 No Content; endpoint no longer exists"
        }
      ]
    },
    {
      "consumerId": "billing-service",
      "contractVersion": "1.0.3",
      "result": "Passed",
      "violations": []
    }
  ]
}

๐Ÿ” Process Flow

flowchart TD
    Start([Contract Testing Agent Activated])
    LoadContracts[Load consumer contracts from registry]
    FetchProducerSpec[Fetch latest producer API specification]
    DiffSchemas[Diff producer spec against consumer expectations]
    GenerateTests[Generate contract test cases per consumer]
    ExecuteTests[Execute tests against producer mock or live instance]
    AnalyzeResults[Analyze results and classify violations]
    EmitReport[Generate compatibility report]
    EmitEvent[Emit ContractValidationCompleted or BreakingChangeDetected]
    UpdateMemory[Update contract registry and version history]
    End([Finish])

    Start --> LoadContracts --> FetchProducerSpec --> DiffSchemas
    DiffSchemas --> GenerateTests --> ExecuteTests --> AnalyzeResults
    AnalyzeResults --> EmitReport --> EmitEvent --> UpdateMemory --> End
Hold "Alt" / "Option" to enable pan & zoom

๐Ÿ“ƒ Agent Contract

agentId: contract-testing
role: "Consumer-Driven Contract Validator"
category: "Quality Assurance, API Compatibility, Testing"
description: >
  Validates API contracts between microservice producers and consumers using
  Pact-style consumer-driven contract testing. Detects breaking changes,
  enforces backward compatibility, and maintains a contract registry.

triggers:
  - api_contract_updated
  - microservice_deployed
  - consumer_registration_changed

inputs:
  - OpenAPI/AsyncAPI/Proto specifications
  - Consumer contract definitions
  - Contract registry (producer-consumer pairs)
  - Producer deployment metadata

outputs:
  - contract-test-suite
  - compatibility-report
  - contract-registry.yaml (updated)
  - breaking-change-alert
  - execution-metadata.json
  - Event: ContractValidationCompleted
  - Event: BreakingChangeDetected

skills:
  - GenerateContractTests
  - ValidateProducerCompatibility
  - DetectBreakingChanges
  - UpdateContractRegistry
  - EmitCompatibilityReport
  - EnforceDeprecationPolicy
  - TrackContractCoverage

memory:
  scope: [traceId, producerId, consumerId, contractVersion]
  stores:
    - contractRegistry
    - contractVersionHistory
    - schemaEmbeddingIndex
    - compatibilityResultCache

validations:
  - All consumer contracts satisfied by producer
  - No breaking changes without explicit override
  - Contract registry is up-to-date
  - execution-metadata.json generated

version: "1.0.0"
status: active

๐Ÿ“ Summary

The Contract Testing Agent is the API compatibility guardian of the ConnectSoft AI Software Factory. It ensures that:

  • ๐Ÿ“œ Every microservice API change is validated against all consumer contracts
  • ๐Ÿ” Breaking changes are detected and blocked before deployment
  • ๐Ÿงช Contract tests are generated, executed, and reported automatically
  • ๐Ÿ“Š A living contract registry tracks all producer-consumer dependencies
  • ๐Ÿง  Historical contract knowledge enables intelligent evolution and drift detection

Without this agent, microservice deployments become a game of chance. With it, API compatibility is guaranteed, traceable, and continuously enforced.