chore: rustfmt the workspace and make clippy -D warnings pass

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-14 19:19:21 +07:00
parent d7fe99edd7
commit f13f0e6953
46 changed files with 6606 additions and 1496 deletions

View File

@@ -61,8 +61,13 @@ impl RetentionPolicy {
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[serde(tag = "mode", rename_all = "snake_case", deny_unknown_fields)]
pub enum CaptureRetention {
Age { days: u16 },
Count { #[serde(default = "fallback_count")] keep: u16 },
Age {
days: u16,
},
Count {
#[serde(default = "fallback_count")]
keep: u16,
},
}
fn fallback_count() -> u16 {
@@ -90,13 +95,20 @@ pub fn evaluate_capture_retention(
now: DateTime<Utc>,
) -> Vec<Uuid> {
snapshots.sort_unstable_by_key(|snapshot| std::cmp::Reverse((snapshot.taken_at, snapshot.id)));
snapshots.into_iter().enumerate().skip(1).filter_map(|(index, snapshot)| {
let expired = match policy {
CaptureRetention::Age { days } => now.signed_duration_since(snapshot.taken_at).num_days() >= i64::from(days),
CaptureRetention::Count { keep } => index >= usize::from(keep),
};
expired.then_some(snapshot.id)
}).collect()
snapshots
.into_iter()
.enumerate()
.skip(1)
.filter_map(|(index, snapshot)| {
let expired = match policy {
CaptureRetention::Age { days } => {
now.signed_duration_since(snapshot.taken_at).num_days() >= i64::from(days)
}
CaptureRetention::Count { keep } => index >= usize::from(keep),
};
expired.then_some(snapshot.id)
})
.collect()
}
/// Keep the newest snapshot in each of the most recent occupied UTC periods.
@@ -175,7 +187,10 @@ pub fn evaluate_decay(policy: &DecayPolicy, mut snapshots: Vec<SnapshotRef>) ->
let mut months: Vec<(i32, u32, SnapshotRef)> = Vec::new();
for s in &snapshots {
let key = (s.taken_at.year(), s.taken_at.month());
if let Some(pos) = months.iter().position(|(y, m, _)| *y == key.0 && *m == key.1) {
if let Some(pos) = months
.iter()
.position(|(y, m, _)| *y == key.0 && *m == key.1)
{
if s.taken_at > months[pos].2.taken_at {
months[pos] = (key.0, key.1, s.clone());
}
@@ -204,14 +219,23 @@ mod tests {
#[test]
fn capture_retention_keeps_one_old_archive_or_the_latest_five() {
let now = Utc::now();
let snapshots: Vec<_> = (0..6).map(|i| SnapshotRef {
id: Uuid::new_v4(),
taken_at: now - Duration::days(15 + i),
}).collect();
assert_eq!(evaluate_capture_retention(CaptureRetention::default(), snapshots.clone(), now),
snapshots[1..].iter().map(|snap| snap.id).collect::<Vec<_>>());
assert_eq!(evaluate_capture_retention(CaptureRetention::Count { keep: 5 }, snapshots.clone(), now),
[snapshots[5].id]);
let snapshots: Vec<_> = (0..6)
.map(|i| SnapshotRef {
id: Uuid::new_v4(),
taken_at: now - Duration::days(15 + i),
})
.collect();
assert_eq!(
evaluate_capture_retention(CaptureRetention::default(), snapshots.clone(), now),
snapshots[1..]
.iter()
.map(|snap| snap.id)
.collect::<Vec<_>>()
);
assert_eq!(
evaluate_capture_retention(CaptureRetention::Count { keep: 5 }, snapshots.clone(), now),
[snapshots[5].id]
);
}
#[test]

View File

@@ -21,9 +21,7 @@ impl TesseraError {
"Another orbit is still circling the vault. Try again when it finishes."
}
TesseraError::WrongPassphrase => "That key doesn't unlock this vault.",
TesseraError::ProviderUnreachable(_) => {
"We couldn't reach the source at this outpost."
}
TesseraError::ProviderUnreachable(_) => "We couldn't reach the source at this outpost.",
TesseraError::DiskFull { .. } => {
"The vault is out of space—free room or widen the hold."
}