import { CheckContext, RuleViolation } from '../engine'; interface FileChange { filename: string; status: string; patch?: string; } /** * Detect invariant violations in code changes * * This is a stubbed implementation that demonstrates the concept. * In a full implementation, this would check for: * - Breaking changes to contracts * - Violations of documented invariants * - Changes that break assumptions */ export async function detectInvariantViolation( files: FileChange[], _context: CheckContext ): Promise { const violations: RuleViolation[] = []; // Stub: Check for obvious breaking changes for (const file of files) { if (!file.patch) continue; const lines = file.patch.split('\n'); // Example: Detect removal of public API methods for (let i = 0; i < lines.length; i++) { const line = lines[i]; // Detect removal of exported functions if (line.startsWith('-') && /export\s+(async\s+)?function\s+\w+/.test(line)) { violations.push({ rule: 'invariant-violation', severity: 'warning', message: 'Public API function removed. This may be a breaking change.', path: file.filename, line: i + 1, }); } // Detect removal of type definitions if (line.startsWith('-') && /export\s+(interface|type)\s+\w+/.test(line)) { violations.push({ rule: 'invariant-violation', severity: 'warning', message: 'Public type definition removed. This may be a breaking change.', path: file.filename, line: i + 1, }); } } } return violations; }