Move inline #[cfg(test)] mod tests { ... } blocks from 22 source files
into dedicated _tests.rs companion files, wired via:
#[cfg(test)]
#[path = "module_tests.rs"]
mod tests;
This keeps implementation-focused source files leaner and more scannable
while preserving full access to private items through `use super::*;`.
Modules extracted:
core: db, note_parser, payloads, project, references, sync_run,
timeline_collect, timeline_expand, timeline_seed
cli: list (55 tests), who (75 tests)
documents: extractor (43 tests), regenerator
embedding: change_detector, chunking
gitlab: graphql (wiremock async tests), transformers/issue
ingestion: dirty_tracker, discussions, issues, mr_diffs
Also adds conflicts_with("explain_score") to the --detail flag in the
who command to prevent mutually exclusive flags from being combined.
All 629 unit tests pass. No behavior changes.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
71 lines
1.9 KiB
Rust
71 lines
1.9 KiB
Rust
use rusqlite::Connection;
|
|
|
|
use super::error::Result;
|
|
use super::metrics::StageTiming;
|
|
use super::time::now_ms;
|
|
|
|
pub struct SyncRunRecorder {
|
|
row_id: i64,
|
|
}
|
|
|
|
impl SyncRunRecorder {
|
|
pub fn start(conn: &Connection, command: &str, run_id: &str) -> Result<Self> {
|
|
let now = now_ms();
|
|
conn.execute(
|
|
"INSERT INTO sync_runs (started_at, heartbeat_at, status, command, run_id)
|
|
VALUES (?1, ?2, 'running', ?3, ?4)",
|
|
rusqlite::params![now, now, command, run_id],
|
|
)?;
|
|
let row_id = conn.last_insert_rowid();
|
|
Ok(Self { row_id })
|
|
}
|
|
|
|
pub fn succeed(
|
|
self,
|
|
conn: &Connection,
|
|
metrics: &[StageTiming],
|
|
total_items: usize,
|
|
total_errors: usize,
|
|
) -> Result<()> {
|
|
let now = now_ms();
|
|
let metrics_json = serde_json::to_string(metrics).unwrap_or_else(|_| "[]".to_string());
|
|
conn.execute(
|
|
"UPDATE sync_runs
|
|
SET finished_at = ?1, status = 'succeeded',
|
|
metrics_json = ?2, total_items_processed = ?3, total_errors = ?4
|
|
WHERE id = ?5",
|
|
rusqlite::params![
|
|
now,
|
|
metrics_json,
|
|
total_items as i64,
|
|
total_errors as i64,
|
|
self.row_id
|
|
],
|
|
)?;
|
|
Ok(())
|
|
}
|
|
|
|
pub fn fail(
|
|
self,
|
|
conn: &Connection,
|
|
error: &str,
|
|
metrics: Option<&[StageTiming]>,
|
|
) -> Result<()> {
|
|
let now = now_ms();
|
|
let metrics_json =
|
|
metrics.map(|m| serde_json::to_string(m).unwrap_or_else(|_| "[]".to_string()));
|
|
conn.execute(
|
|
"UPDATE sync_runs
|
|
SET finished_at = ?1, status = 'failed', error = ?2,
|
|
metrics_json = ?3
|
|
WHERE id = ?4",
|
|
rusqlite::params![now, error, metrics_json, self.row_id],
|
|
)?;
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
#[path = "sync_run_tests.rs"]
|
|
mod tests;
|