Incremental Migration Plan for Task #18
Overview
This document outlines a safe, incremental migration strategy for consolidating builder and content consistency tests around manuscript.tex as the canonical test book. The plan minimizes disruption to CI/CD pipelines while ensuring comprehensive test coverage throughout the transition.
Migration Principles
1. Zero-Downtime Migration
- Parallel Execution: Run old and new tests simultaneously during transition
- Gradual Cutover: Migrate test modules one at a time
- Rollback Capability: Maintain ability to revert to previous test structure
- CI/CD Preservation: Keep existing pipelines functional throughout migration
2. Risk Mitigation
- Comprehensive Validation: Verify each migration step before proceeding
- Coverage Monitoring: Ensure test coverage never decreases
- Performance Tracking: Monitor test execution time impact
- Artifact Preservation: Maintain debugging capabilities throughout transition
3. Quality Assurance
- Functionality Preservation: All existing test scenarios maintained
- Enhanced Coverage: Add missing test scenarios identified in analysis
- Consistent Patterns: Apply unified architecture patterns incrementally
- Documentation Updates: Keep documentation current with each change
Migration Phases
Phase 1: Foundation Setup (Days 1-10)
Day 1-2: Environment Preparation
Objectives: Prepare development environment for incremental migration
Tasks:
-
Create Migration Branch
git checkout -b task-18-test-consolidation git checkout -b phase-1-foundation -
Setup Migration Tracking
# Create migration status file touch migration_status.json # Initialize with current test inventory -
Backup Current Test State
# Create snapshot of current test directory cp -r test/ test_backup_$(date +%Y%m%d) -
Validate Current Test Suite
# Run full test suite to establish baseline mix test --cover # Document current coverage and performance metrics
Success Criteria:
- ✅ Migration branch created and configured
- ✅ Current test suite passes completely
- ✅ Baseline metrics documented
- ✅ Backup created
Day 3-5: Core Utility Implementation
Objectives: Implement core shared utilities without disrupting existing tests
Tasks:
-
Create Shared Utility Directory
mkdir -p test/support/builders/unified -
Implement ManuscriptFixtures Module
- Create
test/support/builders/unified/manuscript_fixtures.ex - Implement core manuscript access functions
- Add comprehensive testing for the module itself
- Create
-
Implement UnifiedTestConfig Module
- Create
test/config/unified_test_config.ex - Implement configuration management
- Add environment variable support
- Create
-
Create Foundation Tests
# Test the new utilities themselves mkdir -p test/support/unified touch test/support/unified/manuscript_fixtures_test.exs touch test/support/unified/unified_test_config_test.exs
Success Criteria:
- ✅ ManuscriptFixtures module implemented and tested
- ✅ UnifiedTestConfig module implemented and tested
- ✅ No impact on existing test execution
- ✅ New utilities pass their own test suite
Day 6-8: TestOrchestrator Implementation
Objectives: Implement build orchestration without affecting existing tests
Tasks:
-
Implement TestOrchestrator Module
- Create
test/support/builders/unified/test_orchestrator.ex - Implement build coordination functions
- Add integration with Task #17's BuildOrchestrator
- Create
-
Create BuildManager Integration
- Create
test/support/builders/unified/build_manager.ex - Implement shared temporary directory support
- Add cleanup policy management
- Create
-
Test Orchestrator Validation
# Create isolated test for orchestrator touch test/support/unified/test_orchestrator_test.exs -
Integration Testing
# Test integration with existing build system mix test test/support/unified/ --only integration
Success Criteria:
- ✅ TestOrchestrator module implemented and tested
- ✅ Integration with Task #17 build system verified
- ✅ Shared temporary directory functionality working
- ✅ No disruption to existing test execution
Day 9-10: Enhanced Utilities
Objectives: Enhance existing utilities and create validation suite
Tasks:
-
Enhance FormatExtractors
- Extend existing
test/support/builders/content_consistency/format_extractors.ex - Add new extraction functions without breaking existing ones
- Implement caching and performance optimizations
- Extend existing
-
Enhance TestHelpers
- Extend existing
test/support/builders/content_consistency/test_helpers.ex - Add new helper functions while preserving existing interface
- Implement enhanced assertion helpers
- Extend existing
-
Create ValidationSuite
- Create
test/support/builders/unified/validation_suite.ex - Implement comprehensive validation functions
- Add cross-format consistency validation
- Create
-
Foundation Validation
# Run comprehensive test of all new utilities mix test test/support/unified/ --cover
Success Criteria:
- ✅ All utility modules implemented and tested
- ✅ Existing test functionality preserved
- ✅ Enhanced capabilities available for migration
- ✅ Performance baseline established
Phase 2: Parallel Implementation (Days 11-25)
Day 11-13: First Pilot Migration (PDF Tests)
Objectives: Create first unified test module alongside existing tests
Tasks:
-
Create Unified Test Structure
mkdir -p test/codexis/builders/unified/format_generation mkdir -p test/codexis/builders/unified/content_validation mkdir -p test/codexis/builders/unified/integration mkdir -p test/codexis/builders/unified/specialized -
Implement PDF Generation Tests
- Create
test/codexis/builders/unified/format_generation/pdf_generation_tests.ex - Use manuscript.tex as canonical source
- Implement comprehensive content validation
- Preserve all functionality from existing PDF builder test
- Create
-
Parallel Execution Setup
# Configure CI to run both old and new PDF tests # Add new test to test suite without removing old one -
Validation and Comparison
# Run both old and new PDF tests mix test test/codexis/builders/pdf_builder_test.exs mix test test/codexis/builders/unified/format_generation/pdf_generation_tests.exs # Compare coverage and performance
Success Criteria:
- ✅ New PDF tests implemented and passing
- ✅ Old PDF tests still passing unchanged
- ✅ Coverage equivalent or improved
- ✅ Performance within acceptable range
Day 14-16: Content Validation Migration
Objectives: Migrate content consistency tests to unified structure
Tasks:
-
Migrate Modular Content Tests
- Copy
test/codexis/builders/content_consistency/totest/codexis/builders/unified/content_validation/ - Update imports to use new unified utilities
- Enhance with new ValidationSuite capabilities
- Copy
-
Update Test References
- Update all internal references to use new utilities
- Preserve existing test interface for backward compatibility
- Add enhanced validation capabilities
-
Parallel Validation
# Run both old and new content consistency tests mix test test/codexis/builders/content_consistency/ mix test test/codexis/builders/unified/content_validation/ -
Performance Comparison
# Compare execution time and resource usage time mix test test/codexis/builders/content_consistency/ time mix test test/codexis/builders/unified/content_validation/
Success Criteria:
- ✅ Content validation tests migrated successfully
- ✅ All existing functionality preserved
- ✅ Enhanced validation capabilities working
- ✅ Performance maintained or improved
Day 17-19: HTML Generation Migration
Objectives: Migrate HTML builder tests (already using real manuscript)
Tasks:
-
Migrate HTML Builder Tests
- Create
test/codexis/builders/unified/format_generation/html_generation_tests.ex - Update to use TestOrchestrator for consistency
- Integrate with ValidationSuite
- Preserve chapter splitting and navigation tests
- Create
-
Integration Enhancement
- Add cross-format consistency validation
- Implement shared temporary directory usage
- Add performance monitoring
-
Validation
# Run parallel tests mix test test/codexis/builders/html_builder_test.exs mix test test/codexis/builders/unified/format_generation/html_generation_tests.exs
Success Criteria:
- ✅ HTML tests migrated with minimal changes required
- ✅ Shared temp directory integration working
- ✅ Cross-format validation enhanced
- ✅ All existing functionality preserved
Day 20-22: EPUB and DOCX Migration
Objectives: Migrate remaining major format builders
Tasks:
-
Migrate EPUB Builder Tests
- Create
test/codexis/builders/unified/format_generation/epub_generation_tests.ex - Replace mock content with manuscript.tex usage
- Integrate with shared build system
- Preserve EPUB-specific technical validation
- Create
-
Migrate DOCX Builder Tests
- Create
test/codexis/builders/unified/format_generation/docx_generation_tests.ex - Replace inline content with manuscript.tex
- Add comprehensive content validation
- Preserve dependency checking and error handling
- Create
-
Cross-Format Integration
# Test all migrated formats together mix test test/codexis/builders/unified/format_generation/
Success Criteria:
- ✅ EPUB and DOCX tests successfully migrated
- ✅ Manuscript.tex integration working for all formats
- ✅ Technical validation preserved
- ✅ Cross-format testing capabilities working
Day 23-25: Specialized Test Migration
Objectives: Migrate converter and infrastructure tests
Tasks:
-
Migrate Converter Tests
- Consolidate various converter tests in
test/codexis/builders/unified/specialized/ - Create
latex_processing_tests.ex,converter_tests.ex - Preserve targeted feature testing while adding manuscript integration
- Consolidate various converter tests in
-
Migrate Infrastructure Tests
- Create
infrastructure_tests.exfor temp cleanup, directory management - Integrate with shared temporary directory system
- Add comprehensive error handling tests
- Create
-
Create Integration Test Suite
- Create
test/codexis/builders/unified/integration/unified_build_tests.ex - Implement end-to-end testing of complete build pipeline
- Add performance and error handling tests
- Create
Success Criteria:
- ✅ All specialized tests migrated successfully
- ✅ Infrastructure tests enhanced with new capabilities
- ✅ Integration test suite implemented
- ✅ Complete test coverage maintained
Phase 3: Validation and Transition (Days 26-35)
Day 26-28: Comprehensive Validation
Objectives: Validate complete unified test suite against existing tests
Tasks:
-
Full Test Suite Comparison
# Run complete old test suite time mix test test/codexis/builders/ --exclude unified --cover # Run complete new test suite time mix test test/codexis/builders/unified/ --cover # Compare results -
Coverage Analysis
# Generate detailed coverage reports mix test --cover --export-coverage old_coverage mix test test/codexis/builders/unified/ --cover --export-coverage new_coverage # Compare coverage reports mix test.coverage --export-coverage old_coverage new_coverage -
Performance Analysis
# Run performance comparison mix test.bench test/codexis/builders/ --exclude unified mix test.bench test/codexis/builders/unified/ -
Gap Analysis
- Identify any missing functionality
- Validate all test scenarios preserved
- Check cross-format consistency improvements
Success Criteria:
- ✅ New test suite coverage >= old test suite coverage
- ✅ Performance within 10% of baseline
- ✅ All functionality preserved
- ✅ Enhanced capabilities working
Day 29-31: CI/CD Integration
Objectives: Integrate unified test suite into CI/CD pipeline
Tasks:
-
Update CI Configuration
# Update .github/workflows/test.yml - name: Run unified test suite run: | mix test test/codexis/builders/unified/ - name: Run legacy tests (parallel) run: | mix test test/codexis/builders/ --exclude unified -
Add Performance Monitoring
- name: Performance comparison run: | echo "Old test suite:" time mix test test/codexis/builders/ --exclude unified echo "New test suite:" time mix test test/codexis/builders/unified/ -
Add Coverage Reporting
- name: Coverage comparison run: | mix test --cover --export-coverage old_coverage test/codexis/builders/ --exclude unified mix test --cover --export-coverage new_coverage test/codexis/builders/unified/ mix test.coverage --compare old_coverage new_coverage -
Add Artifact Preservation
- name: Preserve test artifacts on failure if: failure() run: | find /tmp -name "codexis_test_*" -type d -exec cp -r {} test-artifacts/ \;
Success Criteria:
- ✅ CI/CD pipeline updated successfully
- ✅ Both old and new tests running in parallel
- ✅ Performance monitoring in place
- ✅ Artifact preservation working
Day 32-35: Gradual Cutover
Objectives: Begin transition from old to new test suite
Tasks:
-
Feature Flag Implementation
# Add environment variable to control test execution export CODEXIS_USE_UNIFIED_TESTS=true -
Gradual Format Transition
# Day 32: Transition PDF tests # Disable old PDF tests, rely on new ones # Day 33: Transition HTML and content consistency tests # Day 34: Transition EPUB and DOCX tests # Day 35: Transition specialized tests -
Monitoring and Validation
# Monitor each transition day mix test test/codexis/builders/unified/ --cover # Validate no regressions introduced -
Rollback Preparation
# Maintain ability to quickly rollback if issues found git tag pre-unified-tests
Success Criteria:
- ✅ Gradual transition completed successfully
- ✅ No test failures or regressions
- ✅ Performance maintained
- ✅ Rollback capability preserved
Phase 4: Cleanup and Finalization (Days 36-42)
Day 36-38: Remove Legacy Tests
Objectives: Remove old test files and cleanup redundant code
Tasks:
-
Archive Legacy Tests
# Move old tests to archive directory mkdir -p test/archived/pre_unified/ mv test/codexis/builders/pdf_builder_test.exs test/archived/pre_unified/ mv test/codexis/builders/epub_builder_test.exs test/archived/pre_unified/ mv test/codexis/builders/docx_builder_test.exs test/archived/pre_unified/ mv test/codexis/builders/wikijs_builder_test.exs test/archived/pre_unified/ mv test/codexis/builders/content_consistency_test.exs test/archived/pre_unified/ -
Remove Redundant Code
# Remove duplicate validation logic # Remove unused test utilities # Remove redundant test data files -
Update Test References
# Update any remaining references to old test files # Update documentation references # Update script references -
Cleanup Validation
# Run full test suite to ensure no broken references mix test # Validate all functionality still working
Success Criteria:
- ✅ Legacy tests archived (not deleted for safety)
- ✅ Redundant code removed
- ✅ All references updated
- ✅ Test suite still passing completely
Day 39-40: Documentation Updates
Objectives: Update all documentation to reflect new test architecture
Tasks:
-
Update Test Documentation
- Update
test/README.md - Create
docs/testing-architecture.md - Update
CLAUDE.mdtest section
- Update
-
Create Migration Documentation
- Document migration process completed
- Create troubleshooting guide
- Document new test patterns
-
Update Development Guides
- Update contributor guidelines
- Update testing best practices
- Update CI/CD documentation
-
API Documentation
- Add comprehensive module documentation
- Create usage examples
- Document configuration options
Success Criteria:
- ✅ All documentation updated and accurate
- ✅ Migration process documented
- ✅ New test patterns documented
- ✅ Developer guides updated
Day 41-42: Final Validation
Objectives: Complete final validation and optimization
Tasks:
-
Comprehensive Test Run
# Run complete test suite multiple times for i in {1..5}; do echo "Test run $i:" time mix test --cover done -
Performance Optimization
# Profile test execution mix test --trace # Optimize any slow tests identified -
Coverage Verification
# Generate final coverage report mix test --cover # Verify coverage meets or exceeds original baseline -
Final Documentation Review
- Review all documentation for accuracy
- Validate code examples work
- Check for any missing information
Success Criteria:
- ✅ Test suite performance optimized
- ✅ Coverage verified and documented
- ✅ All documentation accurate and complete
- ✅ Migration fully validated and complete
Risk Management
High-Risk Scenarios and Mitigation
Scenario 1: CI/CD Pipeline Failure
Risk: New tests break CI/CD pipeline, blocking development
Mitigation:
- Parallel Execution: Run both old and new tests during transition
- Feature Flags: Use environment variables to control test execution
- Rollback Plan: Maintain tagged versions for quick rollback
- Monitoring: Add alerts for test execution time and failure rates
Recovery Process:
# Quick rollback if CI fails
git revert <last-migration-commit>
# or
export CODEXIS_USE_UNIFIED_TESTS=false
Scenario 2: Performance Regression
Risk: New test suite significantly slower than original
Mitigation:
- Performance Monitoring: Track execution time at each migration step
- Optimization Points: Identify and optimize slow tests immediately
- Parallel Execution: Use async testing where possible
- Caching: Implement intelligent caching for repeated operations
Recovery Process:
# If performance regression detected
mix test.bench --compare baseline.bench current.bench
# Identify slow tests and optimize
# Revert specific changes if necessary
Scenario 3: Test Coverage Loss
Risk: Migration results in reduced test coverage
Mitigation:
- Coverage Tracking: Monitor coverage at each migration step
- Gap Analysis: Identify and fill any coverage gaps immediately
- Comprehensive Validation: Verify all test scenarios preserved
- Enhanced Testing: Add missing test scenarios identified in analysis
Recovery Process:
# If coverage loss detected
mix test --cover --export-coverage current
mix test.coverage --compare baseline.coverage current.coverage
# Identify missing coverage and add tests
Scenario 4: Functionality Loss
Risk: Migration loses important test functionality
Mitigation:
- Comprehensive Mapping: Document all existing functionality before migration
- Incremental Validation: Validate each migration step preserves functionality
- Parallel Testing: Run old and new tests in parallel for comparison
- Review Process: Code review for each migration step
Recovery Process:
# If functionality loss detected
# Identify missing functionality from mapping document
# Implement missing functionality in new test structure
# Validate with side-by-side comparison
Monitoring and Alerts
CI/CD Monitoring
# Add to CI pipeline
- name: Monitor test performance
run: |
TEST_TIME=$(time mix test 2>&1 | grep real | awk '{print $2}')
if [[ $TEST_TIME > "10m" ]]; then
echo "WARNING: Test execution time exceeded 10 minutes"
exit 1
fi
- name: Monitor test coverage
run: |
COVERAGE=$(mix test --cover | grep "Total coverage" | awk '{print $3}' | sed 's/%//')
if [[ $COVERAGE < 85 ]]; then
echo "WARNING: Test coverage below 85%"
exit 1
fi
Automated Alerts
- Slack notifications for test failures
- Email alerts for performance regressions
- Dashboard monitoring for coverage trends
Success Metrics
Quantitative Metrics
Test Execution Performance
- Baseline: Current test suite execution time
- Target: Within 110% of baseline execution time
- Measurement: Average of 5 consecutive test runs
Test Coverage
- Baseline: Current test coverage percentage
- Target: Maintain or improve coverage (>=95% of baseline)
- Measurement: Line and branch coverage analysis
Code Reduction
- Target: 30-40% reduction in test code volume
- Measurement: Lines of code in test files before/after
Maintenance Effort
- Target: Reduce time to add new format support by 50%
- Measurement: Time tracking for test updates
Qualitative Metrics
Code Quality
- ✅ Consistent test patterns across all modules
- ✅ Unified manuscript.tex usage as canonical source
- ✅ Comprehensive error handling and debugging support
- ✅ Clear separation of concerns
Developer Experience
- ✅ Easier test maintenance and updates
- ✅ Clear documentation and examples
- ✅ Consistent development patterns
- ✅ Improved debugging capabilities
System Reliability
- ✅ Reduced test brittleness
- ✅ Better error reporting
- ✅ Improved test isolation
- ✅ Enhanced cross-format validation
Communication Plan
Stakeholder Updates
Daily Standups
- Progress updates on current migration phase
- Any blockers or issues encountered
- Performance and coverage metrics
- Risk mitigation status
Weekly Reports
- Detailed progress against timeline
- Performance and coverage trends
- Risk assessment updates
- Upcoming phase planning
Phase Completion Reports
- Comprehensive validation results
- Success criteria verification
- Lessons learned documentation
- Next phase preparation status
Documentation Updates
Real-time Updates
- Migration status tracking
- Current test execution instructions
- Known issues and workarounds
Phase Completion Documentation
- Completed migration documentation
- Updated development guides
- Enhanced troubleshooting documentation
Rollback Strategy
Immediate Rollback (Emergency)
# If critical issue discovered
git checkout main
git revert --no-edit $(git log --oneline task-18-test-consolidation..HEAD | awk '{print $1}')
Selective Rollback (Specific Issues)
# Rollback specific test module
git checkout main -- test/codexis/builders/old_module_test.exs
# Temporarily disable new module
mv test/codexis/builders/unified/new_module_tests.ex test/disabled/
Gradual Rollback (Performance Issues)
# Gradually revert to old tests while keeping infrastructure
export CODEXIS_USE_UNIFIED_TESTS=false
# Keep new utilities but use old test structure temporarily
This incremental migration plan provides a comprehensive, low-risk approach to consolidating the test suites while maintaining full CI/CD functionality and preserving all existing test capabilities throughout the transition process.