Skip to content

fix(vault): open Markdown files in the Encrypted Vault reader - #448

Merged
github-actions[bot] merged 4 commits into
devfrom
fix/vault-markdown-reader-unsupported-format
Aug 22, 2026
Merged

github-actions[bot] merged 4 commits into
devfrom
fix/vault-markdown-reader-unsupported-format

Conversation

@libravault-pipeline-bot

Copy link
Copy Markdown
Contributor

Summary

.md files stored in an Encrypted Vault fail to open with "Unsupported format: markdown" on both Android and iOS, even though the non-vault reader already has full Markdown support. This wires the Vault reader's format dispatch to render Markdown too.

Closes #442

Approach

Following the hand-scoped implementation plan a maintainer posted on the issue (after an earlier triage pass on this same issue correctly flagged a real module-boundary ambiguity and stopped at status:needs-info):

  • Add a MarkdownReady/.markdownReady state parallel to the existing EpubReady/PdfReady, on both platforms.
  • Load the decrypted bytes already available (VaultFileReader.readAt on Android, VaultStore.readFullContent on iOS — both already used for EPUB/PDF) and decode as UTF-8 text.
  • Render via a new Vault-local Markdown screen, not by depending on feature:reader (Android) — see "Risky/uncertain" below for why this deviates from one detail of the literal plan text.

Risky / uncertain — flagging explicitly

The issue's own triage comment identified 3 open questions and asked a human to decide. The maintainer's follow-up plan answered (1) plain-render-first is fine for v1, and (3) relative images are unsupported for v1 (safe no-op fallback). For (2) — whether shared Markdown code should move to a core:markdown-style module or feature:vault should take a direct dependency on feature:reader — the plan's code sample referenced feature:reader's CoilMarkdownImageTransformer/rememberMarkdownTypography directly, which would require the latter.

I did not do that. feature:vault has multiple recent, explicit doc comments (VaultReaderTopBar, VaultReaderSettings, and VaultReaderViewModel's own AppReadingTheme/ReadingTheme mapper, the last of which landed on dev after the plan comment was written) all independently re-affirming "duplicated per module rather than a new cross-module dependency" as this module's live, current convention — and the original triage comment flagged the direct-dependency route as pulling in Readium x3/pdf-viewer/jsoup/webkit/room/tts into feature:vault's graph. Given the full-parity items the shared code would have bought (TOC, mermaid, image loading) are all separately marked out-of-scope for v1 in the same plan, I added the renderer's external library dependency directly (matching the low-ambiguity EPUB/PDF precedent already in this module) and wrote a small local typography adapter from VaultReaderSettings, rather than adding the feature:vault → feature:reader dependency implied by the snippet. This is a judgment call on an already-flagged architectural fork — please double check it's the one you wanted before merging.

Explicitly out of scope for v1 (matches the plan)

  • Relative image loading inside vault markdown — no equivalent of the SAF DocumentFile tree exists inside an encrypted vault; images just don't render (no crash).
  • Mermaid diagrams, TOC sheet/scroll-to-heading, per-section scroll persistence.
  • Reading-position persistence for vault Markdown (bookmark/highlight actions are disabled while a Markdown file is open, same as they already are for any non-ready state).

Test plan

  • Android: VaultReaderViewModelTest — MARKDOWN entry reaches MarkdownReady with the decoded text; regression test that a genuinely unhandled format still surfaces Error.
  • iOS: VaultReaderViewModelTests — "markdown" entry reaches .markdownReady.
  • ./gradlew testDebugUnitTest locally before marking ready.

Adds a MarkdownReady state and loads the decrypted bytes as UTF-8 text
via VaultFileReader.readAt, mirroring the existing EPUB/PDF branches.
Rendering wiring follows in subsequent commits.

Part of #442.
…roid)

Adds VaultMarkdownReaderScreen, a v1-scoped Vault-local Markdown
renderer (whole-document Markdown() call, VaultReaderSettings-driven
typography), and wires it into VaultReaderScreen's format dispatch.

Deliberately adds the multiplatform-markdown-renderer-m3 dependency
directly to feature:vault (matching the existing Readium/PDF
precedent of pulling third-party renderers in per-module) rather than
depending on feature:reader, per this module's established "duplicate
rather than share" convention (see VaultReaderTopBar's and
VaultReaderSettings' doc comments) - see the PR description for the
full rationale on this deviating from one detail of the issue's
hand-scoped plan.

No TOC/mermaid/relative-image support yet - explicitly out of scope
for v1 per the issue.

Closes #442
Adds a markdownReady state to VaultReaderViewModel, decoding the
decrypted content as UTF-8 text and parsing it with the existing
MarkdownDocumentParser (already shared with the non-vault reader,
since iOS has no per-module Gradle-style boundary to work around).
VaultReaderView renders it via the existing MarkdownReaderContent,
with fixed v1 typography defaults (no theme/font-size controls exist
for the Vault reader on iOS yet) and no image loading/TOC/position
persistence, matching Android's equivalent v1 scope for this issue.

Part of #442
@libravault-pipeline-bot
libravault-pipeline-bot Bot force-pushed the fix/vault-markdown-reader-unsupported-format branch from de65ae2 to 80a6cd4 Compare August 22, 2026 18:28
@github-actions
github-actions Bot marked this pull request as ready for review August 22, 2026 18:35
@github-actions github-actions Bot added the status:needs-info Dev/QA agent needs more detail before proceeding label Aug 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

The dev agent's run failed (crashed or exhausted its turn budget) while producing this PR — routed to a human instead of silently advancing an unconfirmed fix to QA. See the workflow run log for what happened.

@libravault-xyz

Copy link
Copy Markdown
Collaborator

Principal-dev-lead read-through (the automated run that produced this diff crashed/ran out of budget before reaching QA, per the bot comment above — not a design or code problem, so re-routing rather than reworking).

Traced every symbol this diff touches back to its real definition rather than trusting the diff at face value:

  • Android: VaultReaderFontFamily's 5 cases, VaultReaderSettings.fontFamily/fontSize/lineSpacing, VaultFileReader.readAt/plainSize, and the settings var at the VaultReaderScreen.kt call site all match what VaultMarkdownReaderScreen.kt references.
  • iOS: MarkdownReaderContent's init matches the markdownContent call site parameter-for-parameter; LibraVaultColorScheme.forReadingTheme(_:) and ConcreteReadingTheme.{light,dark} exist. Confirmed real vault imports actually produce the lowercase "markdown" string this PR's case "markdown": matches on (traced through EncryptedVaultContentsViewModel.importOne → String(describing: MediaFormat.markdown)).
  • isReady (iOS) / bookmark-highlight gating (Android) correctly leave Markdown falling through their existing default branches — matches what the new doc comments claim.
  • Both new tests exercise the real decode → state path, and the pre-existing "unsupported format" test was correctly repointed to a still-genuinely-unhandled format (MOBI) rather than silently losing that branch's coverage.

No issues found. Relabeling to status:needs-qa so the real test suites run — most checks above show SKIPPED, this never actually got there.

@libravault-xyz libravault-xyz added status:needs-qa PR open, awaiting qa-agent verification and removed status:needs-info Dev/QA agent needs more detail before proceeding labels Aug 22, 2026
@claude

claude Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

QA verification — PR #448 vs issue #442

Environment note: this run is on a Linux CI runner with no Xcode/xcodebuild available, so the iOS XCTest suite (VaultReaderViewModelTests.swift) could not be executed here. iOS coverage below is from direct code review of the view model, view, and test file, not a test run.

Acceptance criteria (per issue #442 + the maintainer's hand-scoped plan/decision comments)

  • PASS — Android: .md vault entry opens and renders instead of "Unsupported format". VaultReaderViewModel.kt's when (entry.format) now has a "MARKDOWN" branch that reads r.readAt(0L, r.plainSize.toInt()) and decodes UTF-8 into MarkdownReady(title, text), dispatched in VaultReaderScreen.kt to the new VaultMarkdownReaderScreen (renders via com.mikepenz.markdown.m3.Markdown).
  • PASS — iOS: "markdown" vault entry opens and renders. VaultReaderViewModel.swift's switch entry.format now has a case "markdown" that decodes content (already-decrypted Data from readFullContent) to String, parses via the existing MarkdownDocumentParser.parse, and sets .markdownReady. VaultReaderView.swift dispatches this to the existing MarkdownReaderContent component.
  • PASS (with an explicit, pre-cleared deviation) — "reuse existing markdown rendering rather than reimplementing": iOS reuses MarkdownDocumentParser/MarkdownReaderContent from feature:reader/shared code directly, as expected. Android does not depend on feature:reader — it adds the external multiplatform-markdown-renderer-m3 dependency directly to feature:vault and writes a small local typography adapter (VaultMarkdownReaderScreen.kt). This looks like a deviation from the issue's literal "reuse ... rather than reimplementing" wording, but it's exactly decision test(reader): Readium 3 instrumentation tests + emulator CI #2 from the maintainer's own follow-up comment on Vault reader: markdown files fail with "Unsupported format: markdown" #442 ("Neither new module nor a feature:vault → feature:reader dependency ... feature:vault takes the external renderer dependency directly"), which superseded the issue's original wording and cleared status:needs-info. Not a gap — it's the scoped-and-approved path.
  • PASS — regression coverage: an unhandled format ("MOBI"/no matching iOS case) still surfaces Error/.error, confirmed both by a dedicated test and by reading the else/default branches.
  • PASS — relative images / mermaid / TOC / position persistence are explicitly out of scope per the plan, and the diff matches that (no image transformer wired for vault markdown, images: [:] on iOS, no TOC).

Regression check

Confirmed the pre-fix code path (commit 294cd8d, before this PR's own b8dfdff) had no "MARKDOWN" case in VaultReaderViewModel.kt's when block — a MARKDOWN entry fell through to else -> Error("Unsupported format: MARKDOWN"). The new Android test (a MARKDOWN entry opens a reader and decodes the text into MarkdownReady) asserts MarkdownReady, so it would have failed red against pre-fix code — this is a real regression guard, not a trivially-true one. The Android test stubs reader.readAt(0L, bytes.size) and reader.plainSize explicitly (not relying on MockK's relaxed defaults) and asserts the exact decoded string, so it's exercising the real decode path, not a mock that quietly no-ops.

The iOS test (testLoadMarkdownReadyExposesTheDecodedTextAndParsedBlocks) goes through a real VaultSessionManager/VaultStore against a temp-directory vault (create → import → unlock → load), not a mock of the crypto/store layer — same pattern as the existing EPUB/PDF tests in that file. Real integration-style coverage, code-reviewed but not executed here (see environment note above).

Tests run

  • ./gradlew :feature:vault:testDebugUnitTest --continue → BUILD SUCCESSFUL (all vault module unit tests pass, including the new MARKDOWN test).
  • ./gradlew testDebugUnitTest --continue (full JVM suite, checking for regressions elsewhere) → BUILD SUCCESSFUL, 438 actionable tasks, no failures.
  • iOS VaultReaderViewModelTests.swift — not executed (no Xcode toolchain on this Linux runner); verified by reading the test and the implementation it exercises.

AGENTS.md conventions

  • Branch name fix/vault-markdown-reader-unsupported-format matches fix/<short-slug>.
  • Commits use Conventional Commits and are split one-concern-per-commit (state/decode → Android render wiring → iOS render wiring).
  • No hardcoded versions — the new Gradle dependency is pulled from the version catalog (libs.markdown.renderer.m3), already used by feature:reader.
  • Non-trivial changes have unit tests on both platforms per the "always ship unit tests" rule, at the right level (plain JVM view-model tests, not UI/screenshot tests, matching what's actually observable here).

Minor, non-blocking note

The PR description's own "Test plan" checklist boxes are left unchecked (- [ ]) even though all three items (Android test, iOS test, local testDebugUnitTest run) are actually done — cosmetic only, not a functional gap.

QA verdict: PASS

@github-actions github-actions Bot removed the status:needs-qa PR open, awaiting qa-agent verification label Aug 22, 2026
@libravault-pipeline-bot libravault-pipeline-bot Bot added the status:needs-review QA passed, awaiting principal-review-agent label Aug 22, 2026
@github-actions github-actions Bot added status:needs-info Dev/QA agent needs more detail before proceeding and removed status:needs-review QA passed, awaiting principal-review-agent labels Aug 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR's branch is stale relative to dev — specifically, .github/workflows/principal-review.yml differs between this branch and dev. GitHub Actions refuses to mint the OIDC token claude-code-action needs when a pull_request-triggered, id-token: write workflow's own file doesn't byte-match the base branch (its own anti-tampering check), so the principal review agent step was skipped rather than silently no-opping (see issue #254 for the full diagnosis). Rebase/merge dev into this branch and re-add status:needs-review to retry.

@libravault-xyz

Copy link
Copy Markdown
Collaborator

Rebased onto current dev (clean merge, no conflicts — genuinely stale, not a self-touching case). Compiles clean. Re-labeling to retry principal review; QA already passed.

@libravault-xyz libravault-xyz added status:needs-review QA passed, awaiting principal-review-agent and removed status:needs-info Dev/QA agent needs more detail before proceeding labels Aug 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📱 iOS Build Status: PASSED

✅ iOS Simulator Build & Unit Tests - success
✅ 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

Copy link
Copy Markdown
Contributor

Principal review — verdict: auto-merge

Risk classification

No risk:* label is currently on this PS — .github/scripts/classify_pr_risk.py doesn't appear to have applied one (possibly lost across the rebase-to-retry cycle documented in the PR history). Re-ran it myself directly against origin/dev...HEAD:

$ python3 .github/scripts/classify_pr_risk.py origin/dev HEAD
risk:low
diff is 247 changed lines and touches no sensitive path

247 changed lines (< 400 threshold), and none of the 8 changed files match any sensitive_paths glob in agent-policy.yml (checked each of feature/vault/build.gradle.kts, VaultMarkdownReaderScreen.kt, VaultReaderScreen.kt, VaultReaderViewModel.kt, the Android test, and the 3 iOS files by hand against the glob list — no core/vaultcrypto|vaultstore, no workflows, no fixtures/screenshots/billing/versions files touched). risk:low confirmed independently.

What I verified myself (not just re-reading the diff/PR description)

  • Symbol-by-symbol trace, both platforms — libs.markdown.renderer.m3 resolves to a real catalog entry (gradle/libs.versions.toml:104, com.mikepenz:multiplatform-markdown-renderer-m3:0.32.0); VaultFileReader.readAt/.plainSize are real, already-used APIs (core/vaultcrypto/.../VaultFileReader.kt); VaultReaderSettings/VaultReaderFontFamily/OpenDyslexicFontFamily all exist with the fields VaultMarkdownReaderScreen.kt reads. On iOS, MarkdownDocumentParser, MarkdownBlock, and MarkdownReaderContent all live in the same Xcode target/module as the vault code (Sources/Models, Sources/Features/Reader/Components vs. Sources/Features/EncryptedVault), so the "no Gradle-style boundary on iOS" claim in the PR description checks out — this is a real, accessible dependency, not a claim about non-existent code. MarkdownReaderContent's init signature matches the markdownContent call site param-for-param, and LibraVaultColorScheme.forReadingTheme(_:) / ConcreteReadingTheme are real.
  • Format-string plumbing, both directions — confirmed the Android vault importer (VaultContentsViewModel.importOne) stamps format = format.name from core.storage.model.MediaFormat, which does have a MARKDOWN case (ext == "md"/"markdown"), so entry.format == "MARKDOWN" is what actually gets written, matching the new "MARKDOWN" -> branch. On iOS, traced EncryptedVaultContentsViewModel → LibraryFileScanner.extensionFormats["md"/"markdown"] = .markdown → String(describing:) on a no-payload enum case yields the lowercase "markdown" the new case "markdown": matches — not a guess, the enum and its stringification are both real.
  • Regression coverage — checked out the pre-fix commit (b8dfdff's parent) and confirmed VaultReaderViewModel.kt's when block had no "MARKDOWN" case, so the new test would fail red pre-fix. The repointed "unsupported format" test now uses "MOBI", which I confirmed is not a case anywhere in core.domain.model.MediaFormat/core.storage.model.MediaFormat — it's a genuinely still-unhandled format, not accidentally testing something now supported.
  • Bookmark/highlight gating — Android's addBookmark() no-ops safely for Markdown because _currentPositionRef is never written outside the EPUB/PDF position callbacks (stays null, early-returns). iOS gates at the UI layer instead: isReady in VaultReaderView.swift only returns true for .epubReady/.pdfReady, so the bookmark/highlight toolbar buttons are .disabled for .markdownReady — I initially flagged this as a possible discrepancy (iOS's currentPositionRef computed property falls through to a chapter: default rather than no-op'ing like Android), but the UI-level .disabled(!isReady) means that code path is unreachable while a Markdown file is open. Not a bug, just a different (both correct) place each platform enforces the same rule.
  • Ran the actual test suite, not just read it: ./gradlew :feature:vault:testDebugUnitTest --tests "xyz.libravault.feature.vault.VaultReaderViewModelTest" → BUILD SUCCESSFUL, 35/35 tests passed including a MARKDOWN entry opens a reader and decodes the text into MarkdownReady. Also confirmed on the actual PR CI run (not just locally): Unit & Integration Tests (JVM) and Build & Test iOS (Simulator) both went from pending to pass while I was reviewing. iOS XCTest itself I couldn't execute (no Xcode here, same limitation QA noted), but I did verify the test file's assertions against the real types it exercises (VaultReaderViewModelTests.swift's new test constructs a real .markdownReady case and checks markdownBlocks.count, not a mock).
  • The flagged architectural deviation (feature:vault not depending on feature:reader, contrary to the plan's literal code sample) — read all 3 issue Vault reader: markdown files fail with "Unsupported format: markdown" #442 comments directly. The maintainer's own third comment explicitly supersedes the second comment's code sample: "Neither new module nor a feature:vault → feature:reader dependency... This keeps the existing module boundary intact" — posted specifically to clear status:needs-info, and is the most recent explicit instruction on file. The PR's approach matches this instruction exactly, not just the module's general "duplicate, don't share" convention. This is the correct resolution of the flagged ambiguity, not a deviation that needs a human's judgment call.
  • CI-config scrutiny: no .github/workflows/** files are touched by this PR's own diff. The earlier github-actions bot comment about a stale principal-review.yml (OIDC anti-tampering, Agent pipeline silently no-ops on stale PR branches: workflow-file drift trips GitHub's OIDC validation, producing a misleading "no verdict" message #254) was resolved by the subsequent rebase — confirmed git diff origin/dev -- .github/workflows/principal-review.yml is empty on the current HEAD.
  • No new networking dependency introduced (multiplatform-markdown-renderer-m3 is a local Compose/rendering library, already used identically by feature:reader).

Minor, non-blocking nit

r.readAt(0L, r.plainSize.toInt()) (Android) truncates/overflows for a plaintext markdown file over ~2GB — purely theoretical for this file type, matches the maintainer's own literal suggested snippet on #442, and existing precedent elsewhere in this module doesn't universally guard against it either. Not filing an issue for this — it doesn't clear the CONFIRMED bar and isn't worth the permanent-record overhead for pipeline flagging purposes here.

Outcome

No CONFIRMED findings. Diff is risk:low under a freshly re-run classification. Both gating unit-test suites now show green on the PR's own CI run (JVM + iOS Simulator build/test), corroborated by my own local run of the new/changed Android tests. AGENTS.md test conventions (JUnit 5, backtick names, MockK, regression + happy-path coverage) are all followed. Recommending auto-merge.

@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 22, 2026
@github-actions
github-actions Bot merged commit 8e868c9 into dev Aug 22, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Vault reader: markdown files fail with "Unsupported format: markdown"

1 participant