Shell
#!/bin/bash
# quality-gate-check.sh
# Validates quality gates and triggers milestone updates when passed
# Quality gates: test coverage, linting, type hints, performance, etc.
set -euo pipefail
PROJECT_ROOT="/Users/eddiebelaval/Development/deepstack"
BUILD_PLAN="$PROJECT_ROOT/docs/BUILD_PLAN.md"
PROGRESS="$PROJECT_ROOT/docs/PROGRESS.md"
# Colors for output
GREEN='\033[0;32m'
RED='\033[0;31m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
log() {
echo -e "${BLUE}[QUALITY GATE]${NC} $1"
}
success() {
echo -e "${GREEN}[✓ PASSED]${NC} $1"
}
fail() {
echo -e "${RED}[✗ FAILED]${NC} $1"
}
warn() {
echo -e "${YELLOW}[!]${NC} $1"
}
# Check test coverage (if pytest-cov is configured)
check_test_coverage() {
log "Checking test coverage..."
if [[ ! -d "$PROJECT_ROOT/tests" ]]; then
warn "No tests directory found. Skipping coverage check."
return 1
fi
# Check if pytest is available
if ! command -v pytest &> /dev/null; then
warn "pytest not installed. Skipping coverage check."
return 1
fi
# Run pytest with coverage (if configured)
cd "$PROJECT_ROOT"
if pytest --cov=core --cov-report=term-missing 2>/dev/null | grep -q "TOTAL.*[8-9][0-9]%\|TOTAL.*100%"; then
success "Test coverage ≥80%"
return 0
else
fail "Test coverage <80%"
return 1
fi
}
# Check linting (if pylint/flake8 configured)
check_linting() {
log "Checking code quality (linting)..."
if ! command -v pylint &> /dev/null; then
warn "pylint not installed. Skipping linting check."
return 1
fi
cd "$PROJECT_ROOT"
if pylint core/ --exit-zero --score=yes 2>/dev/null | grep -q "rated at [8-9]\.[0-9]/10\|rated at 10\.0/10"; then
success "Linting score ≥8.0/10"
return 0
else
fail "Linting score <8.0/10"
return 1
fi
}
# Check type hints (if mypy configured)
check_type_hints() {
log "Checking type hint coverage..."
if ! command -v mypy &> /dev/null; then
warn "mypy not installed. Skipping type check."
return 1
fi
cd "$PROJECT_ROOT"
# Simple check: if mypy passes with no errors
if mypy core/ --ignore-missing-imports 2>/dev/null; then
success "Type hints passing"
return 0
else
fail "Type hint errors found"
return 1
fi
}
# Check for mock data (should be zero in production)
check_no_mock_data() {
log "Checking for mock data..."
cd "$PROJECT_ROOT/core"
local mock_count=$(grep -r "hash(symbol)\|mock_data\|fake_data" . 2>/dev/null | wc -l)
if [[ $mock_count -eq 0 ]]; then
success "Zero mock data found"
return 0
else
fail "Found $mock_count instances of mock data"
return 1
fi
}
# Validate all Phase 1 quality gates
validate_phase1_gates() {
log "Validating Phase 1 quality gates..."
local gates_passed=0
local gates_total=4
check_test_coverage && ((gates_passed++))
check_linting && ((gates_passed++))
check_type_hints && ((gates_passed++))
check_no_mock_data && ((gates_passed++))
log "Quality gates passed: $gates_passed/$gates_total"
if [[ $gates_passed -eq $gates_total ]]; then
success "All Phase 1 quality gates passed!"
return 0
else
fail "Phase 1 quality gates incomplete ($gates_passed/$gates_total)"
return 1
fi
}
# Main execution
main() {
log "Running quality gate checks..."
# Default: validate based on current phase
# For now, check Phase 1 gates since we're in Phase 1
validate_phase1_gates
local exit_code=$?
if [[ $exit_code -eq 0 ]]; then
# All gates passed - trigger milestone tracker
log "Quality gates passed! Triggering milestone tracker..."
if [[ -f "/Users/eddiebelaval/.claude/hooks/milestone-tracker.sh" ]]; then
/Users/eddiebelaval/.claude/hooks/milestone-tracker.sh
fi
fi
exit $exit_code
}
main "$@"