Watch
0
0
Fork
You've already forked hyperhive
0

add a /clear-todos command that marks the agent's todos done

This commit is contained in:
damocles 2026-11-16 00:34:38 +01:00 • committed by mara
commit dc0d08b7fb

View file

@ -323,6 +323,27 @@ impl Todos {
Ok(total)
}
/// The agent's operator dismisses every open todo at once: each is acked
/// exactly as [`Todos::mark_done`] would, so a reconciled producer's next
/// `upsert` still tells "unchanged" from "different". Returns the number
/// of rows newly acked.
///
/// # Errors
///
/// Propagates the sqlite update failure.
///
/// # Panics
///
/// Panics if the connection mutex is poisoned.
pub fn mark_all_done(&self) -> Result<usize> {
let conn = self.conn.lock().unwrap();
let n = conn.execute(
"UPDATE todos SET acked = 1, acked_at = ?1 WHERE acked = 0",
params![Utc::now().timestamp()],
)?;
Ok(n)
}
/// List todos, newest-updated first. `subsystem = Some(..)` filters to
/// one producer's set; `None` returns all. Excludes acked rows — once
/// the agent has dismissed a todo it stays out of its own list, even
@ -466,6 +487,23 @@ mod tests {
assert_eq!(left, ["c", "d", "e"]);
}
#[test]
fn mark_all_done_acks_every_open_todo_once_and_keeps_the_rows() {
let (_dir, s) = store();
let (done, _) = s.upsert("router", Some("a"), "a", None, true).unwrap();
s.mark_done(done).unwrap();
s.upsert("router", Some("b"), "b", None, true).unwrap();
s.upsert("matrix", None, "c", None, false).unwrap();
// The already-acked one is not counted again.
assert_eq!(s.mark_all_done().unwrap(), 2);
assert_eq!(s.mark_all_done().unwrap(), 0);
assert!(!s.has_any().unwrap());
// Acked, not deleted: an unchanged re-push is not new.
let (_, changed) = s.upsert("router", Some("b"), "b", None, false).unwrap();
assert!(!changed);
}
#[test]
fn keyed_upsert_dedups_and_reports_changed() {
let (_dir, s) = store();