Slice 6: Factor common success-path from format-strategy branches #42

Closed
opened 2026-06-05 18:11:30 +02:00 by AlexKucera · 1 comment
AlexKucera commented 2026-06-05 18:11:30 +02:00 (Migrated from github.com)

Parent

#36 — PRD-003: Deepen Codebase Architecture

What to build

Factor out the repeated post-download success logic from the three format-strategy blocks in download_book() (m4b_mp3_fallback, mp3_only, m4b_only). Each branch currently repeats: rename chapters → download accompanying files → return success DownloadResult. Extract this into a shared helper so each branch becomes: attempt download → if success, call success helper → return result.

Acceptance criteria

  • A private helper (e.g., _finalize_download()) handles rename_chapters + accompanying_files + success DownloadResult
  • All three format-strategy branches call the shared helper on success
  • No duplicated rename/accompany/return-success code across branches
  • All existing format-strategy tests pass (fallback, mp3_only, m4b_only)
  • Full test suite passes
  • Adding a new format strategy in the future requires only writing the download attempt + calling the existing success helper

Blocked by

#41 — Slice 5 (extract streaming loop) should land first so the function being refactored has stabilized

## Parent #36 — PRD-003: Deepen Codebase Architecture ## What to build Factor out the repeated post-download success logic from the three format-strategy blocks in `download_book()` (m4b_mp3_fallback, mp3_only, m4b_only). Each branch currently repeats: rename chapters → download accompanying files → return success DownloadResult. Extract this into a shared helper so each branch becomes: attempt download → if success, call success helper → return result. ## Acceptance criteria - [ ] A private helper (e.g., `_finalize_download()`) handles rename_chapters + accompanying_files + success DownloadResult - [ ] All three format-strategy branches call the shared helper on success - [ ] No duplicated rename/accompany/return-success code across branches - [ ] All existing format-strategy tests pass (fallback, mp3_only, m4b_only) - [ ] Full test suite passes - [ ] Adding a new format strategy in the future requires only writing the download attempt + calling the existing success helper ## Blocked by #41 — Slice 5 (extract streaming loop) should land first so the function being refactored has stabilized
AlexKucera commented 2026-06-05 19:12:21 +02:00 (Migrated from github.com)

Closed via bf7e474 — extracted _finalize_download() helper. 4 new tests, 126 total in test_downloader.py, full suite passes.

Closed via `bf7e474` — extracted `_finalize_download()` helper. 4 new tests, 126 total in test_downloader.py, full suite passes.
Sign in to join this conversation.