Skip to content

refactor: split repo.rs God file into sidecar + per-theme test modules #70

@StudentWeis

Description

@StudentWeis

Current State

src/repository/repo.rs is currently a 1,694-line file. Roughly 460 lines are production logic; the remaining ~1,300 lines are #[cfg(test)] test cases embedded in the same file. The file simultaneously handles repository construction, schema migration, save/get/delete/clear, pin logic, dedup, and rich-text/image sidecar file management.

Target State

  • Tests are split by theme into src/repository/tests/{save,pin,dedup,display}_tests.rs, mounted via #[cfg(test)] mod tests; in src/repository/mod.rs.
  • Filesystem sidecar helpers (remove_image_files, remove_record_sidecars, remove_superseded_rich_text_files, schema-migration / clear directory cleanup) live in a new src/repository/sidecar.rs as free functions.
  • repo.rs is responsible only for DB encode/decode and delegates filesystem side-effects to sidecar.

Rationale

  • A single test edit currently recompiles the entire 1.7k-line file → slow incremental builds.
  • Adding a new ContentType requires reading the whole file to feel safe — high cognitive overhead.
  • Mixing DB logic with filesystem side-effects makes both harder to reason about and test in isolation.

This is item §1.1 ("src/repository/repo.rs — God File ⚠️ High Priority") in doc/CODE_REVIEW.md.

Acceptance Criteria

  • repo.rs production code stays ≤ ~500 lines and contains no embedded test module.
  • src/repository/sidecar.rs exists and owns all sidecar filesystem helpers as free functions.
  • Tests live under src/repository/tests/{save,pin,dedup,display}_tests.rs.
  • scripts/precheck.sh passes (fmt / check / clippy -D warnings / test / machete / i18n / icons / themes).
  • No behavior change — all existing tests still pass without modification of their assertions.

Scope

repository

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions