Skip to content

Deduplicate test-fixture boilerplate in post-Batch-C writer+pool setup #126

Open

Description

@utof

After Batch C Task 7, every writer+pool test fixture follows the same shape:

```rust
struct NoopBus; // or NullBus — both equivalent
impl EventBus for NoopBus {
fn emit(&self, _: &FileEvent) -> Result<(), CoreError> { Ok(()) }
}

let td = tempfile::tempdir().expect("tempdir");
let db_path = td.path().join("test.db");
let bus: Arc = Arc::new(NoopBus);
let writer = SqliteWriter::start(&db_path, bus).expect("writer start");
let reads = ReadPool::open(&db_path).expect("pool open");
```

This appears at least 13 times across the workspace:

  • `crates/app/src/{container,metadata,scan,search,tag,volume}.rs`
  • `crates/db/src/{file_repo,metadata_repo,search_repo,tag_repo,volume_repo}.rs`
  • `crates/db/tests/writer_hlc_{file,metadata,volume}.rs`
  • `crates/desktop/tests/commands_test.rs` (4 instances)

Proposal

Add a small internal `testing` helper, either:

  1. A `perima_app::testing` module gated on `#[cfg(test)]` with `NoopBus` + `test_writer_pool(db_path: &Path) -> (SqliteWriterHandle, ReadPool)` helper.
  2. Or a `perima_db::testing` submodule exposing the same.

Also the `fts_matches_ground_truth_under_soft_delete_churn` proptest destructures `let (_td, db, _repo, _writer) = test_db();` but never uses `_repo` — a dedicated `test_db_raw()` would avoid constructing an unused `SqliteSearchRepository` per case.

Acceptance

  • `rg 'impl EventBus for NoopBus' crates/` returns ≤1 hit.
  • New `#[cfg(test)]` tests use the shared helper; existing tests migrated.
  • Ground-truth proptest uses `test_db_raw()` (or equivalent).

Not blocking any future batch. Surfaced by a code review after Batch C Task 7.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions