Skip to content

test(reader): ReaderScreenKt design pass — extract bookmark ref logic (#607) - #608

Merged
github-actions[bot] merged 3 commits into
devfrom
feature/reader-screen-coverage-607
Aug 25, 2026
Merged

github-actions[bot] merged 3 commits into
devfrom
feature/reader-screen-coverage-607

Conversation

@libravault-pipeline-bot

Copy link
Copy Markdown
Contributor

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() ViewModelStoreOwner sharing 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.

  • I re-verified the ViewModelStoreOwner-sharing mechanism directly: EpubReaderScreen/MarkdownReaderScreen both already accept viewModel: XReaderViewModel = hiltViewModel() as an explicit parameter ("caller may pass its own instance"), and ReaderScreen always passes its own pre-created instance down explicitly. hiltViewModel() resolves by the ambient LocalViewModelStoreOwner (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 file epubViewModel/markdownViewModel are obtained (wrapper vs. an extracted content composable), as long as it's still the same position in the composition tree with no new ViewModelStoreOwner introduced, would not change instance identity or break the sharing. That specific risk is not what's actually blocking a mechanical split.
  • The real blocker is testability, not risk of breakage: the state.contentSource != null branch's Scaffold content requires a real FragmentActivity (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 existing feature/reader test 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 internal top-level functions with dedicated JUnit 5 unit tests — same treatment already given to selectReaderBottomBar/readAloudSupported in the prior session:

  • bookmarkPositionRef(format, pageIndex, markdownScrollFraction, positionCfi, currentLocatorJson) — the onAddBookmark ref-encoding when block (page:/scroll:/CFI-or-live-locator), previously inline and untested.
  • resolveBookmarkTarget(positionRef) — the onBookmarkClick prefix-decoding logic, previously three parallel startsWith/removePrefix/toXOrNull() checks, now a BookmarkTarget sealed 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/reader is not in agent-policy.yml's sensitive_paths; this is a pure-logic extraction plus new unit tests, no behaviour change intended. Risk should classify risk:low, but the diff will be assessed by classify_pr_risk.py regardless of what's said here.

Closes #607

…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.
@libravault-pipeline-bot
libravault-pipeline-bot Bot force-pushed the feature/reader-screen-coverage-607 branch from 8b7b51f to f148128 Compare August 25, 2026 11:31
@github-actions
github-actions Bot marked this pull request as ready for review August 25, 2026 11:42
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.
@github-actions

Copy link
Copy Markdown
Contributor

📱 iOS Build Status: PASSED

⏭️ iOS Simulator Build & Unit Tests - skipped
✅ Android Core Modules - success

iOS UI tests run in a separate, informational job and are not reflected above — check "iOS UI Tests (informational)" for those.

View run details

@github-actions github-actions Bot added the risk:low Principal review classified this PR as low risk label Aug 25, 2026
@libravault-pipeline-bot libravault-pipeline-bot Bot added the status:needs-qa PR open, awaiting qa-agent verification label Aug 25, 2026
@claude

claude Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

QA verification — PR #608 vs #607

Issue #607's remaining scope: "the actual design pass on the top-level ReaderScreenKt composable — deciding how (or whether) to split it into wrapper + pure-content pieces without breaking the sibling-ViewModel sharing, then implementing that split with coverage."

No status:blocked on the PR or issue.

Acceptance criteria

  • ✅ Design pass performed and documented. docs/TEST_COVERAGE_PRD.md §1c records the decision not to do a full wrapper/pure-content split, with a rationale distinct from the one that originally re-scoped this (testability of the FragmentActivity/native-Readium/PDF/WebView render tree, not ViewModelStoreOwner sharing risk).
  • ✅ The ViewModelStoreOwner-sharing re-analysis is factually correct. Verified directly: EpubReaderScreen (epub/EpubReaderScreen.kt:116) and MarkdownReaderScreen (markdown/MarkdownReaderScreen.kt:105) both take viewModel: XReaderViewModel = hiltViewModel() as an overridable parameter, confirming hiltViewModel() resolves via ambient LocalViewModelStoreOwner, not lexical call site — so the split's blocker really is testability, not instance-sharing risk, as claimed.
  • ✅ "implementing that split with coverage" — satisfied by extracting the two remaining pure decision points, bookmarkPositionRef and resolveBookmarkTarget (now a BookmarkTarget sealed type), into internal top-level functions with dedicated JUnit 5 tests, matching the precedent already set by selectReaderBottomBar/readAloudSupported.
  • ✅ Behaviour-preserving. Diffed against origin/dev's inline logic by hand: bookmarkPositionRef's per-format encoding and defaults match the old inline when exactly; resolveBookmarkTarget's prefix decoding matches the old three-branch startsWith/removePrefix/toXOrNull() chain exactly, including the "malformed payload still dismisses the bookmarks sheet without navigating" behaviour (old code called viewModel.hideBookmarks() inside each branch regardless of parse success; new code calls it unconditionally after the when, same net effect).

What I ran

  • ./gradlew :feature:reader:testDebugUnitTest --continue — BUILD SUCCESSFUL. Both new test classes ran and passed: BookmarkPositionRefTest (5/5) and ResolveBookmarkTargetTest (5/5).
  • ./gradlew testDebugUnitTest --continue (full repo, matches jvm-tests.yml) — BUILD SUCCESSFUL, no regressions in any other module.
  • CI's own Unit & Integration Tests (JVM) check on the PR — pass (5m3s).

Test-quality check (AGENTS.md "prove a test can fail")

Hand-mutated bookmarkPositionRef's PDF default (pageIndex ?: 0 → ?: 1) and reran BookmarkPositionRefTest: it went red (PDF encodes page index, defaulting to 0 when unknown() failed), then restored the file and confirmed the tree was clean again. Both new test classes call the extracted functions directly with no mocking — they exercise real logic, not a relaxed mock standing in for it.

AGENTS.md conventions

  • Tests present for non-trivial change — yes.
  • Commit hygiene — one concern per commit (test+extraction, docs, CI-trigger), Conventional Commits subjects. Fine.
  • Branch naming (feature/reader-screen-coverage-607) — fine.
  • No hardcoded versions, no androidTest changes requiring the needs-emulator label.

No regressions found in related areas (BookmarksSheet, ReaderTopBar callers unaffected — call sites now just delegate to the extracted functions).

QA verdict: PASS

@github-actions github-actions Bot removed the status:needs-qa PR open, awaiting qa-agent verification label Aug 25, 2026
@libravault-pipeline-bot libravault-pipeline-bot Bot added the status:needs-review QA passed, awaiting principal-review-agent label Aug 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Principal review — verdict: auto-merge

Risk label: risk:low, independently re-verified by re-running .github/scripts/classify_pr_risk.py origin/dev origin/feature/reader-screen-coverage-607 — 228 changed lines, no sensitive_paths match (confirmed by hand against .github/agent-policy.yml: only docs/TEST_COVERAGE_PRD.md, feature/reader/.../ReaderScreen.kt, and two new test files under feature/reader/src/test/ are touched). Label was applied at 11:53:58Z, after the branch's last real commit (22b5956, 11:47:26Z), so it isn't stale.

CI verified, not just trusted. The PR description itself flags that ready_for_review didn't trigger a fresh jvm-tests.yml run and adds an empty commit to force one. I checked that this actually worked rather than taking the claim at face value: gh run list --workflow=jvm-tests.yml shows run 32844133313 with headSha == the PR's current headRefOid (22b5956a...), conclusion: success. Pulled that run's log directly — Detect Changed Paths shows both new test files as [added], and Unit & Integration Tests (JVM) shows > Task :feature:reader:testDebugUnitTest followed by BUILD SUCCESSFUL in 2m 50s (not up-to-date/cached) — so the new tests genuinely executed and passed on the current HEAD, not a stale draft-time run.

Diff read in full, not summarized. The two extractions are behavior-preserving:

  • bookmarkPositionRef: matches the original inline when (format) exactly, same defaults (pageIndex ?: 0, markdownScrollFraction ?: 0.0), same positionCfi ?: currentLocatorJson fallback for the EPUB/audio-format catch-all branch.
  • resolveBookmarkTarget / BookmarkTarget: matches the original three-way startsWith/toXOrNull() prefix check. Confirmed the viewModel.hideBookmarks() call, which used to run inside all three original branches (including silently on a malformed page:/scroll: payload, since it sat outside the ?.let {}), was correctly hoisted to run unconditionally after the when in the new code — so the "dismiss the sheet even when the payload doesn't parse" behavior the PR claims to preserve actually is preserved, including for the new explicit Malformed case.

AGENTS.md conventions followed: pure helpers marked internal (not private), JUnit 5 with backtick-named test methods, test files mirror the main source path 1:1 with <Subject>Test.kt naming.

Design-pass rationale re-checked against the originating issue (#607). #607's stated blocker was risk to hiltViewModel() ViewModelStoreOwner sharing that Read Aloud's chapter-walk depends on. EpubReaderScreen/MarkdownReaderScreen do take viewModel: XReaderViewModel = hiltViewModel() as an overridable parameter (grep-confirmed), which supports the PR's claim that relocating where epubViewModel/markdownViewModel are obtained wouldn't itself change instance identity, as long as it stays the same position in the composition subtree — so the PR's decision not to force a mechanical wrapper/content split, and instead extract only the two genuinely pure decision points that were actually untested, is a defensible, well-documented call rather than scope-dodging. docs/TEST_COVERAGE_PRD.md §1c and the ReaderScreenKt coverage table row were both updated consistently with this reasoning.

No .github/workflows/** or other CI/build-config changes in this diff. No new networking dependency or call. No sensitive_paths touched. No status:blocked.

No CONFIRMED-severity findings — nothing filed as a GitHub issue.

One minor, non-blocking observation for whoever reads this later (not filing an issue — doesn't meet the CONFIRMED bar): bookmarkPositionRef's else branch (positionCfi ?: currentLocatorJson) is reachable for any non-PDF/non-MARKDOWN MediaFormat, including the audio formats (MP3/M4B/etc.), not just EPUB — this is unchanged from the pre-extraction inline code, so it's pre-existing behavior this PR correctly preserves rather than something introduced here.

@github-actions github-actions Bot added status:approved-auto-merge Principal review passed, risk:low — will auto-merge and removed status:needs-review QA passed, awaiting principal-review-agent labels Aug 25, 2026
@github-actions
github-actions Bot merged commit f0d8dfa into dev Aug 25, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk:low Principal review classified this PR as low risk status:approved-auto-merge Principal review passed, risk:low — will auto-merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test coverage: ReaderScreenKt design pass (Phase 7 split from #521)

0 participants