operations / docs /STEP11_LEGACY_CODE_REMOVAL_PLAN.md
jbbove's picture
🎯 Complete OMIRL web services refactoring with workflow enhancement
36f8fda

Legacy Code Removal Plan for OMIRL Web Services

Overview

After successful migration to the new web services architecture, we can now safely remove legacy OMIRL-specific code that has been replaced by the generic architecture.

Migration Status βœ…

  • βœ… OMIRL adapter migrated to use new architecture via compatibility layer
  • βœ… All integration tests passing
  • βœ… All compatibility tests passing
  • βœ… Performance validated
  • βœ… Zero breaking changes confirmed

Files Safe to Remove

1. Core Legacy Files (OMIRL-Specific)

services/web/browser.py (468 lines)

  • βœ… SAFE TO REMOVE
  • Replaced by: services/web/generic_browser.py + services/web/configs/omirl_config.py
  • All OMIRL-specific browser knowledge moved to configuration
  • No longer used by OMIRL adapter (uses compat layer)

services/web/table_scraper.py (465 lines)

  • βœ… SAFE TO REMOVE
  • Replaced by: services/web/generic_table.py + services/web/adapters/omirl_adapter.py
  • All OMIRL table scraping logic preserved in new architecture
  • No longer used by OMIRL adapter (uses compat layer)

2. Files That Need to Stay

services/web/compat.py

  • ❌ KEEP - Provides backward compatibility layer
  • Used by OMIRL adapter for seamless migration
  • Wraps new architecture with old API

services/web/configs/omirl_config.py

  • ❌ KEEP - Contains all preserved OMIRL knowledge
  • Essential for new architecture functionality
  • Centralizes all OMIRL-specific configuration

services/web/adapters/omirl_adapter.py

  • ❌ KEEP - New OMIRL implementation using generic components
  • Core of the new architecture
  • Provides same functionality as old files but more maintainable

services/web/generic_*.py and base.py

  • ❌ KEEP - Core new architecture components
  • Generic, reusable for future websites
  • Foundation of the new system

Files That Reference Legacy Code

Files Still Using Legacy Imports (Need Updates)

  1. scripts/discovery/test_massimi_precipitazioni.py

    • Current: from services.web.table_scraper import fetch_omirl_massimi_precipitazioni
    • Change to: from services.web.compat import fetch_omirl_massimi_precipitazioni
  2. scripts/discovery/test_valori_stazioni_after_changes.py

    • Current: from services.web.table_scraper import fetch_omirl_stations
    • Change to: from services.web.compat import fetch_omirl_stations
  3. services/media/init.py (Line 52-53)

    • Current: from services.web.browser import get_browser_context
    • Current: from services.web.table_scraper import extract_table_data
    • Note: This needs investigation - media services might need different solution

Test Files Using Legacy Imports

  1. tests/omirl/test_fast.py

    • Uses @patch('services.web.table_scraper.fetch_omirl_stations')
    • Change to: @patch('services.web.compat.fetch_omirl_stations')
  2. tests/test_omirl_implementation.py

    • Uses from services.web.browser import _browser_manager
    • Change to: Use new architecture browser management
  3. tests/omirl/performance_analysis.py

    • Uses from services.web.browser import close_all_browser_sessions
    • Change to: from services.web.compat import close_all_browser_sessions

Removal Steps (Safe Order)

Phase 1: Update Remaining References

  1. Update discovery scripts to use compat layer
  2. Update test files to use compat layer
  3. Investigate and fix media services imports
  4. Run full test suite to validate changes

Phase 2: Remove Legacy Files

  1. Move browser.py to browser_legacy.py (backup)
  2. Move table_scraper.py to table_scraper_legacy.py (backup)
  3. Run full test suite
  4. If all tests pass, delete backup files

Phase 3: Clean Up (Optional)

  1. Remove any remaining references to old files
  2. Update documentation
  3. Remove backup files after confidence period

Risk Assessment

Low Risk βœ…

  • Legacy files are no longer used by production OMIRL adapter
  • Compatibility layer provides identical API
  • All functionality preserved in new architecture
  • Easy rollback by renaming files back

Medium Risk ⚠️

  • Some test files need updates
  • Discovery scripts need updates
  • Media services import needs investigation

High Risk ❌

  • None identified - migration was successful

Validation Plan

Before Removal

# Ensure all current tests pass
python tests/test_omirl_integration.py
python tests/omirl/test_adapter_integration.py
python tests/services/test_compatibility.py

After Each Step

# Validate specific functionality
python -c "from services.web.compat import fetch_omirl_stations; print('βœ… Import works')"
python tests/test_omirl_integration.py

Final Validation

# Complete integration test
python tests/services/test_integration.py

Benefits of Removal

  1. Reduced Codebase: ~933 lines of legacy code removed
  2. No Confusion: Only one way to do OMIRL scraping
  3. Easier Maintenance: Generic architecture easier to extend
  4. Better Testing: New architecture has comprehensive test coverage
  5. Future-Proof: Ready for additional websites

Rollback Plan

If issues discovered after removal:

  1. Restore files from git: git checkout HEAD -- services/web/browser.py services/web/table_scraper.py
  2. Update OMIRL adapter imports back to legacy files
  3. Investigate and fix new architecture issues
  4. Re-attempt removal after fixes

Success Criteria

Removal is successful when:

  1. All OMIRL functionality works unchanged
  2. All tests pass
  3. No import errors
  4. No references to removed files
  5. New architecture handles all use cases
  6. Performance maintained or improved