- Add contracts/NotificationContract.v1.ts (frozen TypeScript interface) - Add contracts/notification.v1.schema.json (JSON Schema) - Add contracts/notification.v1.hash (SHA-256 hash for integrity) - Add scripts/generate-contract-schema.js (schema generator) - Add scripts/check-contract.sh (validation script) Contract v1 is now frozen as single source of truth for cross-platform notification content. All platforms must conform to this contract. See docs/0017-Daily-Notification-Contract-Freeze.md for details.
72 lines
1.7 KiB
Bash
Executable File
72 lines
1.7 KiB
Bash
Executable File
#!/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
|
|
|