Validation Strategy
TL;DR: We use a 3-tier validation system to balance speed and quality. Fast checks run on commit (<30s), critical checks on push (3-5 min), comprehensive checks in CI (12-15 min).
Overview
This document explains our tiered validation strategy implemented as part of the CI/CD optimization (2025-11-16). The strategy balances developer productivity with code quality by running different validation levels at different stages.Why Tiered Validation?
Problem: Running all 130+ validators on everygit push took 8-12 minutes, slowing developer iteration.
Solution: Split validators into 3 tiers based on criticality and speed:
- Tier 1 (Pre-commit): Fast auto-fixers and critical linters (
<30s) - Tier 2 (Pre-push): Type checking, fast tests, deployment validation (3-5 min)
- Tier 3 (CI/Manual): Comprehensive tests, slow validation, security scans (12-15 min)
Tier 1: Pre-Commit (<30s)
When: Runs automatically on git commit (before commit is created)
Purpose: Auto-fix formatting and catch obvious errors immediately
Target Duration: <30 seconds
What Runs
Auto-fixers (modify files automatically):trailing-whitespace- Remove trailing whitespaceend-of-file-fixer- Ensure files end with newlineblack- Format Python code (line-length=127)isort- Sort Python imports (black-compatible)
flake8- Python linting (max-line-length=127, max-complexity=20)bandit- Security linting (low/low severity threshold)check-yaml,check-json,check-toml- File format validationgitleaks- Secret detectiondetect-private-key- SSH key detection
check-added-large-files- Block files >500KB (excludes uv.lock)check-merge-conflict- Detect merge conflict markersmixed-line-ending- Ensure consistent line endings
How to Run Manually
Makefile Shortcut
Tier 2: Pre-Push (3-5 min)
When: Runs automatically ongit push (before pushing to remote)
Purpose: Catch bugs and regressions before CI runs
Target Duration: 3-5 minutes
What Runs
Type Checking:mypy- Static type checking (src/mcp_server_langgraph/)
- Unit tests with
pytest -x(fail-fast mode) - Test coverage validation (≥64% threshold)
- Test infrastructure validation (fixtures, xdist, AsyncMock)
helm-lint- Helm chart validationvalidate-kustomize-builds- Kustomize overlay buildsvalidate-no-placeholders- Production placeholder checkvalidate-gke-autopilot-compliance- GKE resource compliancevalidate-deployment-secrets- Secret key alignmentvalidate-cors-security- CORS configurationtrivy-scan-k8s-manifests- Security scanning (HIGH/CRITICAL)
mintlify-broken-links-check- PRIMARY Mintlify validator (~8-12s)validate-documentation-structure- Orphaned files, ADR numberingvalidate-documentation-integrity- ADR sync, Mermaid diagramsvalidate-adr-index- ADR index up-to-date
check-github-workflows- JSON schema validationactionlint-workflow-validation- Advanced workflow lintingvalidate-github-workflows- Context usage validation
check-test-memory-safety- pytest-xdist OOM preventionvalidate-test-isolation- pytest-xdist worker isolationvalidate-test-fixtures- Fixture validationvalidate-fixture-organization- No duplicate autouse fixturescheck-async-mock-usage- AsyncMock usage validationvalidate-test-ids- Hardcoded ID detection
uv-lock-check- Lockfile synchronizationvalidate-pytest-config- Pytest plugin compatibilityvalidate-pre-push-hook- Pre-push hook completeness
How to Run Manually
Makefile Shortcut
Tier 3: CI/Manual (12-15 min)
When: Runs in CI on every push, or manually for comprehensive validation Purpose: Comprehensive quality assurance, slow tests, expensive validation Target Duration: 12-15 minutes (in CI with parallelization)What Runs
Comprehensive Test Suite:- All unit tests (with full coverage reporting)
- Integration tests (Docker Compose infrastructure)
- E2E tests (full user journeys)
- Property-based tests (Hypothesis, 100 examples in CI)
- Contract tests (MCP protocol compliance)
- Regression tests (performance regression detection)
- Mutation testing (test effectiveness validation)
- Benchmark tests (performance trend tracking)
- Slow test detection (individual tests >10s)
- Test suite performance validation (
<120starget)
- Full Trivy scan (all severity levels)
- SAST with Semgrep
- Dependency scanning
- Container image scanning
- Kubernetes manifest security
audit-todo-fixme-markers- TODO/FIXME auditcheck-mermaid-styling- Diagram styling (moved to manual 2025-11-16)check-async-mock-configuration- AsyncMock config (65 violations, work in progress)validate-test-suite-performance- Performance regression (<120s)detect-slow-unit-tests- Individual slow tests (>10s)
How to Run Manually
Makefile Shortcut
Quick Reference
| Tier | When | Duration | Purpose | Command |
|---|---|---|---|---|
| Tier 1 | git commit | <30s | Auto-fix formatting, catch obvious errors | make validate-commit |
| Tier 2 | git push | 3-5 min | Type checking, fast tests, critical validation | make validate-push |
| Tier 3 | CI / Manual | 12-15 min | Comprehensive tests, slow validation, security | make validate-full |
When to Use Each Tier
Use Tier 1 (validate-commit)
- Quick formatting check before committing
- Fixing linting errors
- Verifying file changes before commit
Use Tier 2 (validate-push)
- Before pushing to remote (runs automatically)
- After making significant changes
- Before creating a pull request
Use Tier 3 (validate-full)
- Before merging to main branch
- After major refactoring
- Investigating test failures
- Pre-release validation
Skipping Validation (Use Sparingly!)
When It’s Safe to Skip
Skip Tier 1 (commit hooks): NEVER recommended- These are fast (
<30s) and catch obvious errors - Auto-fixers improve code quality automatically
- Only skip if you’re confident CI will catch issues
- Example: Documentation-only changes (but still recommended to run)
- Manual validators are informational only
- They don’t block commits or pushes
How to Skip Specific Hooks
Hook IDs Reference
Validation in CI/CD
GitHub Actions Workflows
Main CI Pipeline (.github/workflows/ci.yaml):
- Runs Tier 1 + Tier 2 validators automatically
- Runs Tier 3 validators (comprehensive tests)
- Uses GitHub Actions cache for speed
- Parallel matrix builds for efficiency
- Run in CI using:
pre-commit run --hook-stage manual --all-files - Ensures comprehensive validation even if developer skipped locally
CI Parity Enforcement
Our pre-push hooks match CI validation exactly. This prevents surprises:- If pre-push passes, CI should pass
- If pre-push fails, fix it before pushing
- No “works on my machine” issues
validate-pre-push-hook- Validates pre-push hook completenessvalidate-local-ci-parity- CI job validates local/CI consistency
Validation Changes (2025-11-16)
This validation strategy was implemented as part of CI/CD Optimization - Phase 2.What Changed
Documentation Validators (13 → 4):- REMOVED:
validate-mintlify-docs,validate-docs-navigation,check-doc-links - KEPT:
mintlify-broken-links-check(PRIMARY),validate-documentation-structure,validate-documentation-integrity,validate-adr-index - MOVED TO MANUAL:
check-mermaid-styling
- REMOVED:
make lint,make format,docs-validate-mdx,docs-validate-links - ADDED:
make validate-commit,make validate-push,make validate-full
- Before: 8-12 minutes (all validators)
- After: 3-5 minutes (critical validators only)
- Improvement: 50-60% faster
Migration Guide
Old Command → New Command:make lint→make lint-checkmake format→make lint-fixmake docs-validate-mdx→make docs-validate-mintlifymake docs-validate-links→make docs-validate-mintlify- No direct replacement for validator shortcuts → Use tiered shortcuts (
make validate-commit/push/full)
Best Practices
Development Workflow
Recommended workflow for productive development:- Code changes - Make your changes
- Quick validation -
make validate-commit(<30s) - Commit -
git commit(Tier 1 runs automatically) - Comprehensive check -
make validate-push(3-5 min, before pushing) - Push -
git push(Tier 2 runs automatically) - CI validation - Let CI run Tier 3 validators
Testing Workflow
For test-driven development (TDD):- Write test - Follow RED-GREEN-REFACTOR cycle
- Run test -
pytest tests/path/to/test.py -xvs - Implement - Write minimal code to pass
- Quick check -
make validate-commit - Commit -
git commit - Full validation -
make validate-push(before pushing)
PR Review Workflow
Before creating a pull request:- Full validation -
make validate-full(12-15 min) - Fix any failures - Address all errors and warnings
- Push -
git push(Tier 2 runs automatically) - Create PR - All CI checks should pass
- Monitor CI - Verify all workflows pass
Troubleshooting
”Hooks are too slow”
Solution 1: Use tiered shortcuts“CI fails but pre-push passed”
Diagnosis: CI might run additional validators in Tier 3 (manual stage) Solution: Run full validation locally”Hook fails with unclear error”
Solution: Run hook in verbose mode“Want to see all available hooks”
Performance Optimization
Current Performance
| Tier | Target | Actual | Status |
|---|---|---|---|
| Tier 1 (Pre-commit) | <30s | ~25s | ✅ GOOD |
| Tier 2 (Pre-push) | 3-5 min | ~4-5 min | ✅ GOOD |
| Tier 3 (CI/Manual) | 12-15 min | ~12-18 min | ⚠️ ACCEPTABLE |
Optimization Strategies
For Pre-Commit (<30s goal):
- Keep only auto-fixers and fast linters
- No network operations (no external API calls)
- No slow file operations (no large file parsing)
- Run fast tests with
pytest -x(fail-fast) - Use parallel validation where possible
- Cache dependencies and build artifacts
- Skip slow tests (run in CI instead)
- Use GitHub Actions matrix builds (parallel execution)
- Cache uv dependencies and Docker layers
- Use
pytest-xdistfor parallel test execution - Split slow test suites (e.g.,
pytest-splitfor 4x parallelism)
Related Documentation
- Test-Driven Development:
/home/vishnu/.claude/CLAUDE.md(global TDD standards) - Testing Guide:
tests/README.md(test organization and patterns) - Pre-commit Guide:
.pre-commit-config.yaml(hook configuration) - Makefile Reference:
Makefile(all available targets) - GitHub Actions:
.github/workflows/(CI/CD workflows) - Memory Safety:
tests/MEMORY_SAFETY_GUIDELINES.md(pytest-xdist OOM prevention) - AsyncMock Guide:
tests/ASYNC_MOCK_GUIDELINES.md(AsyncMock best practices) - Pytest xdist Guide:
tests/PYTEST_XDIST_BEST_PRACTICES.md(parallel test execution)
Contact & Support
Questions or Issues?- Review this document first
- Check Makefile help:
make help - Check pre-commit config:
.pre-commit-config.yaml - Ask in team chat or create a GitHub issue
- Determine appropriate tier (commit/push/manual)
- Add to
.pre-commit-config.yamlwith correctstages:parameter - Test locally:
SKIP= pre-commit run <new-hook-id> --all-files - Update this document with the new validator
- Create PR with changes
- Profile slow hooks:
time SKIP= pre-commit run <hook-id> --all-files - Consider moving to manual stage if not critical
- Consider parallelization if hook is CPU-bound
- Consider caching if hook has expensive setup
- Create PR with optimization and updated documentation
Last Updated: 2025-11-16 (CI/CD Optimization - Phase 2) Version: 1.0.0 Status: Active