Testing Guide - Automated Deployment Validation
This guide explains the automated testing infrastructure for catching configuration issues BEFORE deployment.
🎯 Problem We're Solving
Previous deployments required 8+ builds to discover configuration issues:
- Wrong API paths (
/apivs/api/v5) - Incorrect build scripts (
buildvsprototype:build) - Docker layer caching issues
- npm package-lock.json sync issues
- Environment variable misconfigurations
Solution: Automated testing catches ALL of these issues in < 2 minutes, before wasting 10-20 minutes on Cloud Build.
🛠️ Testing Tools
1. scripts/test-deployment.sh - Complete Pre-Deployment Validation
Tests EVERYTHING before deployment:
- ✅ Environment configuration (
.env.production) - ✅ Source code API paths
- ✅ package.json scripts
- ✅ Build process (
npm install+npm run prototype:build) - ✅ Built files contain correct API paths
- ✅ Docker configuration
- ✅ NGINX configuration
- ✅ Cloud Build configuration
- ✅ Kubernetes configuration
- ✅ Live endpoint testing (with
--liveflag)
Usage:
# Run all tests (config + build)
./scripts/test-deployment.sh
# Run all tests + live endpoint checks
./scripts/test-deployment.sh --live
Exit codes:
0= All tests passed → SAFE TO DEPLOY1= Some tests failed → DO NOT DEPLOY
2. scripts/test-endpoints.sh - Live Endpoint Testing
Tests deployed endpoints for correct behavior:
- ✅ Health endpoint returns 200
- ✅ Frontend loads correctly
- ✅ JavaScript contains
/api/v5paths - ✅ API v5 endpoints exist (return 401 without auth)
- ✅ Old API paths (
/api/sessions) return 404
Usage:
# Test production
./scripts/test-endpoints.sh https://coditect.ai
# Test local
./scripts/test-endpoints.sh http://localhost
3. Makefile - Convenient Test Commands
Provides easy-to-remember commands:
# Run all pre-deployment tests
make test
# Test configuration only (fast)
make test-config
# Test build process
make test-build
# Test live endpoints
make test-endpoints
# Run all tests including live endpoints
make test-all
# Deploy (runs tests first)
make deploy
# Clean build artifacts
make clean
🚀 Automated CI/CD Integration
Cloud Build Validation (Step 0)
cloudbuild-combined.yaml now includes automated validation:
Step 0: Pre-Build Validation
- Checks
.env.productionhasVITE_API_URL=/api/v5 - Checks
package.jsonhasprototype:buildscript - Checks source code has
/api/v5paths - Fails fast (< 1 minute) if config is wrong
Step 1: Build + Verification
- Runs
npm run prototype:build - Verifies built files contain
/api/v5paths - Fails fast (< 5 minutes) if build produces wrong output
Benefits:
- Catches issues in 1-5 minutes vs 10-20 minutes
- Prevents bad deployments from reaching GKE
- Saves $$ on Cloud Build costs
📋 Test Checklist for New Deployments
Before every deployment, run:
# 1. Test configuration (< 5 seconds)
make test-config
# 2. Test full build (< 2 minutes)
make test
# 3. Deploy (if tests pass)
make deploy
🐛 Common Test Failures
FAIL: .env.production VITE_API_URL is wrong
Issue: .env.production has VITE_API_URL=/api instead of /api/v5
Fix:
# Edit .env.production
sed -i 's|VITE_API_URL=/api|VITE_API_URL=/api/v5|' .env.production
FAIL: Built files do NOT contain /api/v5 paths
Issue: Environment variable not being picked up by Vite
Fix:
- Clean build cache:
rm -rf dist/ node_modules/.vite - Rebuild:
npm run prototype:build - Verify:
grep -r "/api/v5" dist/
FAIL: npm run prototype:build failed
Issue: Missing dependencies or TypeScript errors
Fix:
# Clean install
rm -rf node_modules package-lock.json
npm install
npm run type-check # Fix any TypeScript errors
npm run prototype:build
FAIL: JavaScript does NOT contain /api/v5 paths
Issue: Source code still has old /api/sessions paths
Fix:
# Find old paths
grep -r "/api/sessions" src/ | grep -v "/api/v5"
# Update to /api/v5/sessions
🔬 Test Coverage
Configuration Tests
-
.env.productionhas correctVITE_API_URL -
.env.productionhas correctVITE_THEIA_URL -
package.jsonhasprototype:buildscript - Source code has
/api/v5fallback URLs - No old
/api/sessionspaths in source
Build Tests
-
npm installsucceeds -
npm run prototype:buildsucceeds -
dist/directory is created -
dist/index.htmlexists - JavaScript file is generated
- JavaScript contains
/api/v5paths - JavaScript does NOT contain old
/api/sessionspaths
Docker Tests
-
dockerfile.local-testexists - Dockerfile copies
dist/to/app/v5-frontend -
nginx-combined.confhas/api/v5/proxy
Cloud Build Tests
-
cloudbuild-combined.yamlusesnpm run prototype:build - Cloud Build uses
npm install(notnpm ci)
Kubernetes Tests
-
k8s-combined-deployment.yamlexists
Live Endpoint Tests (with --live flag)
- Health endpoint returns 200
- Frontend is accessible
- API v5 endpoints return 401 (auth required)
- Old API paths return 404
🎓 Best Practices
1. Test Before Every Commit
# Add to your workflow
make test-config
git add .
git commit -m "Your message"
2. Test After Every Checkout
# After pulling changes
git pull
make test
3. Test After Configuration Changes
# After editing .env.production, package.json, etc.
make test-config
4. Test After Source Code Changes
# After editing API paths, adding features, etc.
make test
5. Test Endpoints After Deployment
# After successful deployment
make test-endpoints
📊 Expected Test Times
| Test | Time | When to Run |
|---|---|---|
make test-config | < 5 seconds | Before every commit |
make test-build | ~ 2 minutes | Before deployment |
make test | ~ 2 minutes | Before deployment |
make test-endpoints | ~ 10 seconds | After deployment |
| Cloud Build Step 0 | < 1 minute | Automatic (CI/CD) |
| Cloud Build Step 1 | ~ 4 minutes | Automatic (CI/CD) |
🚨 When Tests Should Fail
Tests SHOULD fail if:
- ❌ Configuration is incorrect (wrong API URLs)
- ❌ Build scripts are wrong (using
buildinstead ofprototype:build) - ❌ Source code has old API paths
- ❌ npm packages are out of sync
- ❌ TypeScript has compilation errors
- ❌ Built files are missing or incorrect
✅ When Tests Should Pass
Tests SHOULD pass if:
- ✅ All configuration files are correct
- ✅ Build completes successfully
- ✅ Built files contain correct API paths
- ✅ All dependencies are installed
- ✅ TypeScript compiles without errors
🔄 Continuous Integration Workflow
1. Developer makes changes
↓
2. Run `make test-config` (< 5 sec)
↓
3. Commit changes
↓
4. Run `make test` (~ 2 min)
↓
5. Push to GitHub
↓
6. Cloud Build triggers
↓
7. Step 0: Pre-build validation (< 1 min)
↓
8. Step 1: Build + verification (~ 4 min)
↓
9. Step 2: Docker build (~ 10 min)
↓
10. Step 3: Push to registry
↓
11. Step 4: Deploy to GKE
↓
12. Run `make test-endpoints` (~ 10 sec)
↓
13. ✅ Deployment complete!
📝 Troubleshooting
Tests pass locally but fail in Cloud Build
Cause: Different environment or cached files
Fix:
# Clean everything
make clean
rm -rf node_modules
npm install
make test
Tests pass but endpoints fail
Cause: Browser cache or old pods
Fix:
- Hard refresh browser:
Ctrl+Shift+R(Windows) orCmd+Shift+R(Mac) - Check pod status:
kubectl get pods -n coditect-app - Verify correct image is deployed
Tests hang or timeout
Cause: npm install or build process is slow
Fix:
# Increase timeout or run with more resources
NODE_OPTIONS=--max_old_space_size=8192 make test
🎉 Benefits
Before Automated Testing
- 8 builds required to find and fix issues
- 10-20 minutes per build = 80-160 minutes wasted
- Manual verification required after each build
- No visibility into what broke
After Automated Testing
- 1 build (issues caught before deployment)
- 2 minutes local testing + 15 minutes Cloud Build = 17 minutes total
- Automatic verification in CI/CD
- Clear error messages showing exactly what's wrong
Time Saved: 63-143 minutes per deployment Cost Saved: ~$5-10 per failed build (Cloud Build costs) Stress Reduced: 🚀 Massive!
Next Steps:
- Run
make testto verify your current setup - Add
make test-configto your pre-commit workflow - Review test output to understand what's being validated
- Customize tests for your specific needs
Questions? See the scripts themselves:
scripts/test-deployment.sh- Main test suitescripts/test-endpoints.sh- Endpoint testingMakefile- Test orchestration