use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct SpecChanged {
#[serde(default)]
pub app_id: String,
pub page_id: String,
pub kind: String,
pub at_ms: u64,
}
#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
#[serde(tag = "type", rename_all = "kebab-case")]
pub enum SpecApiEvent {
SpecChanged(SpecChanged),
SpecCheckInvoked {
#[serde(default)]
app_id: String,
snapshot_id: String,
page_ids: Vec<String>,
invoked_via: String,
at_ms: u64,
},
SpecCheckCompleted {
#[serde(default)]
app_id: String,
snapshot_id: String,
page_count: usize,
overall_match_rate: f32,
perfect_match_count: usize,
partial_match_count: usize,
no_match_count: usize,
eval_error_count: usize,
total_duration_ms: u64,
at_ms: u64,
},
SpecCheckPolicyViolation {
#[serde(default)]
app_id: String,
snapshot_id: String,
page_id: String,
conjunct_name: String,
rule_kind: String,
observed: serde_json::Value,
at_ms: u64,
},
FlywheelProposalPromoted {
#[serde(default)]
app_id: String,
proposal_id: String,
page_id: String,
consecutive_greens: u32,
snapshot_id: String,
at_ms: u64,
},
FlywheelProposalDemoted {
#[serde(default)]
app_id: String,
proposal_id: String,
page_id: String,
failing_assertion_id: String,
failing_state_id: String,
snapshot_id: String,
at_ms: u64,
},
}
impl SpecApiEvent {
pub fn app_id(&self) -> &str {
match self {
SpecApiEvent::SpecChanged(inner) => &inner.app_id,
SpecApiEvent::SpecCheckInvoked { app_id, .. }
| SpecApiEvent::SpecCheckCompleted { app_id, .. }
| SpecApiEvent::SpecCheckPolicyViolation { app_id, .. }
| SpecApiEvent::FlywheelProposalPromoted { app_id, .. }
| SpecApiEvent::FlywheelProposalDemoted { app_id, .. } => app_id,
}
}
}