#!/bin/bash # check-contract.sh # # CI contract validation script # # Checks: # 1. Schema matches committed version # 2. Hash matches committed version # 3. Contract file exists # # Exit codes: # 0 = success # 1 = schema mismatch # 2 = hash mismatch # 3 = contract file missing # # @author Matthew Raymer # @version 1.0.0 set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" CONTRACT_FILE="$PROJECT_ROOT/contracts/NotificationContract.v1.ts" SCHEMA_FILE="$PROJECT_ROOT/contracts/notification.v1.schema.json" HASH_FILE="$PROJECT_ROOT/contracts/notification.v1.hash" echo "🔍 Checking contract v1 compliance..." # Check contract file exists if [ ! -f "$CONTRACT_FILE" ]; then echo "❌ Contract file not found: $CONTRACT_FILE" exit 3 fi # Generate current schema and hash echo "📋 Generating current schema and hash..." CURRENT_SCHEMA=$(node "$SCRIPT_DIR/generate-contract-schema.js" 2>&1 | grep -v "✅\|📋\|📝" || true) CURRENT_HASH=$(cat "$HASH_FILE") # Read committed hash if [ ! -f "$HASH_FILE" ]; then echo "❌ Hash file not found: $HASH_FILE" exit 3 fi COMMITTED_HASH=$(cat "$HASH_FILE") # Compare hashes if [ "$CURRENT_HASH" != "$COMMITTED_HASH" ]; then echo "❌ Contract hash mismatch!" echo " Current: $CURRENT_HASH" echo " Committed: $COMMITTED_HASH" echo "" echo "⚠️ Contract has been modified without version bump." echo " See docs/0017-Daily-Notification-Contract-Freeze.md for change process." exit 2 fi # Check schema file exists if [ ! -f "$SCHEMA_FILE" ]; then echo "❌ Schema file not found: $SCHEMA_FILE" exit 3 fi echo "✅ Contract v1 validation passed" echo " Hash: $CURRENT_HASH" exit 0