bindery-cli 0.61.0__tar.gz → 0.61.1__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.61.0 → bindery_cli-0.61.1}/PKG-INFO +1 -1
  2. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/patchnotes.md +33 -0
  3. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/pyproject.toml +1 -1
  4. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/roadmap.md +1 -0
  5. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/src/bindery/__init__.py +1 -1
  6. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/src/bindery/cli.py +20 -0
  7. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/src/bindery/epub.py +4 -1
  8. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/tests/test_cli.py +33 -0
  9. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/tests/test_epub.py +40 -0
  10. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/uv.lock +1 -1
  11. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/.github/FUNDING.yml +0 -0
  12. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/.github/workflows/ci.yml +0 -0
  13. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/.github/workflows/publish.yml +0 -0
  14. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/.gitignore +0 -0
  15. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/AGENTS.md +0 -0
  16. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/LICENSE +0 -0
  17. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/OBSERVE-RESEARCH.md +0 -0
  18. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/README.md +0 -0
  19. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/docs/screenshots/library-sweep.png +0 -0
  20. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/logo.svg +0 -0
  21. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/plugin/__init__.py +0 -0
  22. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/project.done +0 -0
  23. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/run_tests.sh +0 -0
  24. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/scripts/FastSweep.java +0 -0
  25. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/scripts/build_plugin.py +0 -0
  26. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/scripts/fast_sweep.py +0 -0
  27. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/spec.md +0 -0
  28. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/src/bindery/__main__.py +0 -0
  29. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/src/bindery/audit.py +0 -0
  30. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/src/bindery/library.py +0 -0
  31. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/src/bindery/observe.py +0 -0
  32. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/src/bindery/pagination.py +0 -0
  33. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/src/bindery/reserialize.py +0 -0
  34. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/src/bindery/transforms.py +0 -0
  35. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/src/bindery/validate.py +0 -0
  36. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/src/bindery/watermark.py +0 -0
  37. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/tests/test_audit.py +0 -0
  38. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/tests/test_comment_hyphens.py +0 -0
  39. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/tests/test_contamination.py +0 -0
  40. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/tests/test_cover_tocdrift.py +0 -0
  41. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/tests/test_flags_real_core.py +0 -0
  42. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/tests/test_flags_wiring.py +0 -0
  43. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/tests/test_help.py +0 -0
  44. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/tests/test_library.py +0 -0
  45. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/tests/test_matcher_hardening.py +0 -0
  46. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/tests/test_observe.py +0 -0
  47. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/tests/test_pagination.py +0 -0
  48. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/tests/test_plugin.py +0 -0
  49. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/tests/test_reserialize.py +0 -0
  50. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/tests/test_space_renames.py +0 -0
  51. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/tests/test_spine_guard.py +0 -0
  52. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/tests/test_transforms.py +0 -0
  53. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/tests/test_validate.py +0 -0
  54. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/tests/test_version.py +0 -0
  55. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/tests/test_watermark.py +0 -0
  56. {bindery_cli-0.61.0 → bindery_cli-0.61.1}/tests/test_xml_hardening.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: bindery-cli
3
- Version: 0.61.0
3
+ Version: 0.61.1
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,38 @@
1
1
  # bindery-cli Patch Notes
2
2
 
3
+ ## v0.61.1 (2026-11-03)
4
+
5
+ ### The hex-ref href crash, and the sweep that survives it
6
+
7
+ The first whole-library `--all` dry run (the 2026-11-03 observe lane)
8
+ crashed with exit 1 forty minutes in: `_decode_numeric_refs` raised
9
+ `ValueError: invalid literal for int() with base 16: 'x2013'` inside the
10
+ prune's content-doc pass, and the exception escaped the sweep's repair
11
+ loop, killing the run and its report.
12
+
13
+ Two fixes:
14
+
15
+ - **The decoder** (epub.py): `_NUMERIC_REF_RE` captured the hex ref's `x`
16
+ into the digits group (`–` -> `'x2013'`) and the repl fed the
17
+ whole capture to `int(_, 16)`. XML spells hex character references with
18
+ a lowercase x only, so the regex was right and the int call ate the x;
19
+ the fix strips the prefix before the int. The bug sat dormant since
20
+ v0.58.0 shipped the decode because the resolver runs only on the opt-in
21
+ paths (prune, anchor strip), so the default pass never met it. Library
22
+ census: 36 hex-ref hrefs across 5 books, every one an external URL
23
+ (en-dashes and ampersands in macmillan/tor/techcrunch query strings)
24
+ that the decode reaches before the scheme check discards it. Five new
25
+ tests pin the decode, the internal-href contract extended to hex, and
26
+ the crash shape end-to-end through `strip_missing_file_hrefs`.
27
+ - **The sweep crash guard** (cli.py): an unexpected per-book exception is
28
+ now that book's `error` verdict (`crash (ValueError): ...; not
29
+ applied`), counted in the existing errors tally and flowing to --json
30
+ like every other record, instead of a run-killing traceback. The
31
+ unified trouble exit contract is unchanged. The single-file repair
32
+ verb keeps its traceback: there an operator is watching one book.
33
+
34
+ Suite: 838 tests.
35
+
3
36
  ## v0.61.0 (2026-11-02)
4
37
 
5
38
  ### Issue #25: fix-empty-body injects `<p>&#160;</p>`, not bare `&nbsp;`
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "bindery-cli"
7
- version = "0.61.0"
7
+ version = "0.61.1"
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 = [
@@ -54,6 +54,7 @@ The plugin vendors the core and never gates (the epubcheck latency ruling).
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
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 |
57
+ | 0.61.1 | The hex-ref href crash and the sweep that survives it: `_NUMERIC_REF_RE` captured the hex ref's `x` into the digits group and `int('x2013', 16)` killed the first whole-library `--all` dry run (2026-11-03 observe lane; 36 hex-ref hrefs across 5 books, every one an external URL the decode reaches before the scheme check discards it; dormant since v0.58.0 because the resolver is opt-in-path-only); the fix strips the prefix before the int, and the sweep's repair loop gains the crash guard -- an unexpected per-book exception is that book's `error` verdict (`crash (Type): ...; not applied`), counted in the existing errors tally, instead of a run-killing traceback (the single-file verb keeps its traceback) | v0.61.1 |
57
58
 
58
59
  ## Open work
59
60
 
@@ -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.61.0"
14
+ VERSION = "0.61.1"
15
15
  __version__ = VERSION
16
16
 
17
17
  from .epub import RepairReport, repair_epub # noqa: E402
@@ -843,6 +843,26 @@ def run_library(args) -> int:
843
843
  )
844
844
  tqdm.write(f" ERROR {rel}\n unreadable ({reason}): {e}")
845
845
  continue
846
+ except Exception as e:
847
+ # The crash guard (v0.61.1): an unexpected per-book exception (a
848
+ # transform meeting an input shape no test imagined) used to
849
+ # escape as a run-killing traceback that cost a multi-hour sweep
850
+ # its whole report (the 2026-11-03 hex-ref href crash). One
851
+ # book's bug is that book's error verdict, not the run's.
852
+ errors += 1
853
+ records.append(
854
+ Outcome(
855
+ epub,
856
+ "error",
857
+ None,
858
+ None,
859
+ f"crash ({type(e).__name__}): {e}; not applied",
860
+ )
861
+ )
862
+ tqdm.write(
863
+ f" ERROR {rel}\n crash ({type(e).__name__}): {e}; not applied"
864
+ )
865
+ continue
846
866
  records.append(o)
847
867
  if o.status == "nochange":
848
868
  nochange += 1
@@ -753,7 +753,10 @@ def _decode_numeric_refs(s: str) -> str:
753
753
 
754
754
  def repl(m: re.Match) -> str:
755
755
  digits = m.group(1)
756
- cp = int(digits, 16 if digits[0] in "xX" else 10)
756
+ # The hex alternative captures its lowercase x (XML's only spelling):
757
+ # strip it here. Feeding it to int() raised ValueError on the first
758
+ # href carrying &#x2013; and killed the whole-library sweep (2026-11-03).
759
+ cp = int(digits[1:], 16) if digits[0] in "xX" else int(digits, 10)
757
760
  return chr(cp) if 0 < cp <= 0x10FFFF else m.group(0)
758
761
 
759
762
  return _NUMERIC_REF_RE.sub(repl, s)
@@ -160,6 +160,39 @@ class TestLibrarySurvivesCorruptEpub(unittest.TestCase):
160
160
  self.assertIn("cannot read", err.getvalue())
161
161
 
162
162
 
163
+ class TestLibrarySurvivesUnexpectedCrash(unittest.TestCase):
164
+ def test_sweep_converts_a_crashing_book_to_an_error_verdict(self):
165
+ # v0.61.1's crash guard: an unexpected exception inside the per-book
166
+ # repair used to escape as a run-killing traceback (the 2026-11-03
167
+ # hex-ref href crash cost a whole-library --all sweep its report).
168
+ # One book's bug is that book's error verdict, not the run's.
169
+ with tempfile.TemporaryDirectory() as td:
170
+ root = Path(td)
171
+ crasher = root / "Author" / "Crash (1)" / "crash.epub"
172
+ crasher.parent.mkdir(parents=True)
173
+ build(crasher)
174
+ good = root / "Author" / "Book (2)" / "book.epub"
175
+ good.parent.mkdir(parents=True)
176
+ build(good)
177
+ real = process_book
178
+
179
+ def flaky(src, *a, **k):
180
+ if src.name == "crash.epub":
181
+ raise ValueError("int('x2013', 16)")
182
+ return real(src, *a, **k)
183
+
184
+ out, err = io.StringIO(), io.StringIO()
185
+ with (
186
+ mock.patch("bindery.cli.process_book", side_effect=flaky),
187
+ redirect_stdout(out),
188
+ redirect_stderr(err),
189
+ ):
190
+ rc = main(["library", td, "--no-validate"])
191
+ self.assertEqual(rc, 2)
192
+ self.assertIn("crash (ValueError)", out.getvalue())
193
+ self.assertIn("ACCEPT", out.getvalue())
194
+
195
+
163
196
  class TestRepairPartialLabel(unittest.TestCase):
164
197
  def test_partial_output_is_labeled_not_repaired(self):
165
198
  # The file is worth writing (fewer fatals), but the old "repaired:" line read
@@ -10,7 +10,9 @@ from xml.etree import ElementTree as ET
10
10
 
11
11
  from bindery.epub import (
12
12
  RepairFlags,
13
+ _decode_numeric_refs,
13
14
  _locate_opf,
15
+ _resolve_href,
14
16
  collect_undeclared_resources,
15
17
  declare_missing_manifest_items,
16
18
  downgrade_epub3_tags,
@@ -24,6 +26,7 @@ from bindery.epub import (
24
26
  package_version,
25
27
  repair_epub,
26
28
  strip_epub3_attributes,
29
+ strip_missing_file_hrefs,
27
30
  strip_ncx_dangling_targets,
28
31
  strip_page_map,
29
32
  sync_ncx_uid,
@@ -3142,3 +3145,40 @@ class TestUnboundPrefix(unittest.TestCase):
3142
3145
  src, dst = self._build_embed_scar(td)
3143
3146
  report = repair_epub(src, dst)
3144
3147
  self.assertNotIn("unbound_prefixes_bound", report.fixes)
3148
+
3149
+
3150
+ class TestNumericRefHrefDecode(unittest.TestCase):
3151
+ """The hex branch of the issue #20 decode: the regex captured the x into
3152
+ the digits group and int('x2013', 16) raised ValueError on the first href
3153
+ carrying &#x2013;, killing the whole-library --all sweep (2026-11-03; 36
3154
+ hrefs across 5 books, every one an external URL the decode reaches before
3155
+ the scheme check). XML spells hex refs with a lowercase x only; the regex
3156
+ was right, the int call ate the x."""
3157
+
3158
+ def test_hex_ref_decodes(self):
3159
+ self.assertEqual(_decode_numeric_refs("8&#x2013;5-million"), "8–5-million")
3160
+
3161
+ def test_decimal_ref_unchanged(self):
3162
+ self.assertEqual(_decode_numeric_refs("K&#38;C.png"), "K&C.png")
3163
+
3164
+ def test_out_of_range_ref_stays_encoded(self):
3165
+ self.assertEqual(_decode_numeric_refs("a&#x110000;b"), "a&#x110000;b")
3166
+
3167
+ def test_internal_hex_ref_href_resolves_to_its_entry(self):
3168
+ # the issue #20 contract extended to hex: href="a&#x2013;b.xhtml"
3169
+ # names the raw entry a–b.xhtml
3170
+ self.assertEqual(_resolve_href("OEBPS", "a&#x2013;b.xhtml"), "OEBPS/a–b.xhtml")
3171
+
3172
+ def test_external_hex_ref_href_survives_the_anchor_prune(self):
3173
+ # the crash shape end-to-end: an <a> href carrying &#x2013; (an
3174
+ # external URL) went through _resolve_href inside
3175
+ # strip_missing_file_hrefs and raised, killing the sweep
3176
+ text = (
3177
+ '<html xmlns="http://www.w3.org/1999/xhtml"><body><p>'
3178
+ '<a href="http://techcrunch.com/2011/02/01kleiner-perkins-leads'
3179
+ '-8&#x2013;5-million-round-for-path/">x</a>'
3180
+ "</p></body></html>"
3181
+ )
3182
+ out, n = strip_missing_file_hrefs(text, "OEBPS", frozenset({"OEBPS/c1.xhtml"}))
3183
+ self.assertEqual(n, 0)
3184
+ self.assertEqual(out, text)
@@ -8,7 +8,7 @@ resolution-markers = [
8
8
 
9
9
  [[package]]
10
10
  name = "bindery-cli"
11
- version = "0.61.0"
11
+ version = "0.61.1"
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
File without changes