Skip to content

Commit fca9977

Browse files
committed
Add repair report contract
1 parent 2d37fe2 commit fca9977

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

src/report.rs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
use chrono::{DateTime, Utc};
2+
use serde::{Deserialize, Serialize};
3+
4+
use crate::models::HealthState;
5+
6+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
7+
#[serde(rename_all = "snake_case")]
8+
pub enum RepairMode {
9+
DryRun,
10+
Apply,
11+
}
12+
13+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
14+
#[serde(rename_all = "snake_case")]
15+
pub enum RepairRisk {
16+
SafeDerivedStateRebuild,
17+
ReviewRequired,
18+
PolicyBlocked,
19+
}
20+
21+
#[derive(Debug, Clone, Serialize, Deserialize)]
22+
pub struct RepairReport {
23+
pub report_id: String,
24+
pub mode: RepairMode,
25+
pub generated_at: DateTime<Utc>,
26+
pub health_before: HealthState,
27+
pub health_after: Option<HealthState>,
28+
pub affected_objects: u64,
29+
pub preserved_durable_objects: u64,
30+
pub rebuilt_indexes: u64,
31+
pub quarantined_objects: u64,
32+
pub unresolved_conflicts: u64,
33+
pub policy_decisions: Vec<String>,
34+
pub risk: RepairRisk,
35+
pub summary: String,
36+
pub next_action: String,
37+
}
38+
39+
pub fn sample_repair_report(now: DateTime<Utc>, mode: RepairMode) -> RepairReport {
40+
let (health_after, summary, next_action) = match mode {
41+
RepairMode::DryRun => (
42+
None,
43+
"Dry-run completed. No durable state was modified.".to_string(),
44+
"Review this report before running a scoped apply operation.".to_string(),
45+
),
46+
RepairMode::Apply => (
47+
Some(HealthState::Clean),
48+
"Apply completed against sample state. No durable user objects were modified.".to_string(),
49+
"Run `sourceos sync status` to verify current health.".to_string(),
50+
),
51+
};
52+
53+
RepairReport {
54+
report_id: format!("repair:{}", now.timestamp()),
55+
mode,
56+
generated_at: now,
57+
health_before: HealthState::RepairRecommended,
58+
health_after,
59+
affected_objects: 0,
60+
preserved_durable_objects: 0,
61+
rebuilt_indexes: 0,
62+
quarantined_objects: 0,
63+
unresolved_conflicts: 0,
64+
policy_decisions: vec![],
65+
risk: RepairRisk::SafeDerivedStateRebuild,
66+
summary,
67+
next_action,
68+
}
69+
}

0 commit comments

Comments
 (0)