From 715ec581803cde184bf804c9d3f6ee4965baaee3 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 31 Oct 2026 09:10:07 +0100 Subject: [PATCH] sources: Refreshed::is_clean decides the exit, where a test reaches it Co-Authored-By: Claude Sonnet 5.5 --- crates/huginn-daemon/src/bin/huginn-sources.rs | 2 +- crates/huginn-daemon/src/sources/mod.rs | 7 +++++++ crates/huginn-daemon/src/sources/tests.rs | 8 ++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/crates/huginn-daemon/src/bin/huginn-sources.rs b/crates/huginn-daemon/src/bin/huginn-sources.rs index e3b03c7..fc5a291 100644 --- a/crates/huginn-daemon/src/bin/huginn-sources.rs +++ b/crates/huginn-daemon/src/bin/huginn-sources.rs @@ -81,7 +81,7 @@ fn main() -> ExitCode { let mut forge = HttpForge::new(&options.forge_url); let mut journal = |report: &huginn_daemon::sources::Report| println!("{report}"); match refresh(&mut embedder, &mut index, &mut forge, &options.state_root, &mut journal) { - Ok(refreshed) if refreshed.failed.is_empty() && refreshed.retirement_withheld.is_none() => ExitCode::SUCCESS, + Ok(refreshed) if refreshed.is_clean() => ExitCode::SUCCESS, Ok(refreshed) => { if !refreshed.failed.is_empty() { eprintln!("huginn-sources: {} repos failed: {}", refreshed.failed.len(), refreshed.failed.join(", ")); diff --git a/crates/huginn-daemon/src/sources/mod.rs b/crates/huginn-daemon/src/sources/mod.rs index b8843ed..0a45872 100644 --- a/crates/huginn-daemon/src/sources/mod.rs +++ b/crates/huginn-daemon/src/sources/mod.rs @@ -199,6 +199,13 @@ pub struct Refreshed { pub retirement_withheld: Option, } +impl Refreshed { + /// Every repo converged and the catalog could be trusted to retire from. + pub fn is_clean(&self) -> bool { + self.failed.is_empty() && self.retirement_withheld.is_none() + } +} + /// Brings the collection to the forge's current state. A collection that /// exists without Huginn's label is refused untouched. One repo's failure is /// logged and the others go on; the caller exits nonzero if any failed. diff --git a/crates/huginn-daemon/src/sources/tests.rs b/crates/huginn-daemon/src/sources/tests.rs index 97bce7b..698f828 100644 --- a/crates/huginn-daemon/src/sources/tests.rs +++ b/crates/huginn-daemon/src/sources/tests.rs @@ -380,6 +380,14 @@ fn a_repo_renamed_only_by_case_keeps_no_stale_points() { assert_eq!(rig.index.cursors().into_iter().collect::>(), [("demo".to_owned(), head)]); } +/// A run is clean only when no repo failed and retirement was not withheld. +#[test] +fn a_run_is_clean_only_when_nothing_failed_and_retirement_was_not_withheld() { + assert!(Refreshed::default().is_clean()); + assert!(!Refreshed { failed: vec!["Demo".into()], retirement_withheld: None }.is_clean()); + assert!(!Refreshed { failed: Vec::new(), retirement_withheld: Some("short".into()) }.is_clean()); +} + /// A mirror no cursor knows (a first ingest that never finished) is retired /// with its points too. #[test]