Skip to content

refactor(persistence): split persistence.rs into domain modules behind a barrel#701

Merged
appergb merged 1 commit into
betafrom
refactor/split-persistence
Jun 17, 2026
Merged

refactor(persistence): split persistence.rs into domain modules behind a barrel#701
appergb merged 1 commit into
betafrom
refactor/split-persistence

Conversation

@appergb

@appergb appergb commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

User description

What

Splits the 2757-line src-tauri/src/persistence.rs god-file into a focused
persistence/ module — behavior-unchanged, pure move + re-export. Part of #697.

File Lines Concern
mod.rs 121 shared fs/io helpers (data_dir, ensure_dir, atomic_write, read_or_default), HISTORY_CAP/PREFERENCES_FILE, module wiring
paths.rs 345 models / recordings / Foundry roots + migration helpers
credentials.rs 880 OS credential vault — CredsRoot model, keyring/android/legacy, CredentialAccount, CredentialsSnapshot, CredentialsVault
style_pack.rs 910 StylePackStore + ZIP import/export + prefs reconciliation
history.rs 135 HistoryStore
dictionary.rs 206 DictionaryStore + vocab presets
preferences.rs 145 read_preferences + PreferencesStore
correction.rs 136 CorrectionRuleStore

How / invariants

  • Public surface unchanged. Every previously-pub item is re-exported with pub use <submodule>::*, so crate::persistence::* is identical and zero call sites changed (verified against coordinator, commands, asr/local/models).
  • Pure move. No logic, signatures, public API, or UI touched.
  • Shared helpers stay private in mod.rs; child modules reach them via super:: (parent items are visible to descendants — no visibility widening needed).
  • Glob re-exports are deliberate: they keep cfg-gated items (Android #[cfg(target_os="android")], Windows foundry_*) resolution-safe on every target, avoiding the explicit-pub use breakage that sank the earlier types.rs split. The only import tweak is gating use anyhow::anyhow / use std::fs in credentials.rs so Android sees no new unused-import warning.
  • Tests moved next to the code they cover (chunk-payload → credentials, prefs migration → preferences, vocab roundtrip → dictionary, correction syntax → correction, model-root → paths, style-pack sync → style_pack).

credentials.rs (880) and style_pack.rs (910) stay above the ~800 soft guideline on purpose: each store shares private field / cache-state access with its helpers, so splitting them further would force pub(super) cross-module plumbing — the exact fragility this refactor is avoiding. Open to a follow-up sub-split if preferred.

Test plan

  • cargo fmt — clean
  • cargo check — 0 errors, 0 new warnings in persistence/
  • cargo clippy --no-deps — clean (the 3 persistence lints are pre-existing, on verbatim-moved code)
  • cargo test --lib446 passed, 0 failed (count unchanged)
  • CI: Linux / Windows / macOS / Android build jobs (cross-platform cfg code can't be compiled on the macOS dev box)

Base: beta.


PR Type

Enhancement


Description

  • Split 2757-line persistence.rs into domain submodules

  • Each submodule owns one store: credentials, style_pack, paths, dictionary, history, correction, preferences

  • Re-export via pub use barrel, zero call-site changes

  • Shared filesystem helpers stay private in mod.rs


Diagram Walkthrough

flowchart LR
  A["persistence.rs (2757 lines)"] --> B["mod.rs (helpers, consts, re-exports)"]
  A --> C["credentials.rs (OS vault)"]
  A --> D["style_pack.rs (pack store + ZIP)"]
  A --> E["paths.rs (storage paths)"]
  A --> F["dictionary.rs (vocab store)"]
  A --> G["history.rs (dictation history)"]
  A --> H["correction.rs (correction rules)"]
  A --> I["preferences.rs (user prefs store)"]
  B --> C
  B --> D
  B --> E
  B --> F
  B --> G
  B --> H
  B --> I
Loading

File Walkthrough

Relevant files
Enhancement
8 files
mod.rs
Module wiring, shared helpers, and glob re-exports             
+121/-0 
credentials.rs
OS credential vault store                                                               
+880/-0 
style_pack.rs
Style-pack store with ZIP import/export                                   
+910/-0 
paths.rs
Storage path resolution for models, recordings, Foundry   
+345/-0 
dictionary.rs
Vocabulary dictionary store and vocab presets                       
+206/-0 
history.rs
Dictation history store with retention                                     
+135/-0 
correction.rs
Correction-rule store                                                                       
+136/-0 
preferences.rs
User preferences store with streamingInsert migration       
+145/-0 
Additional files
1 files
persistence.rs +0/-2757

…d a barrel

Behavior-unchanged decomposition of the 2757-line `persistence.rs` god-file
into a `persistence/` module, one file per concern. Everything is re-exported
via glob (`pub use <submodule>::*`) so the `crate::persistence::*` public
surface is byte-for-byte identical and no call site changes.

Layout:
- mod.rs         shared fs/io helpers (data_dir, ensure_dir, atomic_write,
                 read_or_default) + the two cross-cutting consts + re-exports
- paths.rs       models / recordings / Foundry roots + migration helpers
- credentials.rs OS credential vault (CredsRoot model, keyring/android/legacy,
                 CredentialAccount, CredentialsSnapshot, CredentialsVault)
- history.rs     HistoryStore
- preferences.rs read_preferences + PreferencesStore
- style_pack.rs  StylePackStore + ZIP import/export + prefs reconciliation
- dictionary.rs  DictionaryStore + vocab presets
- correction.rs  CorrectionRuleStore

Pure move + re-export: no logic, signatures, public API, or UI changed. Unit
tests moved next to the code they now cover. Shared helpers stay private in
`mod.rs` (parent items are visible to child modules), and glob re-exports keep
cfg-gated items (Android/Windows) resolution-safe across every target —
avoiding the explicit-`pub use` breakage seen in the earlier types.rs split.

Verified on macOS: cargo fmt/check/clippy clean (no new persistence warnings),
446 lib tests green. Android/Windows cfg paths verified by CI.

Part of #697.
@github-actions

Copy link
Copy Markdown
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

697 - Partially compliant

Compliant requirements:

  • Split persistence.rs into focused submodules: credential, style_pack, paths, dictionary, history, preferences, correction
  • Public surface unchanged (all previously pub items re-exported via pub use submodule::*)
  • No logic, signatures, or UI touched (pure move)
  • Shared helpers remain private in mod.rs; child modules use super::

Non-compliant requirements:

  • None from code inspection

Requires further human verification:

  • Actual CI runs (cargo test, tsc, build, all-platform) are needed to confirm cross-platform compatibility (e.g., Windows cfg-gated types)
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ No major issues detected

@appergb appergb merged commit a94ea3d into beta Jun 17, 2026
5 checks passed
@appergb appergb deleted the refactor/split-persistence branch June 17, 2026 08:10
appergb pushed a commit that referenced this pull request Jun 17, 2026
Re-cut of the 1.3.10-2 beta from the synced cloud beta branch (supersedes the
-2 pre-release, which was deleted). Identical code to 1.3.10-2 — version-number
bump only. Bundles #701 persistence split, #702 top-bar unification, #703
onboarding accessibility gate, on top of 1.3.10-1 audit fixes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant