/** * Agentic QE v3 - Contract Testing Domain Interfaces * * Bounded Context: Contract Testing * Responsibility: API contracts, consumer-driven contracts, schema validation */ import type { DomainEvent, Result } from '../../shared/types/index.js'; import type { FilePath, Version } from '../../shared/value-objects/index.js'; /** * API Contract definition */ export interface ApiContract { readonly id: string; readonly name: string; readonly version: Version; readonly type: ContractType; readonly provider: ServiceInfo; readonly consumers: ServiceInfo[]; readonly endpoints: ContractEndpoint[]; readonly schemas: SchemaDefinition[]; } export type ContractType = 'rest' | 'graphql' | 'grpc' | 'event' | 'message'; export interface ServiceInfo { readonly name: string; readonly version: string; readonly team?: string; readonly repository?: string; } export interface ContractEndpoint { readonly path: string; readonly method: HttpMethod; readonly requestSchema?: string; readonly responseSchema?: string; readonly headers?: Record; readonly examples: EndpointExample[]; } export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS'; export interface EndpointExample { readonly name: string; readonly request: unknown; readonly response: unknown; readonly statusCode: number; } export interface SchemaDefinition { readonly id: string; readonly name: string; readonly type: 'json-schema' | 'openapi' | 'graphql' | 'protobuf' | 'avro'; readonly content: string; } /** * Contract verification result */ export interface VerificationResult { readonly contractId: string; readonly provider: string; readonly consumer: string; readonly passed: boolean; readonly failures: ContractFailure[]; readonly warnings: ContractWarning[]; readonly timestamp: Date; } export interface ContractFailure { readonly endpoint: string; readonly type: FailureType; readonly expected: unknown; readonly actual: unknown; readonly message: string; } export type FailureType = 'missing-endpoint' | 'schema-mismatch' | 'status-code-mismatch' | 'header-mismatch' | 'response-body-mismatch' | 'timeout' | 'connection-error'; export interface ContractWarning { readonly endpoint: string; readonly message: string; readonly severity: 'high' | 'medium' | 'low'; } /** * Breaking change detection */ export interface BreakingChange { readonly type: BreakingChangeType; readonly location: string; readonly description: string; readonly impact: 'high' | 'medium' | 'low'; readonly affectedConsumers: string[]; readonly migrationPath?: string; } export type BreakingChangeType = 'removed-endpoint' | 'removed-field' | 'type-change' | 'required-field-added' | 'enum-value-removed' | 'response-code-change'; export interface ContractVerifiedEvent extends DomainEvent { readonly type: 'ContractVerifiedEvent'; readonly contractId: string; readonly provider: string; readonly consumer: string; readonly passed: boolean; readonly failureCount: number; } export interface BreakingChangeDetectedEvent extends DomainEvent { readonly type: 'BreakingChangeDetectedEvent'; readonly contractId: string; readonly changes: BreakingChange[]; readonly affectedConsumers: string[]; } export interface ContractPublishedEvent extends DomainEvent { readonly type: 'ContractPublishedEvent'; readonly contractId: string; readonly version: string; readonly provider: string; } export interface ConsumerContractCreatedEvent extends DomainEvent { readonly type: 'ConsumerContractCreatedEvent'; readonly contractId: string; readonly consumer: string; readonly provider: string; readonly interactionCount: number; } /** * Contract Validation Service * Validates API contracts against schemas */ export interface IContractValidationService { /** * Validate contract structure */ validateContract(contract: ApiContract): Promise>; /** * Validate request against schema */ validateRequest(request: unknown, schema: SchemaDefinition): Promise>; /** * Validate response against schema */ validateResponse(response: unknown, schema: SchemaDefinition): Promise>; /** * Validate OpenAPI/Swagger specification */ validateOpenAPI(spec: string): Promise>; } export interface ValidationReport { readonly isValid: boolean; readonly errors: ValidationError[]; readonly warnings: string[]; } export interface ValidationError { readonly path: string; readonly message: string; readonly code: string; } export interface SchemaValidationResult { readonly isValid: boolean; readonly errors: SchemaError[]; } export interface SchemaError { readonly path: string; readonly keyword: string; readonly message: string; readonly params: Record; } export interface OpenAPIValidationResult { readonly isValid: boolean; readonly specVersion: string; readonly errors: ValidationError[]; readonly warnings: string[]; readonly endpointCount: number; readonly schemaCount: number; } /** * Contract Verification Service * Verifies provider against consumer contracts */ export interface IContractVerificationService { /** * Verify provider against consumer contracts */ verifyProvider(providerUrl: string, contracts: ApiContract[]): Promise>; /** * Verify single consumer contract */ verifyConsumerContract(providerUrl: string, contract: ApiContract, consumerName: string): Promise>; /** * Run verification with mock responses */ verifyWithMocks(contract: ApiContract, mocks: MockResponse[]): Promise>; } export interface MockResponse { readonly endpoint: string; readonly method: HttpMethod; readonly statusCode: number; readonly body: unknown; readonly headers?: Record; } /** * API Compatibility Service * Detects breaking changes between versions */ export interface IApiCompatibilityService { /** * Compare two contract versions */ compareVersions(oldContract: ApiContract, newContract: ApiContract): Promise>; /** * Check if new version is backward compatible */ isBackwardCompatible(oldContract: ApiContract, newContract: ApiContract): Promise>; /** * Get breaking changes between versions */ getBreakingChanges(oldContract: ApiContract, newContract: ApiContract): Promise>; /** * Generate migration guide */ generateMigrationGuide(breakingChanges: BreakingChange[]): Promise>; } export interface CompatibilityReport { readonly isCompatible: boolean; readonly breakingChanges: BreakingChange[]; readonly nonBreakingChanges: NonBreakingChange[]; readonly deprecations: Deprecation[]; } export interface NonBreakingChange { readonly type: 'added-endpoint' | 'added-field' | 'added-enum-value' | 'optional-field-added'; readonly location: string; readonly description: string; } export interface Deprecation { readonly location: string; readonly reason: string; readonly removalVersion?: string; readonly replacement?: string; } export interface MigrationGuide { readonly fromVersion: string; readonly toVersion: string; readonly steps: MigrationStep[]; readonly estimatedEffort: 'trivial' | 'minor' | 'moderate' | 'major'; } export interface MigrationStep { readonly order: number; readonly description: string; readonly codeChanges?: string; readonly automated: boolean; } /** * Schema Validation Service * Validates data against various schema formats */ export interface ISchemaValidationService { /** * Validate JSON Schema */ validateJsonSchema(data: unknown, schema: object): Promise>; /** * Validate GraphQL schema */ validateGraphQLSchema(schema: string): Promise>; /** * Compare schemas for compatibility */ compareSchemas(oldSchema: SchemaDefinition, newSchema: SchemaDefinition): Promise>; /** * Generate schema from sample data */ inferSchema(samples: unknown[]): Promise>; } export interface GraphQLValidationResult { readonly isValid: boolean; readonly errors: GraphQLError[]; readonly typeCount: number; readonly queryCount: number; readonly mutationCount: number; } export interface GraphQLError { readonly message: string; readonly locations: Array<{ line: number; column: number; }>; } export interface SchemaComparisonResult { readonly isCompatible: boolean; readonly additions: string[]; readonly removals: string[]; readonly modifications: SchemaModification[]; } export interface SchemaModification { readonly path: string; readonly oldType: string; readonly newType: string; readonly isBreaking: boolean; } export interface IContractRepository { findById(id: string): Promise; findByProvider(provider: string): Promise; findByConsumer(consumer: string): Promise; findLatestVersion(name: string): Promise; save(contract: ApiContract): Promise; publish(contract: ApiContract): Promise; } export interface IVerificationResultRepository { findByContractId(contractId: string): Promise; findLatest(contractId: string, consumer: string): Promise; findFailed(since: Date): Promise; save(result: VerificationResult): Promise; } export interface IContractTestingCoordinator { /** * Register new contract */ registerContract(contract: ApiContract): Promise>; /** * Verify all consumer contracts for provider */ verifyAllConsumers(providerName: string, providerUrl: string): Promise>; /** * Check for breaking changes before release */ preReleaseCheck(providerName: string, newContractPath: FilePath): Promise>; /** * Generate contract from OpenAPI spec */ importFromOpenAPI(specPath: FilePath): Promise>; /** * Export contract to OpenAPI spec */ exportToOpenAPI(contractId: string): Promise>; } export interface ProviderVerificationReport { readonly provider: string; readonly totalConsumers: number; readonly passedConsumers: number; readonly failedConsumers: string[]; readonly results: VerificationResult[]; readonly canDeploy: boolean; } export interface PreReleaseReport { readonly breakingChanges: BreakingChange[]; readonly affectedConsumers: AffectedConsumer[]; readonly canRelease: boolean; readonly recommendations: string[]; } export interface AffectedConsumer { readonly name: string; readonly team?: string; readonly breakingChanges: BreakingChange[]; readonly notified: boolean; } //# sourceMappingURL=interfaces.d.ts.map