Repository navigation
test(reader): ReaderScreenKt design pass — extract bookmark ref logic (#607) - #608
Conversation
…erage Design-pass decision for #607: ReaderScreenKt's top-level composable is not split PlayerScreen/SettingsScreen-style — its render tree needs a real FragmentActivity plus native Readium/PDF/WebView components to render at all, so extracting a "pure content" composable would not gain any testability, only add wiring risk (see PR description for the full rationale, including why the sibling-hiltViewModel ViewModelStoreOwner sharing concern that previously blocked this does not actually apply here). Instead, extract the composable's two remaining untested *pure* decision points into internal functions with dedicated unit tests: - bookmarkPositionRef: the onAddBookmark ref encoding (page:/scroll:/CFI). - resolveBookmarkTarget: the onBookmarkClick positionRef decoding, now a BookmarkTarget sealed type instead of three parallel prefix checks. Both preserve existing behaviour exactly, including the silent no-navigate fallback for a malformed page:/scroll: payload.
Adds §1c to TEST_COVERAGE_PRD.md documenting the decision not to split ReaderScreenKt's top-level composable, and why, closing out the Phase 7 target §1b left re-scoped and open.
8b7b51f to
f148128
Compare
gh pr ready's ready_for_review event did not dispatch a new jvm-tests.yml run (the JVM job stayed pointed at the stale draft-time push, where it's deliberately skipped for draft PRs). This empty commit forces a fresh synchronize event so the real test job actually runs.
📱 iOS Build Status: PASSED⏭️ iOS Simulator Build & Unit Tests - skipped iOS UI tests run in a separate, informational job and are not reflected above — check "iOS UI Tests (informational)" for those. |
QA verification — PR #608 vs #607Issue #607's remaining scope: "the actual design pass on the top-level No Acceptance criteria
What I ran
Test-quality check (AGENTS.md "prove a test can fail")Hand-mutated AGENTS.md conventions
No regressions found in related areas ( QA verdict: PASS |
Principal review — verdict:
|
Summary
Design pass for
ReaderScreenKt's top-level composable, per #607 (split out of #521 / docs/TEST_COVERAGE_PRD.md Phase 7 §1b). §1b's prior session left this re-scoped, deliberately not doing a PlayerScreen/SettingsScreen-style wrapper + pure-content split, citing risk to the sibling-hiltViewModel()ViewModelStoreOwnersharing that Read Aloud's chapter-walk coordination depends on.Design decision this PR makes and documents: do not do the wrapper/pure-content split, for a different (and more decisive) reason than the one that blocked the prior session.
ViewModelStoreOwner-sharing mechanism directly:EpubReaderScreen/MarkdownReaderScreenboth already acceptviewModel: XReaderViewModel = hiltViewModel()as an explicit parameter ("caller may pass its own instance"), andReaderScreenalways passes its own pre-created instance down explicitly.hiltViewModel()resolves by the ambientLocalViewModelStoreOwner(typically the nav back-stack entry hosting this screen) plus the requested type — not by which composable function lexically contains the call. So moving where in the fileepubViewModel/markdownViewModelare obtained (wrapper vs. an extracted content composable), as long as it's still the same position in the composition tree with no newViewModelStoreOwnerintroduced, would not change instance identity or break the sharing. That specific risk is not what's actually blocking a mechanical split.state.contentSource != nullbranch'sScaffoldcontent requires a realFragmentActivity(LocalContext.current as? FragmentActivity) and renders native Readium (EPUB)/PDF/WebView-backed child screens. There is no existing precedent anywhere in this module for Robolectric-rendering that branch (confirmed by reading every existingfeature/readertest file), and nothing about extracting a "pure content" composable changes that — the extracted composable would still not be renderable in a JVM/Robolectric test without the same native dependencies. Splitting it would add a large, high-risk diff (the whole ~500-line render tree, ~40 callback params) for zero net gain in what CI can actually exercise.What this PR does instead: extracts the two remaining actually pure (format/state-in, value-out) decision points in the file into
internaltop-level functions with dedicated JUnit 5 unit tests — same treatment already given toselectReaderBottomBar/readAloudSupportedin the prior session:bookmarkPositionRef(format, pageIndex, markdownScrollFraction, positionCfi, currentLocatorJson)— theonAddBookmarkref-encodingwhenblock (page:/scroll:/CFI-or-live-locator), previously inline and untested.resolveBookmarkTarget(positionRef)— theonBookmarkClickprefix-decoding logic, previously three parallelstartsWith/removePrefix/toXOrNull()checks, now aBookmarkTargetsealed type (PdfPage/MarkdownScroll/EpubLocator/Malformed) with one function computing it.Both are behaviour-preserving extractions — call sites now just delegate to them — including the existing silent no-navigate-but-still-dismiss behaviour when a
page:/scroll:payload fails to parse.Each new test was mutation-checked by hand (flipping the branch order / removing the
?:fallback) to confirm it goes red, per AGENTS.md's "prove a test can fail."Risk
feature/readeris not inagent-policy.yml'ssensitive_paths; this is a pure-logic extraction plus new unit tests, no behaviour change intended. Risk should classifyrisk:low, but the diff will be assessed byclassify_pr_risk.pyregardless of what's said here.Closes #607