Slice 2: Wire selector into sync_run pipeline — TTY guard, --limit superseded, integration tests #48

Closed
opened 2026-06-06 10:45:24 +02:00 by AlexKucera · 1 comment
AlexKucera commented 2026-06-06 10:45:24 +02:00 (Migrated from github.com)

Parent

#20 (Feature: Interactive Book Selection --select)

What to build

Replace the select_mode stub in sync_run.py (currently prints "not yet implemented" and returns) with the real selection pipeline. When select_mode=True, after filtering already-downloaded books and before the download loop:

  1. TTY check — if sys.stdout.isatty() is False, print an error message ("--select requires an interactive terminal") and return SyncRunResult(fatal_error=...). Exit code 1 via cli.py. This prevents cron/non-interactive hangs (user story 7).

  2. All caught up — if no undownloaded books remain, print "All caught up!" and exit 0 (identical to current behavior, user story 9).

  3. Convert to Books — convert the filtered raw dicts to Book objects using from_library_row() from book.py.

  4. Call selector — selector.select_books(books). If it returns an empty list, exit 0 (user story 10).

  5. Pass to orchestrator — convert selected Book objects back to a format the orchestrator accepts, or pass them directly. The orchestrator currently takes list[dict] and calls from_library_row() internally, so selected Books need to flow through without double-conversion. The cleanest approach: pass selected Books as a list and skip the orchestrator's internal from_library_row conversion when Book objects are already provided (or convert Books back to raw dicts for compatibility).

  6. --limit superseded — when select_mode is True, --limit is explicitly ignored (not applied). Print a verbose-mode note: "Selection mode active — --limit is superseded by manual selection." (user story 13)

  7. Default off, no config option — --select is off by default and has no config.yaml key. Existing scripts and cron jobs are completely unaffected (user story 12).

Integration tests should cover: no-TTY error exit, all-caught-up path with select mode, empty selection exit 0, selected books flow correctly to the orchestrator/download function, --limit ignored when select is active.

Acceptance criteria

  • select_mode stub in sync_run.py replaced with real pipeline
  • No TTY → SyncRunResult(fatal_error=...) with clear error message
  • All-caught-up path works identically with and without --select
  • from_library_row() converts filtered raw dicts to Books before calling select_books()
  • Empty selection from select_books() → clean exit 0
  • Selected Books flow into the download orchestrator correctly (no double-conversion)
  • --limit is ignored when --select is active, with verbose note
  • --select has no config.yaml option — CLI-only, off by default
  • --select flag in argparse no longer says "[not implemented]"
  • Integration tests in test_sync_run.py cover: no-TTY error, all-caught-up, empty selection, selected→orchestrator flow, limit-ignored
  • Existing tests continue to pass (no regressions)

Blocked by

  • #47 (Slice 1: selector.py module)
## Parent #20 (Feature: Interactive Book Selection `--select`) ## What to build Replace the `select_mode` stub in `sync_run.py` (currently prints "not yet implemented" and returns) with the real selection pipeline. When `select_mode=True`, after filtering already-downloaded books and before the download loop: 1. **TTY check** — if `sys.stdout.isatty()` is False, print an error message ("--select requires an interactive terminal") and return `SyncRunResult(fatal_error=...)`. Exit code 1 via cli.py. This prevents cron/non-interactive hangs (user story 7). 2. **All caught up** — if no undownloaded books remain, print "All caught up!" and exit 0 (identical to current behavior, user story 9). 3. **Convert to Books** — convert the filtered raw dicts to `Book` objects using `from_library_row()` from `book.py`. 4. **Call selector** — `selector.select_books(books)`. If it returns an empty list, exit 0 (user story 10). 5. **Pass to orchestrator** — convert selected `Book` objects back to a format the orchestrator accepts, or pass them directly. The orchestrator currently takes `list[dict]` and calls `from_library_row()` internally, so selected Books need to flow through without double-conversion. The cleanest approach: pass selected Books as a list and skip the orchestrator's internal `from_library_row` conversion when Book objects are already provided (or convert Books back to raw dicts for compatibility). 6. **`--limit` superseded** — when `select_mode` is True, `--limit` is explicitly ignored (not applied). Print a verbose-mode note: "Selection mode active — --limit is superseded by manual selection." (user story 13) 7. **Default off, no config option** — `--select` is off by default and has no `config.yaml` key. Existing scripts and cron jobs are completely unaffected (user story 12). Integration tests should cover: no-TTY error exit, all-caught-up path with select mode, empty selection exit 0, selected books flow correctly to the orchestrator/download function, `--limit` ignored when select is active. ## Acceptance criteria - [ ] `select_mode` stub in `sync_run.py` replaced with real pipeline - [ ] No TTY → `SyncRunResult(fatal_error=...)` with clear error message - [ ] All-caught-up path works identically with and without `--select` - [ ] `from_library_row()` converts filtered raw dicts to Books before calling `select_books()` - [ ] Empty selection from `select_books()` → clean exit 0 - [ ] Selected Books flow into the download orchestrator correctly (no double-conversion) - [ ] `--limit` is ignored when `--select` is active, with verbose note - [ ] `--select` has no config.yaml option — CLI-only, off by default - [ ] `--select` flag in argparse no longer says "[not implemented]" - [ ] Integration tests in `test_sync_run.py` cover: no-TTY error, all-caught-up, empty selection, selected→orchestrator flow, limit-ignored - [ ] Existing tests continue to pass (no regressions) ## Blocked by - #47 (Slice 1: selector.py module)
AlexKucera commented 2026-06-06 12:14:14 +02:00 (Migrated from github.com)

Implemented in fa1543e. All 11 acceptance criteria met, 304 tests pass with 0 regressions.

Implemented in fa1543e. All 11 acceptance criteria met, 304 tests pass with 0 regressions.
Sign in to join this conversation.