bindery-cli 0.59.0__tar.gz → 0.60.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/AGENTS.md +5 -4
  2. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/PKG-INFO +1 -1
  3. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/patchnotes.md +42 -0
  4. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/pyproject.toml +1 -1
  5. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/roadmap.md +1 -0
  6. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/src/bindery/__init__.py +1 -1
  7. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/src/bindery/validate.py +33 -7
  8. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/tests/test_validate.py +64 -6
  9. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/uv.lock +1 -1
  10. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/.github/FUNDING.yml +0 -0
  11. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/.github/workflows/ci.yml +0 -0
  12. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/.github/workflows/publish.yml +0 -0
  13. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/.gitignore +0 -0
  14. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/LICENSE +0 -0
  15. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/OBSERVE-RESEARCH.md +0 -0
  16. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/README.md +0 -0
  17. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/docs/screenshots/library-sweep.png +0 -0
  18. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/logo.svg +0 -0
  19. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/plugin/__init__.py +0 -0
  20. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/project.done +0 -0
  21. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/run_tests.sh +0 -0
  22. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/scripts/FastSweep.java +0 -0
  23. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/scripts/build_plugin.py +0 -0
  24. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/scripts/fast_sweep.py +0 -0
  25. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/spec.md +0 -0
  26. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/src/bindery/__main__.py +0 -0
  27. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/src/bindery/audit.py +0 -0
  28. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/src/bindery/cli.py +0 -0
  29. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/src/bindery/epub.py +0 -0
  30. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/src/bindery/library.py +0 -0
  31. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/src/bindery/observe.py +0 -0
  32. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/src/bindery/pagination.py +0 -0
  33. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/src/bindery/reserialize.py +0 -0
  34. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/src/bindery/transforms.py +0 -0
  35. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/src/bindery/watermark.py +0 -0
  36. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/tests/test_audit.py +0 -0
  37. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/tests/test_cli.py +0 -0
  38. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/tests/test_comment_hyphens.py +0 -0
  39. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/tests/test_contamination.py +0 -0
  40. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/tests/test_cover_tocdrift.py +0 -0
  41. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/tests/test_epub.py +0 -0
  42. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/tests/test_flags_real_core.py +0 -0
  43. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/tests/test_flags_wiring.py +0 -0
  44. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/tests/test_help.py +0 -0
  45. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/tests/test_library.py +0 -0
  46. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/tests/test_matcher_hardening.py +0 -0
  47. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/tests/test_observe.py +0 -0
  48. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/tests/test_pagination.py +0 -0
  49. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/tests/test_plugin.py +0 -0
  50. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/tests/test_reserialize.py +0 -0
  51. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/tests/test_space_renames.py +0 -0
  52. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/tests/test_spine_guard.py +0 -0
  53. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/tests/test_transforms.py +0 -0
  54. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/tests/test_version.py +0 -0
  55. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/tests/test_watermark.py +0 -0
  56. {bindery_cli-0.59.0 → bindery_cli-0.60.0}/tests/test_xml_hardening.py +0 -0
@@ -191,8 +191,9 @@ Born from the 2026 library audit (see the user memory `calibre-library-epubcheck
191
191
  (their gain is invisible to epubcheck, so it only forbids a regression, never demands
192
192
  a measured improvement). The structural opt-ins go through the normal `gate` (their
193
193
  gain IS visible, so a run with no measurable improvement is a noop and nothing is
194
- applied) except the two whose gains sit on axes epubcheck does not measure:
195
- `--fix-cover` and `--encode-url-spaces`, accepted under the same `no_worse` bar with
194
+ applied) except the three whose gains sit on axes epubcheck does not measure:
195
+ `--fix-cover`, `--encode-url-spaces`, and `--fix-media-types` (the font half,
196
+ v0.56.0), accepted under the same `no_worse` bar with
196
197
  the partial rule intact. One masked-axis rule (v0.51.0, issue #9, for the
197
198
  NCX sync; generalized v0.57.0, issue #22, to every fired fix): when the gate
198
199
  answers noop on a book that started AND stayed fatal, `process_book`
@@ -230,13 +231,13 @@ Born from the 2026 library audit (see the user memory `calibre-library-epubcheck
230
231
  character references before the fragment split (attribute text arrives
231
232
  escaped; entries are raw; decoding first keeps the `#` inside `&`
232
233
  from cutting the target), `_ITEM_TAG_RE`/`_SPINE_ITEM_RE`/`_GUIDE_REF_RE`/prune_dangling_edges' matcher accept an optional ns prefix (`<opf:item>`), and the renamed-reference spellings percent-encode `[`/`]` (`_encode_ref_path`). Since v0.52.0 (issue #10): `spine_dangles(src)` walks itemref -> manifest item -> archive entry through `_resolve_href`+`_norm_path` (None on an unreadable package: the veto needs evidence, never fires on a probe failure), and `prune_missing_manifest_items` derives its spine protection from the text it prunes (no snapshot parameter: fix_manifest_ids renames ids ahead of it, and the existence set it checks against must be the layout its hrefs are written in — `present_src` when space renames are active, matching the content-doc prune). Since v0.46.0 the opt-in selection is the `RepairFlags` dataclass (one field per flag, all off by default; the all-off instance IS the default pass): `repair_epub(src, dst, flags)` and `process_book(..., flags)` take one object instead of a ~25-kwarg signature, the EPUB2-targeted fixes' version gate swaps in a `dataclasses.replace` copy (never mutating the caller's instance), and the plugin's bare `repair_epub(src, dst)` call constructs exactly the all-off default pass. Since v0.55.0 (issue #16) the RSC-008 half lives beside the prune: `collect_undeclared_resources` (one whole-book census: content img/link, inline `<style>` url(), stylesheet url(), OPF guide refs) + `declare_missing_manifest_items` (sorted `bindery-dN` items before `</manifest>`, `_DECLARE_MEDIA_TYPES` blessed extensions only), gated and threaded through `RepairFlags.declare_missing`. Since v0.38.0/v0.39.0 (Phase 16): `generate_container` + the `--fix-container` gateway (insert after mimetype when missing, replace in-loop when stale; constant-epoch timestamp keeps bytes deterministic), `prune_dangling_edges` (prune_missing_manifest_items returns the pruned ids and the edges that pointed at them (spine@toc, media-overlay, fallback, EPUB2 cover meta) are rewritten so pruning cannot manufacture the regression the gate rejects), and `fix_manifest_media_types` (extension map + magic-byte confirmation via a `peek` callable over the open source zip; jpg/png/gif only), and `fix_cover_meta` (the ruling's deterministic half: dangling EPUB2 cover meta re-pointed from the guide's cover reference when exactly one manifest item carries that file, removed otherwise; accepted under no_worse like the lossy strips because cover wiring is invisible to epubcheck).
233
- - `src/bindery/validate.py`: epubcheck wrapper, the `gate` (improvement) and `no_worse` (no-regression, for the lossy strips) acceptance bars. Since v0.55.0 (issue #15) the default oracle budget is size-scaled (`oracle_timeout_for`: 300s at or under 10 MB, +60s per started 10 MB above, 1800s cap), one subprocess retry follows a timed-out attempt (the daemon path's subprocess fallback is that attempt), and only a double timeout raises `OracleTimeout`, which the gate surfaces as `(epubcheck timeout)` instead of `(epubcheck failed)` (the sweep selectors catch it and keep the book a candidate).
234
+ - `src/bindery/validate.py`: epubcheck wrapper, the `gate` (improvement) and `no_worse` (no-regression, for the lossy strips) acceptance bars. Since v0.55.0 (issue #15) the default oracle budget is size-scaled (`oracle_timeout_for`: 300s at or under 10 MB, +60s per started 10 MB above, 1800s cap), one subprocess retry follows a timed-out attempt (the daemon path's subprocess fallback is that attempt), and only a double timeout raises `OracleTimeout`, which the gate surfaces as `(epubcheck timeout)` instead of `(epubcheck failed)` (the sweep selectors catch it and keep the book a candidate). Since v0.60.0 (issue #24) the size term counts decimal MB (10,440,245 bytes is 9.96 binary MiB, so the book the docs call 10.4 MB computed the flat 300s base with no size chunk), and the budget also scales on archive entry count (+60s per started 500 entries above 1,000; a path that does not open as a zip falls back to size-only): the Summa Theologica is entry-count-bound, not bytes-bound (3,831 entries / 3,808 spine docs; measured 384s source and 445s candidate), and now computes 720s.
234
235
  - `src/bindery/library.py`: Calibre walk, atomic replace, backups, and native format installation. Since v0.19.0 `CalibreIdResolver` resolves the book id from `metadata.db` through cquarry (one lazy path→id map per run; since v0.20.0 the map comes from `CalibreDB.format_path_index()`, re-normalized with `resolve().lower()` for the resolver's symlinked-directory and case-insensitive matching); the `(id)` directory-name regex is only the no-catalog fallback. Since v0.24.0 `install_format()` places the repaired file atomically and updates the `data` row through `cquarry.write.WritableCalibreDB` (since v0.31.0 via `set_format`, cquarry 1.17's sanctioned remove+add in one transaction); the external `calibredb` CLI is gone. Since v0.32.0 a guessed id drives a row update only when metadata.db corroborates it (`_verify_guess`: books row exists, file in the book's own directory, catalogued `data.name` when a row exists); anything else saves in place and leaves the catalog untouched: never reintroduce directory-name guessing as the primary source: renamed/mismatched directories would replace the wrong book. Since 2026-09-15 `make_backup` takes the opt-in `--backup-keep N` ring: at most N backup files per book, the author original `.bak` never deleted, newest content at the highest name; default remains an unbounded rotation.
235
236
  - `src/bindery/cli.py`: `repair` and `library` subcommands, including `--all` and `--install-to-calibre`; since v0.52.0 `process_book` carries the spine-resolution veto (issue #10) above every verdict path, promotions included: a candidate whose spine dangles more than the source's is `reject` with `(spine collapse)` appended to the summary, whatever the counts say. `repair --json` emits the library per-book record vocabulary (2026-09-15; since v0.45.0 every per-book record, the phase1 payload included, also carries the structured fix breakdown: the `fixes` dict plus `ncx_uid_synced`/`watermark_refusals` off the `Outcome`, and `_phase1_decisions` reads that data instead of substring-matching the rendered `summary`, which stays for human eyes; CalibreQuarry's lossy-consent mirror is the waiting consumer, floor `bindery>=0.45.0`); since v0.29.0 also the `run` verbs: `phase1` (pre-import vetting over loose files: the audit battery composed with one gated repair sweep; read-only until `--apply-lossy`, which IS the lossy-strip consent) and `phase3` (the scoped post-import apply step: `library --id --sweep --only all --apply --all --install-to-calibre` plus a pre/post summary; mechanically refuses unscoped sweeps with exit 2; since 2026-09-15 the summary sums applied/equal states only and carries rejected projections as `rejected_projection`). Plus `bindery doctor` (2026-09-15): the environment self-check that imports none of the VirInvictus stack, never raises, and always exits 0. The `observe` verb (v0.53.0) writes schema v2 artifacts since v0.55.0 (issue #13): `codes.messages` (renamed from the mislabeled `occurrences`) counts aggregated epubcheck JSON message entries, `codes.occurrences` now carries the true per-site scale (summed `locations`), a `counting` block states both scales in the artifact, and `--against` accepts v1 or v2 (the trend keys exist in both). Both run verbs take `--non-interactive` and surface open questions as `decisions_needed` in their JSON, never prompts. They drive the shipped `run_library` through the real parser, so no flag can drift between the verb and the subcommand it wraps. Since v0.46.0 `cli._flags_from_args(args)` is the one place the argparse names map onto `RepairFlags` fields (each `or --all`), shared by `run_library` and `run_repair`; the old per-verb ~25-kwarg blocks are gone. Since v0.47.1 the help is two-level (the --help-repairs reference is
236
237
  custom-rendered and colors itself with the CPython 3.14 argparse theme,
237
238
  gated by argparse's own _colorize detection so the levels always agree) and the repair-flag inventory is one table: `_REPAIR_FLAG_TABLE` (dest + one-line short help + long reference text) registers the compact grouped `--help` (argparse argument groups, hand-short usage line) and `--help-repairs` renders the long descriptions (a custom argparse Action, deliberately NOT store_true so the wiring test's selection count ignores it); adding a flag means adding a table row. Since v0.48.0 the metadata.db doors are enforced: `_require_closed_calibre` (pgrep fail-closed, exit 1) guards `audit --tag` and `library --apply --install-to-calibre` (run phase3 transitively), and `--help-json` (a custom argparse Action like --help-repairs, never colored) dumps the per-verb exit contract and the door list; since v0.48.1 the per-verb exit contracts tell the code's truth (repair: 0 probed/written incl. partial / 1 trouble, never 2; audit: 0/1/2 plus 3 for findings+write-failure; library and the run slices: the unified 0/2/1); since v0.49.0 the single-file verb's no-output form is a probe (the gate runs, the record's `output` is null and `applied` false, nothing is written anywhere; the old implicit `(repaired).epub` sibling was issue #7's import litter in a vetted tree, and writing now needs an explicit DST). `library --workers N` (v0.30.0) parallelizes only the sweep's candidate pass, in windows of N consumed in order so `--limit` stays lazy; the repair phase is never parallel (shared workdir, atomic-replacement contract). Since v0.40.0 `main()` guards the VirInvictus stack: a `ModuleNotFoundError` naming `vir_tui`/`cquarry` (marker-gated to 3.14+ on the 3.12 floor) becomes one stderr line and trouble exit 2 instead of a traceback; anything else missing still raises.
238
239
  - `plugin/__init__.py` + `scripts/build_plugin.py`: the Bindery Repair Calibre plugin (v0.37.0; identity `Bindery Repair` / `bindery_repair`, approved and built per the scoped spec in roadmap.md Phase 3). The builder vendors `transforms.py`, `epub.py`, `pagination.py`, `watermark.py`, `reserialize.py` byte-identically into the zip (the zip root is a package, so their relative imports resolve unchanged; the suite's drift test pins the equality) with the version tuple substituted from the single-source VERSION; `publish.yml` attaches `BinderyRepair-v<VERSION>.zip` to each release. The plugin runs ONLY the default pass (epubcheck cannot gate inside Calibre), never raises, is byte-idempotent (zero fixes returns the original path), testzip()-verifies its output, logs one line per book, and takes JSON config via `site_customization` (`log`, `log_path`, `max_size_mb` default 150, `max_log_mb` rotation cap default 2, `epubcheck_path` experimental validation default OFF). Load it in tests through the `tests/test_plugin.py` stubs: the calibre namespace is installed in sys.modules and the package loads with a two-dir `__path__` (plugin dir first, then src/bindery) exactly like calibre's zipplugin loader shape. **Plugin/interpreter compatibility (v0.40.0):** v0.39.0 shipped PEP 758 unparenthesized except tuples, and the plugin died with a bare SyntaxError on every released Calibre (7.x and the whole 8.x series embed Python 3.11, 9.0+ embeds 3.14; from calibre's bypy sources.json, checked against the upstream clone). The core is now grammar-pinned: parenthesized except tuples everywhere, `ruff`'s `target-version = "py312"` pin (inference from requires-python would rewrite the parens back off), `tests/test_version.py`'s parse guard, and CI's `plugin-compat` job byte-compiling the built zip under 3.11/3.12/3.13/3.14. `minimum_calibre_version` is (7, 0, 0): the oldest series whose interpreter CI covers, replacing the hollow (2, 0, 0); `supported_platforms` stays `["linux"]` (developed and tested on Linux only). Any new syntax in the vendored modules must clear the guard before it ships.
239
- - `tests/`: transforms (including the shared duplicate-id rename), end-to-end repair, atomic replace, pagination, watermarks, the audit analyzers (content/pagenumbers/emptytext/ocr/monolithic/completeness, archive integrity, spine classification, contamination since v0.50.0), the library sweep and `CalibreIdResolver`, validate, reserialize, CLI wiring, the version pin and the syntax-floor grammar guard, and the Calibre plugin (build drift + run behavior under calibre stubs). Since the v0.46.0 follow-ups: `tests/test_flags_wiring.py` reflectively pins the RepairFlags inventory to the argparse dests and `_flags_from_args` mapping (a flag added without a field, a field without a flag, or a remapped line fails there), the all-off defaults, and the version gate's caller-immutability contract (test_epub's `TestVersionGateKeepsFlagsIntact`); `tests/test_comment_hyphens.py` carries the RSC-016 fix; `tests/test_flags_real_core.py` drives every repair flag from argv through the unmocked core (--no-validate; the gate itself stays pinned by the mocked-oracle tests and runs for real wherever epubcheck exists). `tests/test_contamination.py` (v0.50.0) carries the three contamination sweeps, the advisory contract, the `_dir_dispatch` key pin, and the cover-routing regression. The v0.46.0 trio (test_flags_wiring, test_comment_hyphens, test_flags_real_core) rides CI's core-compat 3.12/3.13 leg; the hand-listed module list there must gain an entry for every new stack-free test module (audit-side test modules like test_contamination stay on the 3.14 leg by convention). The v0.55.0 batch (issues #11-#16): `tests/test_validate.py` pins the size-scaled timeout and the retry-then-OracleTimeout contract, `tests/test_observe.py` the v2 line format (`CODE:messages:occurrences`), the renamed codes block, the counting envelope, and v1 `--against` acceptance, `tests/test_epub.py::TestDeclareMissingItems` the RSC-008 declarer (sorted deterministic items, blessed media types only, id collisions prefixed, schemes/fragments/spaces/declared skipped), `tests/test_transforms.py::TestFixDuplicateIds` the content-doc rename, and `tests/test_flags_real_core.py` drives `--fix-duplicate-ids`, `--declare-missing-items`, and the extended `--strip-epub3-attrs` set through the real argv-to-fix path. The v0.59.0 addition (issue #23): `tests/test_epub.py::TestPruneDanglingNcxTargets` pins the node-exact prune rule (dead leaf dropped, dead parent spliced above live children, dead subtree one span, scheme/bare-fragment/contentless/comment-hidden untouched, escaped-ampersand src resolves, pageTarget and legacy navTarget covered, wrapper-crossing and unclosed walks abort, a wholesale-dead container refuses) plus the end-to-end prune+resequence, and `tests/test_flags_real_core.py` drives `--prune-dangling-ncx-targets` through argv.
240
+ - `tests/`: transforms (including the shared duplicate-id rename), end-to-end repair, atomic replace, pagination, watermarks, the audit analyzers (content/pagenumbers/emptytext/ocr/monolithic/completeness, archive integrity, spine classification, contamination since v0.50.0), the library sweep and `CalibreIdResolver`, validate, reserialize, CLI wiring, the version pin and the syntax-floor grammar guard, and the Calibre plugin (build drift + run behavior under calibre stubs). Since the v0.46.0 follow-ups: `tests/test_flags_wiring.py` reflectively pins the RepairFlags inventory to the argparse dests and `_flags_from_args` mapping (a flag added without a field, a field without a flag, or a remapped line fails there), the all-off defaults, and the version gate's caller-immutability contract (test_epub's `TestVersionGateKeepsFlagsIntact`); `tests/test_comment_hyphens.py` carries the RSC-016 fix; `tests/test_flags_real_core.py` drives every repair flag from argv through the unmocked core (--no-validate; the gate itself stays pinned by the mocked-oracle tests and runs for real wherever epubcheck exists). `tests/test_contamination.py` (v0.50.0) carries the three contamination sweeps, the advisory contract, the `_dir_dispatch` key pin, and the cover-routing regression. The v0.46.0 trio (test_flags_wiring, test_comment_hyphens, test_flags_real_core) rides CI's core-compat 3.12/3.13 leg; the hand-listed module list there must gain an entry for every new stack-free test module (audit-side test modules like test_contamination stay on the 3.14 leg by convention). The v0.55.0 batch (issues #11-#16): `tests/test_validate.py` pins the size-scaled timeout and the retry-then-OracleTimeout contract, `tests/test_observe.py` the v2 line format (`CODE:messages:occurrences`), the renamed codes block, the counting envelope, and v1 `--against` acceptance, `tests/test_epub.py::TestDeclareMissingItems` the RSC-008 declarer (sorted deterministic items, blessed media types only, id collisions prefixed, schemes/fragments/spaces/declared skipped), `tests/test_transforms.py::TestFixDuplicateIds` the content-doc rename, and `tests/test_flags_real_core.py` drives `--fix-duplicate-ids`, `--declare-missing-items`, and the extended `--strip-epub3-attrs` set through the real argv-to-fix path. The v0.59.0 addition (issue #23): `tests/test_epub.py::TestPruneDanglingNcxTargets` pins the node-exact prune rule (dead leaf dropped, dead parent spliced above live children, dead subtree one span, scheme/bare-fragment/contentless/comment-hidden untouched, escaped-ampersand src resolves, pageTarget and legacy navTarget covered, wrapper-crossing and unclosed walks abort, a wholesale-dead container refuses) plus the end-to-end prune+resequence, and `tests/test_flags_real_core.py` drives `--prune-dangling-ncx-targets` through argv. The v0.60.0 addition (issue #24): `tests/test_validate.py` pins the decimal-MB size term (exactly 10 MiB earns its 360s chunk) and the entry term (the 3,831-entry shape at <= 10 MB computes 660s; the full Summa shape computes 720s; exactly 1,000 entries stays at the size budget; 1,001 adds the first chunk; 2,500 computes 540s).
240
241
 
241
242
  ## Conventions
242
243
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: bindery-cli
3
- Version: 0.59.0
3
+ Version: 0.60.0
4
4
  Summary: Audit EPUB body text and repair broken EPUBs with deterministic, epubcheck-gated fixes; atomic in-place replacement in a Calibre library.
5
5
  Project-URL: Homepage, https://github.com/VirInvictus/bindery-cli
6
6
  Project-URL: Repository, https://github.com/VirInvictus/bindery-cli
@@ -1,5 +1,47 @@
1
1
  # bindery-cli Patch Notes
2
2
 
3
+ ## v0.60.0 (2026-11-01)
4
+
5
+ ### Issue #24: the oracle budget also scales on archive entry count
6
+
7
+ The Summa Theologica (Calibre book #7301: 10,440,245 bytes, 3,831
8
+ archive entries, 3,808 spine documents, a 16,456-finding playOrder NCX)
9
+ kept dying at the gate even after v0.55.0's size-scaled budget, and the
10
+ first miss was the units: the size term divides by binary MiB, and
11
+ 10,440,245 bytes is 9.96 MiB, so the book every doc reports as 10.4 MB
12
+ computed the flat 300s base with no size chunk at all. Even with a size
13
+ chunk it would have missed: epubcheck measured 384s on the source and
14
+ 445s on the `--all` candidate (both runs under sweep contention), because
15
+ the book's cost is entry-count-bound (3,831 entries, 3,808 spine
16
+ documents), not bytes-bound. Either way the retry burned the same way
17
+ and every sweep misfiled the book as `(epubcheck timeout)` -- it stayed
18
+ a candidate forever.
19
+
20
+ Two budget changes, same 1800s cap. The size term counts decimal MB
21
+ (how book sizes are actually reported), so exactly-10-MiB files earn
22
+ their chunk instead of straddling the threshold. And the budget gains an
23
+ entry term shaped like the size term at finer granularity: +60s per
24
+ started 500 archive entries above the first 1,000. The Summa computes
25
+ 720s (300 base + 60 size + 360 entries) against its measured 445s worst
26
+ case; books at or under 1,000 entries and 10 MB keep their historical
27
+ budget exactly, and a path that does not open as a zip (the budget is
28
+ computed before the book is judged) falls back to the size term alone.
29
+ No gate or CLI surface changes; the sweep selectors and the OracleTimeout
30
+ contract are untouched, and no library dry-run re-validation is
31
+ triggered (the change is the oracle's patience, not an acceptance bar).
32
+
33
+ The diagnosis also settled what the repair buys: epubcheck DOES police
34
+ the playOrder contract (2 of the source's 6 RSC-005 error entries are
35
+ exactly that: identical playOrder values for different targets, and
36
+ playOrder sequence gaps), so the default-pass candidate measures
37
+ 0f/6e -> 0f/4e, a strict error decrease the gate accepts; the scoped
38
+ `--all` candidate measures 0f/0e/0w. Measured pins live in
39
+ tests/test_validate.py: exactly 10 MiB earns its decimal chunk (360s),
40
+ the 3,831-entry shape at <= 10 MB computes 660s, the full Summa shape
41
+ (10.44 decimal MB + 3,831 entries) computes 720s, exactly 1,000 entries
42
+ stays at the size budget, 1,001 entries adds the first chunk, and 2,500
43
+ entries compute 540s.
44
+
3
45
  ## v0.59.0 (2026-10-28)
4
46
 
5
47
  ### Issue #23: the dangling NCX navPoint, pruned and re-sequenced in one gate
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "bindery-cli"
7
- version = "0.59.0"
7
+ version = "0.60.0"
8
8
  description = "Audit EPUB body text and repair broken EPUBs with deterministic, epubcheck-gated fixes; atomic in-place replacement in a Calibre library."
9
9
  readme = "README.md"
10
10
  classifiers = [
@@ -53,6 +53,7 @@ The plugin vendors the core and never gates (the epubcheck latency ruling).
53
53
  | 0.57 | The embed scar's element half and the end of the silent equal (issue #22): `--fix-unbound-prefix` now binds an unbound ELEMENT prefix inline (the 9.7.0 writer self-declares xmlns:dc on every dc: element but one; rule 2 for a literal dc: element resolves to the DC namespace itself; Hackers 1f/1e -> 0f/1e with both binds in one run, and the half-repaired intermediate that read equal now repairs), and the masked-axis reclassification generalizes from the v0.51.0 NCX sync to every fired fix: a gate noop on a book that started and stayed fatal reads partial (the manual list) instead of a silent equal; the specimen's residual ncx:-prefixed dtb:uid gap shipped as the v0.57.1 patch (both matchers read a prefixed `<ncx:meta>` carrier; Hackers fully clean 0f/0e/0w) | v0.57.0-v0.57.1 |
54
54
  | 0.58 | The structural dry run's four rejects (issues #18-#21), each bisected to the root on its specimens: the private-ZipInfo write contract (issue #18: writestr stamps the info it is handed with the DESTINATION offsets, one shared info repointed zin's own lookups into the output file -- all 57 "unreadable" books, the "possible zip bomb" included, were this one bug; the peek also catches BadZipFile per the issue), bracket-encoded renamed references plus the start-tag/PI anchor on both reference rewriters (issue #19: raw brackets are RSC-020 path-illegal -- IJ 108e -> 22e -- and the unanchored regex corrupted display text that teaches HTML -- Hacking's two RSC-016 fatals), the entity-decoding href resolver and prefix-tolerant OPF matchers (issue #20: `&amp;` hrefs vs raw-`&` entries made prune and declare swap the same items on the D&D four, and `<opf:item>` blindness duplicated whole manifests on the Sony three), and the three #21 mechanisms (guide-fragment strip, the post-anchor playOrder re-run, the comment-blind duplicate-id rename) | v0.58.0 |
55
55
  | 0.59 | The dangling-NCX prune (issue #23): `--prune-dangling-ncx-targets` removes navPoint/pageTarget elements whose `<content src>` names a document the archive never contained (RSC-007 the manifest prune cannot reach: no item exists for a file the OPF never declared), node-exact over a balanced stack scanner (dead subtree drops as one span, dead parent spliced above live children, scheme/bare-fragment/comment-hidden/contentless refused, unbalanced walk aborts), with the contract-gated playOrder pass re-run in the same branch -- the hand-surgery-plus-second-run rescue is one gate (fixture 0f/1e/0w -> 0f/0e/0w: one navPoint pruned, 389 playOrder values re-sequenced) | v0.59.0 |
56
+ | 0.60 | The oracle budget scales on decimal MB and archive entry count (issue #24): the Summa Theologica (10,440,245 bytes = 9.96 binary MiB, 3,831 entries, 3,808 spine docs, 16,456 playOrder findings) is entry-count-bound, not bytes-bound -- measured 384s source and 445s candidate against the flat 300s its bytes computed (the binary 10 MiB divisor ate the size chunk; the book the docs call 10.4 MB never earned one) -- so every sweep double-timed-out and misfiled it as `(epubcheck timeout)`; the size term counts decimal MB now, the entry term adds +60s per started 500 entries above 1,000 (same 1800s cap), the book computes 720s, and a non-zip path falls back to size-only. epubcheck does police the playOrder contract (2 of the source's 6 RSC-005 error entries): default-pass candidate measures 0f/6e -> 0f/4e (accept), scoped `--all` candidate 0f/0e/0w | v0.60.0 |
56
57
 
57
58
  ## Open work
58
59
 
@@ -11,7 +11,7 @@ Calibre plugin built from this core.
11
11
  Single source of truth for the version. pyproject.toml must match VERSION below.
12
12
  """
13
13
 
14
- VERSION = "0.59.0"
14
+ VERSION = "0.60.0"
15
15
  __version__ = VERSION
16
16
 
17
17
  from .epub import RepairReport, repair_epub # noqa: E402
@@ -22,6 +22,7 @@ import subprocess
22
22
  import tempfile
23
23
  import threading
24
24
  import time
25
+ import zipfile
25
26
  from dataclasses import dataclass
26
27
  from pathlib import Path
27
28
 
@@ -52,22 +53,47 @@ class OracleTimeout(RuntimeError):
52
53
 
53
54
  def oracle_timeout_for(path: Path, base: int = 300) -> int:
54
55
  """The epubcheck budget for one book: the base, plus a minute per
55
- started 10 MB above 10 MB, capped at 30 minutes (issue #15).
56
+ started 10 MB above 10 MB, plus a minute per started 500 archive
57
+ entries above 1,000, capped at 30 minutes (issues #15, #24).
56
58
 
57
59
  The 2026-10-24 whole-library runs hit a 300s ceiling on the Summa
58
60
  Theologica (10.4 MB, 3,795-playOrder NCX): it timed out in one run and
59
61
  passed the identical gate in another, so the fixed budget misfiled a
60
62
  timing flake as a repair error. Bigger books simply get more time;
61
- anything at or under 10 MB keeps the exact historical 300s.
63
+ the historical 300s base itself never changes.
64
+
65
+ The size term alone still misfiled the Summa twice (issue #24). First
66
+ the units: 10,440,245 bytes is 9.96 MiB, just under the binary 10 MiB
67
+ threshold, so the book the docs call 10.4 MB computed the flat 300s
68
+ base with no size chunk at all; the term now counts decimal MB,
69
+ matching how book sizes are actually reported. Second the shape:
70
+ measured at 384s on the source and 445s on the candidate, the book is
71
+ entry-count-bound (3,831 archive entries, 3,808 spine documents), not
72
+ bytes-bound. The entry term mirrors the size term's started-chunk
73
+ shape at finer granularity: a minute per started 500 entries above
74
+ the first 1,000 (an exact 500-multiple earns its chunk, like the
75
+ size term's exact-10-MB multiples), so ordinary books keep their
76
+ historical budget exactly. A path that does not open as a zip (the
77
+ budget is computed before the book is judged) falls back to the size
78
+ term alone.
62
79
  """
63
80
  try:
64
- size_mb = path.stat().st_size / (2**20)
81
+ size_mb = path.stat().st_size / 10**6
65
82
  except OSError:
66
83
  return base
67
- if size_mb <= 10:
68
- return base
69
- chunks = int((size_mb - 10) // 10) + 1
70
- return min(base + 60 * chunks, 1800)
84
+ timeout = base
85
+ if size_mb > 10:
86
+ chunks = int((size_mb - 10) // 10) + 1
87
+ timeout += 60 * chunks
88
+ try:
89
+ with zipfile.ZipFile(path) as zf:
90
+ entries = len(zf.namelist())
91
+ except (OSError, zipfile.BadZipFile):
92
+ entries = 0
93
+ if entries > 1000:
94
+ entry_chunks = ((entries - 1000) // 500) + 1
95
+ timeout += 60 * entry_chunks
96
+ return min(timeout, 1800)
71
97
 
72
98
 
73
99
  def epubcheck_available() -> bool:
@@ -211,14 +211,19 @@ class FailureModes(unittest.TestCase):
211
211
 
212
212
 
213
213
  class ScaledTimeout(unittest.TestCase):
214
- """The size-scaled default budget (issue #15): the Summa Theologica
215
- (10.4 MB) flaked at the fixed 300s; books over 10 MB get a minute per
216
- started 10 MB, capped at 30 minutes."""
214
+ """The size- and entry-scaled default budget (issues #15, #24): the
215
+ Summa Theologica flaked at the fixed 300s (issue #15), then outgrew
216
+ the size term itself -- 384s source and 445s candidate against the
217
+ flat 300s its bytes computed (9.96 binary MiB never earned a chunk) --
218
+ because epubcheck's cost on it is entry-count-bound (3,831 entries,
219
+ 3,808 spine docs). Books over 10 decimal MB get a minute per started
220
+ 10 MB; books over 1,000 entries get a minute per started 500 entries;
221
+ capped at 30 minutes."""
217
222
 
218
223
  def test_at_or_under_ten_mb_keeps_the_base(self) -> None:
219
224
  with tempfile.TemporaryDirectory() as td:
220
225
  small = Path(td) / "small.epub"
221
- small.write_bytes(b"x" * (10 * 2**20))
226
+ small.write_bytes(b"x" * 9_500_000)
222
227
  self.assertEqual(oracle_timeout_for(small), 300)
223
228
  empty = Path(td) / "missing.epub"
224
229
  self.assertEqual(oracle_timeout_for(empty), 300)
@@ -226,12 +231,65 @@ class ScaledTimeout(unittest.TestCase):
226
231
  def test_over_ten_mb_scales_per_started_chunk(self) -> None:
227
232
  with tempfile.TemporaryDirectory() as td:
228
233
  book = Path(td) / "summa.epub"
229
- book.write_bytes(b"x" * int(10.4 * 2**20))
234
+ book.write_bytes(b"x" * 10_400_000)
230
235
  self.assertEqual(oracle_timeout_for(book), 360)
231
236
  big = Path(td) / "big.epub"
232
- big.write_bytes(b"x" * (51 * 2**20))
237
+ big.write_bytes(b"x" * 55_000_000)
233
238
  self.assertEqual(oracle_timeout_for(big), 600)
234
239
 
240
+ def test_binary_mib_trap_earns_its_decimal_chunk(self) -> None:
241
+ """The Summa trap (issue #24): exactly 10 MiB is 10.49 decimal MB,
242
+ so the size term fires where the old binary divisor read it as
243
+ at-threshold and gave the flat 300s."""
244
+ with tempfile.TemporaryDirectory() as td:
245
+ book = Path(td) / "exactly-10mib.epub"
246
+ book.write_bytes(b"x" * (10 * 2**20))
247
+ self.assertEqual(oracle_timeout_for(book), 360)
248
+
249
+ def test_entry_heavy_book_scales_per_started_half_thousand(self) -> None:
250
+ """The Summa entry shape (issue #24): 3,831 tiny entries at
251
+ <= 10 decimal MB compute 300 + 6 x 60 = 660s; the entry term
252
+ mirrors the size term's started-chunk shape at 500-entry
253
+ granularity."""
254
+ with tempfile.TemporaryDirectory() as td:
255
+ book = Path(td) / "summa-shape.epub"
256
+ with zipfile.ZipFile(book, "w") as zf:
257
+ for i in range(3831):
258
+ zf.writestr(f"OEBPS/Text/c{i}.xhtml", "<html/>")
259
+ self.assertEqual(oracle_timeout_for(book), 660)
260
+
261
+ def test_entry_term_boundaries(self) -> None:
262
+ with tempfile.TemporaryDirectory() as td:
263
+ exactly = Path(td) / "exactly-1000.epub"
264
+ with zipfile.ZipFile(exactly, "w") as zf:
265
+ for i in range(1000):
266
+ zf.writestr(f"c{i}.xhtml", "<html/>")
267
+ self.assertEqual(oracle_timeout_for(exactly), 300)
268
+ over = Path(td) / "1001.epub"
269
+ with zipfile.ZipFile(over, "w") as zf:
270
+ for i in range(1001):
271
+ zf.writestr(f"c{i}.xhtml", "<html/>")
272
+ self.assertEqual(oracle_timeout_for(over), 360)
273
+ wide = Path(td) / "2500.epub"
274
+ with zipfile.ZipFile(wide, "w") as zf:
275
+ for i in range(2500):
276
+ zf.writestr(f"c{i}.xhtml", "<html/>")
277
+ self.assertEqual(oracle_timeout_for(wide), 540)
278
+
279
+ def test_the_real_summa_shape(self) -> None:
280
+ """The actual book (issue #24): 10,440,245 bytes (10.44 decimal
281
+ MB, one size chunk) plus 3,831 entries (six entry chunks) compute
282
+ 300 + 60 + 360 = 720s against its measured 384s source / 445s
283
+ candidate."""
284
+ with tempfile.TemporaryDirectory() as td:
285
+ book = Path(td) / "summa-real.epub"
286
+ payload = b"x" * 10_200_000
287
+ with zipfile.ZipFile(book, "w") as zf:
288
+ zf.writestr("OEBPS/big.xhtml", payload)
289
+ for i in range(3830):
290
+ zf.writestr(f"OEBPS/Text/c{i}.xhtml", "<html/>")
291
+ self.assertEqual(oracle_timeout_for(book), 720)
292
+
235
293
  def test_cap(self) -> None:
236
294
  with tempfile.TemporaryDirectory() as td:
237
295
  huge = Path(td) / "huge.epub"
@@ -8,7 +8,7 @@ resolution-markers = [
8
8
 
9
9
  [[package]]
10
10
  name = "bindery-cli"
11
- version = "0.59.0"
11
+ version = "0.60.0"
12
12
  source = { editable = "." }
13
13
  dependencies = [
14
14
  { name = "cquarry", marker = "python_full_version >= '3.14'" },
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes