CI/CD Intelligent Monitoring Guide
๐จ Problem: The Confusing CI/CD Loopโ
Scenario: Tests pass locally, pre-push hook passes, but CI fails with the same tests.
Why This Happens:
- Environment Differences: Local (Node 20+) vs CI (Node 16.20.2, 18.20.8, 20.18.0)
- Working Directory: Different paths between local and CI
- Dependencies: Subtle version differences
- Configuration: Missing files in CI environment
๐ก๏ธ Prevention Strategyโ
1. Enhanced Pre-Push Hook โ IMPLEMENTEDโ
Our .git/hooks/pre-push now:
- โ
Simulates CI environment (
CI=true,NODE_ENV=test) - โ Tests critical failing test first
- โ Shows Node version differences
- โ Provides detailed debugging info on failure
- โ Validates environment configuration
2. Developer Tools โ IMPLEMENTEDโ
Quick Commands:
# Test critical test with CI environment
npm run test:critical
# Full CI environment simulation
npm run test:ci
# Manual CI environment test
CI=true NODE_ENV=test npm test
CI Simulation Script:
# Runs full CI environment simulation
bash scripts/test-ci-environment.sh
3. Before Every Push - Developer Checklistโ
ALWAYS run before pushing:
# 1. Quick critical test
npm run test:critical
# 2. If you have time, full CI simulation
npm run test:ci
# 3. Standard tests
npm test
If ANY of these fail โ DO NOT PUSH โ Fix the issue first.
๐ง Common Environment Issues & Fixesโ
Node Version Differencesโ
Problem: Local Node 20+, CI uses Node 16.20.2
Detection: node --version vs CI matrix
Fix: Use Node features compatible with 16.20.2+
Path Resolution Issuesโ
Problem: Different working directories
Detection: pwd differences in logs
Fix: Use absolute paths or proper config files
Missing Configurationโ
Problem: supernal-code.config.toml not found in CI
Detection: Warning in pre-push hook
Fix: Ensure config files are committed and not in .gitignore
Dependency Differencesโ
Problem: package-lock.json vs npm ci differences
Detection: Different package versions
Fix: Use npm ci consistently, commit package-lock.json
๐ฏ How Our Prevention Worksโ
Enhanced Pre-Push Hook Flowโ
๐ฏ CI Environment Simulation...
Local Node: v20.19.4
CI Matrix: Node 16.20.2, 18.20.8, 20.18.0
๐ฏ Running critical CI test (req-052-testing-guidance)...
โ
Critical test passed with Node v20.19.4
๐ Environment validation...
โ ๏ธ Warning: Check for potential Node version incompatibilities
๐งช Running full test suite...
โ
All tests passed
โ
Pre-push validation complete - safe to push!
What Triggers the Safety Netโ
- Any test failure โ Push blocked immediately
- Critical test failure โ Specific CI failure prevention
- Environment mismatch โ Warning about potential issues
- Missing config โ Alert about CI environment problems
๐ Developer Workflowโ
Standard Developmentโ
# Make changes
git add .
git commit -m "Your changes"
# Pre-push hook automatically runs and validates
git push # Safe if hook passes
When Hook Failsโ
# Hook blocks push and shows exact error
โ CRITICAL TEST FAILED - This exact test failed in CI!
# Debug with provided info
cat .git/logs/pre-push-tests-YYYYMMDD-HHMMSS.log
# Fix the issue
# Commit the fix
# Try pushing again
Extra Validation (Optional)โ
# Before major changes
npm run test:ci
# Quick validation
npm run test:critical
๐ฏ Future Improvementsโ
Planned Enhancementsโ
- Multi-Node Testing: Test against Node 16, 18, 20 locally if available
- Docker CI Simulation: Exact Ubuntu environment replication
- Automated Fix Suggestions: Common problem detection and fixes
- Team Notifications: Slack/Discord alerts for CI failures
Configuration Optionsโ
-
SC_STRICT_CI_CHECK=true- Require exact CI environment match -
SC_SKIP_CRITICAL_TEST=true- Skip specific test pre-check -
SC_CI_NODE_VERSION=16.20.2- Test against specific Node version
๐จ Emergency Bypass (Use Sparingly)โ
When CI is broken and you need to push a fix:
# Bypass pre-push hook (DANGEROUS)
git push --no-verify
# OR bypass via environment
SC_SKIP_PRE_PUSH=true git push
โ ๏ธ Warning: Only use for hotfixes when CI is broken and you're fixing the CI issue itself.
๐ Success Metricsโ
Target: Zero CI failures caused by environment differences
Monitoring:
- Track CI failure rate before/after prevention measures
- Monitor pre-push hook effectiveness
- Developer adoption of
npm run test:ci
Expected Results:
- ๐ CI Failures: Down 90%+ for environment issues
- ๐ Developer Confidence: No more "tests pass locally but fail in CI"
- โก Faster Iteration: Catch issues before pushing