refactor(persistence): split persistence.rs into domain modules behind a barrel#701
Merged
Conversation
…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.
Contributor
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
User description
What
Splits the 2757-line
src-tauri/src/persistence.rsgod-file into a focusedpersistence/module — behavior-unchanged, pure move + re-export. Part of #697.mod.rsdata_dir,ensure_dir,atomic_write,read_or_default),HISTORY_CAP/PREFERENCES_FILE, module wiringpaths.rscredentials.rsCredsRootmodel, keyring/android/legacy,CredentialAccount,CredentialsSnapshot,CredentialsVaultstyle_pack.rsStylePackStore+ ZIP import/export + prefs reconciliationhistory.rsHistoryStoredictionary.rsDictionaryStore+ vocab presetspreferences.rsread_preferences+PreferencesStorecorrection.rsCorrectionRuleStoreHow / invariants
pubitem is re-exported withpub use <submodule>::*, socrate::persistence::*is identical and zero call sites changed (verified againstcoordinator,commands,asr/local/models).mod.rs; child modules reach them viasuper::(parent items are visible to descendants — no visibility widening needed).#[cfg(target_os="android")], Windowsfoundry_*) resolution-safe on every target, avoiding the explicit-pub usebreakage that sank the earliertypes.rssplit. The only import tweak is gatinguse anyhow::anyhow/use std::fsincredentials.rsso Android sees no new unused-import warning.credentials, prefs migration →preferences, vocab roundtrip →dictionary, correction syntax →correction, model-root →paths, style-pack sync →style_pack).credentials.rs(880) andstyle_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 forcepub(super)cross-module plumbing — the exact fragility this refactor is avoiding. Open to a follow-up sub-split if preferred.Test plan
cargo fmt— cleancargo check— 0 errors, 0 new warnings inpersistence/cargo clippy --no-deps— clean (the 3 persistence lints are pre-existing, on verbatim-moved code)cargo test --lib— 446 passed, 0 failed (count unchanged)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 usebarrel, zero call-site changesShared filesystem helpers stay private in mod.rs
Diagram Walkthrough
File Walkthrough
8 files
Module wiring, shared helpers, and glob re-exportsOS credential vault storeStyle-pack store with ZIP import/exportStorage path resolution for models, recordings, FoundryVocabulary dictionary store and vocab presetsDictation history store with retentionCorrection-rule storeUser preferences store with streamingInsert migration1 files