Commit graph

4 commits

Author SHA1 Message Date
Huang Xin
4023867745
test(kosync): check both xpointer forms against crengine at two DOM versions (#7178)
crengine 137cba4 writes [1] on every step only for books opened at DOM
version 20260812 or later. Books KOReader opened before keep their older
version and the unindexed form, so both forms stay in use.

The oracle script takes the DOM version as a fourth argument and checks
that crengine reads each pointer the same with its [1]s dropped, the form
Readest writes. New fixtures for the four oracle books were dumped from
the KOReader emulator with 137cba4 cherry-picked, at 20260812. The
20240114 dumps from the same build match the committed fixtures exactly.
The EPUB oracle now pulls through getCFIFromXPointerRange, the path the
sync hooks use.

Verified:
- oracle test with this PR's xcfi.ts: 8 passed
- with main's xcfi.ts: the 4 new fixtures fail "KOReader -> Readest:
  707/707, 108/108, 19/19, 160/160 mismatches"; the 4 old ones pass
- unindexed_mismatches is empty in every new fixture
- xcfi and kosyncProgress suites: 98 passed; pnpm lint and
  pnpm format:check clean

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 10:02:43 +01:00
Huang Xin
8005ff9af6
fix(kosync): send and read MOBI positions in crengine's HTML form (#6951)
* fix(kosync): send and read MOBI positions in crengine's HTML form

KOReader reads a MOBI book (the Mobipocket format, not KF8) with crengine
as one HTML document, so its positions look like
/html/body/body/div[8]/p[152]/text().596, with top-level elements numbered
across the whole book. foliate splits the same book into a section at each
<mbp:pagebreak>. Readest rejected KOReader's pointers ("Unsupported format
for spine index extraction"), so the Readest app showed "Sync failed" after
the KOReader plugin pushed, and it sent KOReader an EPUB-style
/body/DocFragment[N]/body/... pointer that crengine can't resolve, so
KOReader stayed put.

xcfi now maps MOBI both ways: the section is found by counting each
top-level tag across sections, the empty <a id="fileposN"> anchors foliate
adds are skipped, and the root is /html/body/body when a <guide> in <head>
made crengine open a body of its own (checked against crengine with HTML
files with and without one). A book foliate opens as KF8 keeps the
DocFragment form; crengine doesn't read KF8. isXPointerProgress accepts
/html pointers for KOSync.

Verified against crengine itself: xpointer-oracle.lua (now MOBI-aware) run
in the KOReader emulator on the reporter's book; 499 of its words convert
both ways exactly as crengine writes them, and 720 sampled words of
sample-war-peace.mobi (a flat calibre-style MOBI) too. A 160-word War and
Peace oracle is committed. Without the change the oracle test fails with
"KOReader -> Readest: 160/160 mismatches ... Unsupported format for spine
index extraction", xcfi.mobi.test.ts fails with "expected
'/body/DocFragment[2]/body/p[2]/font[1…' to be
'/html/body/body/p[3]/font[1]/text().0'", and kosyncProgress.test.ts fails
with "expected false to be true". Related xcfi, KOSync, progress and notes
sync suites pass (25 files, 286 tests); pnpm lint and pnpm format:check
pass. Not run: a sync round trip with the KOReader plugin on a device, and
a combined MOBI/KF8 file (foliate reads its KF8 part, crengine its MOBI
part, so those positions still can't be mapped).

Reported by D-Everden on GitHub.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(kosync): give the MOBI XPointer test room to open the 2.7 MB book

Opening sample-war-peace.mobi takes about 2.8 s on its own, so the
default 5 s timeout tripped under the full suite in the pre-push hook.
The crengine oracle test, which opens the same book, already allows
120 s; this one now allows 30 s.

Verified: the file passes alone (2 tests); the hook run that failed
with "Test timed out in 5000ms" is retried with this commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* perf(kosync): parse MOBI sections one at a time for the layout pass

CodeRabbit on #6951: Promise.all kept every parsed section document
alive until all were counted. Each is now parsed, counted and dropped
before the next. Counts and the guide check are unchanged; the xcfi,
crengine oracle and KOSync suites (7 files, 45 tests) pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 20:52:46 +02:00
Huang Xin
2d37bbfc2e
fix(kosync): send and read FB2 positions in crengine's FictionBook form (#6905)
Some checks are pending
CodeQL Advanced / Analyze (actions) (push) Waiting to run
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run
CodeQL Advanced / Analyze (rust) (push) Waiting to run
Publish Docker image / build (linux/amd64, ubuntu-latest) (push) Waiting to run
Publish Docker image / build (linux/arm64, ubuntu-24.04-arm) (push) Waiting to run
Publish Docker image / merge (push) Blocked by required conditions
Build with Nix / tests (push) Waiting to run
PR checks / nix_flake_check (push) Waiting to run
PR checks / rust_lint (push) Waiting to run
PR checks / koplugin_rust_lint (push) Waiting to run
PR checks / build_web_app (push) Waiting to run
PR checks / test_web_app (1) (push) Waiting to run
PR checks / test_web_app (2) (push) Waiting to run
PR checks / test_extensions (push) Waiting to run
PR checks / build_tauri_app (push) Waiting to run
Scorecard supply-chain security / Scorecard analysis (push) Waiting to run
Deploy to vercel on merge / build_and_deploy (push) Waiting to run
* fix(kosync): send and read FB2 positions in crengine's FictionBook form

Readest sent KOReader an EPUB-style /body/DocFragment[N]/body/... XPointer
for FB2 books. crengine reads FB2 natively and builds no DocFragments, so
it couldn't resolve the pointer and KOReader went to the cover. The other
direction rejected KOReader's /FictionBook/... pointers and fell back to
the percentage.

xcfi now maps FB2 both ways: foliate's section for each child of the first
<body> (image, title, epigraph, section) to /FictionBook/body[1]/<tag>[N],
counted per tag the way crengine does, each notes body to body[N], and
foliate's renamed elements back to their FB2 tags (kept as each element's
first class). The push sites (KOSync, Readest progress and notes sync,
BookOrbit notes) pass the book format; range note pulls go through the new
getCFIFromXPointerRange so FB2 highlights from KOReader resolve too.
isXPointerProgress accepts /FictionBook pointers.

Verified against crengine itself: xpointer-oracle.lua (now FB2-aware) run
in the KOReader emulator on a new FB2 fixture dumped all 108 visible words;
xcfi.crengine-oracle.test.ts converts every word both ways exactly as
crengine writes it. Without the change xcfi.fb2.test.ts fails with
"expected '/body/DocFragment[4]/body/section/p[1]/text().4' to be
'/FictionBook/body[1]/section[1]/p[1]/text().4'", the notes-body pull
throws "Unsupported format for spine index extraction", and
kosyncProgress.test.ts fails with "expected false to be true". Related
xcfi, KOSync, progress, notes and BookOrbit suites pass (333 tests);
pnpm lint passes. Not run: a KOSync round trip on a device, and the
reporter's book.

Reported by email to support.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(kosync): cover one-body FB2 books and a leading body-level image

CREngine in the KOReader emulator writes /FictionBook/body/... (no index)
for an FB2 book with one body, and /FictionBook/body[1]/... when it also
has a notes body. Either form resolves in either book. It puts a leading
body-level image at /FictionBook/body/image.0.

A new one-body fixture (an image and a title before two sections) and its
oracle dump (19 words) add the following checks:
- every word converts both ways exactly as CREngine writes it;
- Readest writes body without an index for the one-body book;
- the leading image is /FictionBook/body/image in the one-body book and
  /FictionBook/body[1]/image in the book with notes;
- /FictionBook/body/image.0, /FictionBook/body[1]/image.0 and
  /FictionBook/body[1]/image[1] open section 0 in both books;
- both body forms open the same paragraph in the one-body book.

The code already did all of this, so nothing fails on this branch. With
the body step forced to body[1], three tests fail, e.g. expected
"/FictionBook/body/section[2]/p/text().2", received
"/FictionBook/body[1]/section[2]/p/text().2", and the oracle reports
"Readest -> KOReader: 19/19 mismatches".

Related xcfi, KOSync, progress, notes and BookOrbit suites pass
(164 tests), and pnpm lint passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 02:31:33 +08:00
Huang Xin
d05fb5338a
fix(sync): closing unclosed void tags before XML re-parsing, closes #5271 (#6122)
* chore: update agent memories

* chore: update agent memories

* fix(sync): closing unclosed void tags before XML re-parsing, closes #5271

* chore(agent): update agent memories

* fix(sync): preserve block starts for dropped XPointer whitespace

* docs(agent): sanitize support notes and correct review findings
2026-09-07 18:02:57 +02:00