style: cargo fmt --all (v0.20.x logging r2 feature follow-up)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-28 06:34:01 +00:00
parent 35c987df1c
commit 9a36a06f97
9 changed files with 48 additions and 60 deletions

1
Cargo.lock generated
View File

@@ -4133,6 +4133,7 @@ dependencies = [
"base64 0.22.1", "base64 0.22.1",
"blake3", "blake3",
"dirs 5.0.1", "dirs 5.0.1",
"filetime",
"ignore", "ignore",
"image", "image",
"kebab-chunk", "kebab-chunk",

View File

@@ -1147,10 +1147,7 @@ impl App {
} }
#[doc(hidden)] #[doc(hidden)]
pub fn inspect_ocr_stats_with_config( pub fn inspect_ocr_stats_with_config(&self, _cfg: &kebab_config::Config) -> Result<OcrStatsV1> {
&self,
_cfg: &kebab_config::Config,
) -> Result<OcrStatsV1> {
use crate::ingest_log::percentiles; use crate::ingest_log::percentiles;
let conn = self.sqlite.read_conn(); let conn = self.sqlite.read_conn();
@@ -1189,9 +1186,7 @@ impl App {
let mut by_engine = std::collections::BTreeMap::new(); let mut by_engine = std::collections::BTreeMap::new();
{ {
let mut stmt = conn let mut stmt = conn
.prepare( .prepare("SELECT ocr_engine, COUNT(*) FROM pdf_ocr_events GROUP BY ocr_engine")
"SELECT ocr_engine, COUNT(*) FROM pdf_ocr_events GROUP BY ocr_engine",
)
.context("prepare engine query")?; .context("prepare engine query")?;
let rows = stmt let rows = stmt
.query_map([], |r| Ok((r.get::<_, String>(0)?, r.get::<_, u64>(1)?))) .query_map([], |r| Ok((r.get::<_, String>(0)?, r.get::<_, u64>(1)?)))
@@ -1215,17 +1210,14 @@ impl App {
LIMIT 10", LIMIT 10",
) )
.context("prepare by_doc query")?; .context("prepare by_doc query")?;
stmt.query_map( stmt.query_map([], |r| {
[], Ok(OcrStatsByDoc {
|r| { doc_id: r.get(0)?,
Ok(OcrStatsByDoc { failure_count: r.get(1)?,
doc_id: r.get(0)?, success_count: r.get(2)?,
failure_count: r.get(1)?, p90_ms: None, // per-doc p90 deferred (open question #3)
success_count: r.get(2)?, })
p90_ms: None, // per-doc p90 deferred (open question #3) })
})
},
)
.context("query by_doc")? .context("query by_doc")?
.filter_map(|r| r.ok()) .filter_map(|r| r.ok())
.collect() .collect()

View File

@@ -206,9 +206,7 @@ impl IngestSummary {
/// Simple percentile extraction on a sorted copy of `samples`. /// Simple percentile extraction on a sorted copy of `samples`.
/// Returns `(p50, p90, p99, max)`. All `None` when samples is empty. /// Returns `(p50, p90, p99, max)`. All `None` when samples is empty.
/// p99 surfaces via `inspect ocr-stats`; `IngestSummary` uses p50/p90/max only. /// p99 surfaces via `inspect ocr-stats`; `IngestSummary` uses p50/p90/max only.
pub(crate) fn percentiles( pub(crate) fn percentiles(samples: &[u64]) -> (Option<u64>, Option<u64>, Option<u64>, Option<u64>) {
samples: &[u64],
) -> (Option<u64>, Option<u64>, Option<u64>, Option<u64>) {
if samples.is_empty() { if samples.is_empty() {
return (None, None, None, None); return (None, None, None, None);
} }
@@ -245,13 +243,7 @@ pub(crate) fn cleanup_old_logs(
.collect(); .collect();
// Sort newest-first by mtime (files without mtime go to the end). // Sort newest-first by mtime (files without mtime go to the end).
entries.sort_by_key(|e| { entries.sort_by_key(|e| std::cmp::Reverse(e.metadata().ok().and_then(|m| m.modified().ok())));
std::cmp::Reverse(
e.metadata()
.ok()
.and_then(|m| m.modified().ok()),
)
});
let cutoff = SystemTime::now() let cutoff = SystemTime::now()
.checked_sub(std::time::Duration::from_secs( .checked_sub(std::time::Duration::from_secs(
@@ -414,11 +406,7 @@ mod tests {
let mtime = SystemTime::now() let mtime = SystemTime::now()
.checked_sub(std::time::Duration::from_secs(age_days * 86400)) .checked_sub(std::time::Duration::from_secs(age_days * 86400))
.unwrap(); .unwrap();
filetime::set_file_mtime( filetime::set_file_mtime(&path, filetime::FileTime::from_system_time(mtime)).unwrap();
&path,
filetime::FileTime::from_system_time(mtime),
)
.unwrap();
} }
// keep_recent=3, retention_days=90 (no time-based deletion) // keep_recent=3, retention_days=90 (no time-based deletion)
cleanup_old_logs(dir, 3, 90).unwrap(); cleanup_old_logs(dir, 3, 90).unwrap();
@@ -442,11 +430,7 @@ mod tests {
let mtime = SystemTime::now() let mtime = SystemTime::now()
.checked_sub(std::time::Duration::from_secs(90 * 86400)) .checked_sub(std::time::Duration::from_secs(90 * 86400))
.unwrap(); .unwrap();
filetime::set_file_mtime( filetime::set_file_mtime(&path, filetime::FileTime::from_system_time(mtime)).unwrap();
&path,
filetime::FileTime::from_system_time(mtime),
)
.unwrap();
} }
// keep_recent=10 (both within count) but retention_days=30 → both stale // keep_recent=10 (both within count) but retention_days=30 → both stale
cleanup_old_logs(dir, 10, 30).unwrap(); cleanup_old_logs(dir, 10, 30).unwrap();
@@ -454,6 +438,10 @@ mod tests {
.unwrap() .unwrap()
.filter_map(|e| e.ok()) .filter_map(|e| e.ok())
.collect(); .collect();
assert_eq!(remaining.len(), 0, "stale files must be deleted even within keep_recent"); assert_eq!(
remaining.len(),
0,
"stale files must be deleted even within keep_recent"
);
} }
} }

View File

@@ -190,10 +190,9 @@ where
kind: ProvenanceKind::Warning, kind: ProvenanceKind::Warning,
note: Some(note), note: Some(note),
}); });
let (image_width, image_height) = let (image_width, image_height) = extract_image_dimensions(&page_image_bytes)
extract_image_dimensions(&page_image_bytes) .map(|(w, h)| (Some(w), Some(h)))
.map(|(w, h)| (Some(w), Some(h))) .unwrap_or((None, None));
.unwrap_or((None, None));
emit_progress(PdfOcrProgress::Finished { emit_progress(PdfOcrProgress::Finished {
page: page_num, page: page_num,
ms: start.elapsed().as_millis() as u64, ms: start.elapsed().as_millis() as u64,

View File

@@ -111,7 +111,10 @@ fn ocr_failures_corpus_wide() {
assert_eq!(result.schema_version, "ocr_failures.v1"); assert_eq!(result.schema_version, "ocr_failures.v1");
assert!(result.failure_count >= 1, "expected at least 1 failure"); assert!(result.failure_count >= 1, "expected at least 1 failure");
assert!(!result.failures.is_empty(), "failures list must be non-empty"); assert!(
!result.failures.is_empty(),
"failures list must be non-empty"
);
} }
/// AC-5: `inspect_ocr_failures` with doc_id filter returns matching rows. /// AC-5: `inspect_ocr_failures` with doc_id filter returns matching rows.

View File

@@ -66,8 +66,7 @@ async fn ingest_dual_write_doc_id_matches_ndjson() {
std::fs::copy(scanned_pdf_src(), &dest).expect("copy scanned PDF"); std::fs::copy(scanned_pdf_src(), &dest).expect("copy scanned PDF");
// Run ingest // Run ingest
kebab_app::ingest_with_config(env.config.clone(), env.scope(), false) kebab_app::ingest_with_config(env.config.clone(), env.scope(), false).expect("ingest");
.expect("ingest");
// Read ndjson log // Read ndjson log
let log_files: Vec<_> = std::fs::read_dir(&log_dir) let log_files: Vec<_> = std::fs::read_dir(&log_dir)

View File

@@ -54,10 +54,7 @@ ingest_log_dir = "{state_dir}/logs"
"#; "#;
let w: LoggingWrapper = toml::from_str(toml).expect("old logging config must parse"); let w: LoggingWrapper = toml::from_str(toml).expect("old logging config must parse");
assert!(w.logging.ingest_log_enabled); assert!(w.logging.ingest_log_enabled);
assert_eq!( assert_eq!(w.logging.ingest_log_dir, PathBuf::from("{state_dir}/logs"));
w.logging.ingest_log_dir,
PathBuf::from("{state_dir}/logs")
);
assert_eq!( assert_eq!(
w.logging.keep_recent_runs, 100, w.logging.keep_recent_runs, 100,
"keep_recent_runs must default to 100" "keep_recent_runs must default to 100"

View File

@@ -1018,11 +1018,19 @@ impl SqliteStore {
ms, chars, success, reason, ocr_engine) ms, chars, success, reason, ocr_engine)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
rusqlite::params![ rusqlite::params![
run_id, ts, doc_id, doc_path, page, run_id,
image_byte_size, image_width, image_height, ts,
ms, chars, doc_id,
doc_path,
page,
image_byte_size,
image_width,
image_height,
ms,
chars,
if success { 1i32 } else { 0i32 }, if success { 1i32 } else { 0i32 },
reason, ocr_engine reason,
ocr_engine
], ],
)?; )?;
Ok(()) Ok(())
@@ -1034,8 +1042,7 @@ impl SqliteStore {
/// means "delete everything older than now" (i.e. all past rows). /// means "delete everything older than now" (i.e. all past rows).
pub fn prune_pdf_ocr_events(&self, retention_days: u32) -> anyhow::Result<u64> { pub fn prune_pdf_ocr_events(&self, retention_days: u32) -> anyhow::Result<u64> {
use time::format_description::well_known::Rfc3339; use time::format_description::well_known::Rfc3339;
let cutoff = time::OffsetDateTime::now_utc() let cutoff = time::OffsetDateTime::now_utc() - time::Duration::days(retention_days as i64);
- time::Duration::days(retention_days as i64);
let cutoff_ts = cutoff let cutoff_ts = cutoff
.format(&Rfc3339) .format(&Rfc3339)
.unwrap_or_else(|_| "1970-01-01T00:00:00Z".to_string()); .unwrap_or_else(|_| "1970-01-01T00:00:00Z".to_string());

View File

@@ -25,7 +25,11 @@ fn v008_pdf_ocr_events_table_exists() {
) )
.optional() .optional()
}); });
assert_eq!(name.as_deref(), Some("pdf_ocr_events"), "pdf_ocr_events table must exist after V008"); assert_eq!(
name.as_deref(),
Some("pdf_ocr_events"),
"pdf_ocr_events table must exist after V008"
);
} }
/// AC-8: insert 2 rows with different timestamps; prune with retention_days=0 /// AC-8: insert 2 rows with different timestamps; prune with retention_days=0
@@ -74,9 +78,7 @@ fn record_and_prune_pdf_ocr_event() {
// prune with retention_days=0 → cutoff=now → deletes any row with ts < now. // prune with retention_days=0 → cutoff=now → deletes any row with ts < now.
// The 1970 row should be deleted; the 2099 row survives. // The 1970 row should be deleted; the 2099 row survives.
let pruned = store let pruned = store.prune_pdf_ocr_events(0).expect("prune");
.prune_pdf_ocr_events(0)
.expect("prune");
assert_eq!(pruned, 1, "should have deleted exactly 1 old row"); assert_eq!(pruned, 1, "should have deleted exactly 1 old row");
// Verify only the future row remains // Verify only the future row remains