name: Temporary full safe modularization

on:
  push:
    paths:
      - tools/apply_full_safe_modularization.py
      - tools/fix_modularization_ast_spans.py
      - tools/fix_modularization_shared_state.py
      - .github/workflows/temp-full-safe-modularization.yml
  workflow_dispatch:

permissions:
  contents: write

jobs:
  modularize:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: '3.12'
      - name: Install project dependencies
        run: |
          python -m pip install --upgrade pip
          if [ -f requirements.txt ]; then python -m pip install -r requirements.txt; fi
          python -m pip install filelock
      - name: Repair AST source spans
        run: python tools/fix_modularization_ast_spans.py
      - name: Repair shared state compatibility
        run: python tools/fix_modularization_shared_state.py
      - name: Apply safe modularization
        run: python tools/apply_full_safe_modularization.py
      - name: Verify Python syntax
        run: python -m compileall -q .
      - name: Run full unit test suite
        run: python -m unittest discover -s tests -p 'test_*.py'
      - name: Commit modularized source and cleanup
        run: |
          git config user.name "github-actions[bot]"
          git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
          git rm -f \
            tools/apply_full_safe_modularization.py \
            tools/fix_modularization_ast_spans.py \
            tools/fix_modularization_shared_state.py \
            tools/build_refactor_inventory.py \
            refactor_inventory.json \
            .github/workflows/temp-refactor-inventory.yml \
            .github/workflows/temp-full-safe-modularization.yml
          git add -A
          git commit -m "refactor: modularize registration runtime safely"
          git push
