feat(cli): enhanced summary, graceful Ctrl+C, integration tests (closes #9)

Summary output now lists each failed book (ISBN + title + reason)
and each skipped book (ISBN + title) in both plain-text and rich/TTY
formats. Ctrl+C produces a clean shutdown message with exit code 130
instead of a Python traceback. Three integration tests exercise the
full run() pipeline: happy path, mixed results, and fatal auth failure.

12 new tests (168 total), 15/15 acceptance criteria met.
This commit is contained in:
AlexKucera committed 2026-06-03 15:00:27 +02:00
1 parent 351ded2478
commit 4aaae68a2e
7 files changed
+706 -128

No files matched your search

+52 -4
View File
@@ -40,10 +40,38 @@ class PlainTextReporter:
def update(self, completed: int, *, total: int | None = None) -> None:
"""No-op progress update — plain text mode has no progress bar."""
def summary(self, downloaded: int, skipped: int, failed: int) -> None:
"""Print summary line."""
def summary(
self,
downloaded: int,
skipped: int,
failed: int,
*,
failed_books: list[tuple] | None = None,
skipped_books: list | None = None,
) -> None:
"""Print summary line with optional per-book details.
Args:
downloaded: Count of successfully downloaded books.
skipped: Count of skipped books.
failed: Count of failed books.
failed_books: List of (book, reason) tuples for each failure.
skipped_books: List of Book objects that were skipped.
"""
self._print(f"\nSummary: {downloaded} downloaded, {skipped} skipped, {failed} failed")
if failed_books:
self._print(" Failed:")
for book, reason in failed_books:
authors = ", ".join(book.authors) if book.authors else "Unknown"
self._print(f" ✗ {authors} - {book.title} [{book.isbn}] ({reason})")
if skipped_books:
self._print(" Skipped:")
for book in skipped_books:
authors = ", ".join(book.authors) if book.authors else "Unknown"
self._print(f" ⏭ {authors} - {book.title} [{book.isbn}]")
def _print(self, message: str) -> None:
self._out.write(message + "\n")
self._out.flush()
@@ -117,12 +145,32 @@ class ProgressReporter:
self._console.print(f" [red]✗[/red] {book.title}[dim] [{book.isbn}]{detail}[/dim]")
self._current_task = None
def summary(self, downloaded: int, skipped: int, failed: int) -> None:
"""Print summary line and stop progress."""
def summary(
self,
downloaded: int,
skipped: int,
failed: int,
*,
failed_books: list[tuple] | None = None,
skipped_books: list | None = None,
) -> None:
"""Print summary line with optional per-book details and stop progress."""
if self._progress:
self._progress.stop()
self._console.print(f"\n[bold]Summary:[/bold] {downloaded} downloaded, {skipped} skipped, {failed} failed")
if failed_books:
self._console.print(" [red]Failed:[/red]")
for book, reason in failed_books:
authors = ", ".join(book.authors) if book.authors else "Unknown"
self._console.print(f" ✗ {authors} - {book.title} [{book.isbn}] ({reason})")
if skipped_books:
self._console.print(" [yellow]Skipped:[/yellow]")
for book in skipped_books:
authors = ", ".join(book.authors) if book.authors else "Unknown"
self._console.print(f" ⏭ {authors} - {book.title} [{book.isbn}]")
def _fmt_size(bytes_val: int) -> str:
"""Format byte count as human-readable size string."""