use serde::Serialize;
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct OmenaTestkitSnapshotGovernancePolicyV0 {
pub fixture_grammar: &'static str,
pub snapshot_manifest_schema: &'static str,
pub known_failure_schema: &'static str,
pub allow_global_disable: bool,
pub update_requires_review: bool,
pub unreferenced_action: &'static str,
pub hot_snapshot_max_age_days: u32,
pub known_failure_review_period_days: u32,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct OmenaTestkitKnownFailureRecordV0 {
pub rationale: &'static str,
pub owner: &'static str,
pub age_days: u32,
pub has_expiry_or_review_policy: bool,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct OmenaTestkitSnapshotGovernanceSeedV0 {
pub snapshot_id: &'static str,
pub fixture_id: &'static str,
pub snapshot_path: &'static str,
pub referenced_by_fixture: bool,
pub hot_snapshot: bool,
pub age_days: u32,
pub known_failure: Option<OmenaTestkitKnownFailureRecordV0>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct OmenaTestkitSnapshotGovernanceVerdictV0 {
pub snapshot_id: &'static str,
pub fixture_id: &'static str,
pub rejected_unreferenced: bool,
pub hot_snapshot_review_required: bool,
pub known_failure_review_required: bool,
pub known_failure_policy_complete: bool,
pub action: &'static str,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct OmenaTestkitSnapshotGovernanceReportV0 {
pub schema_version: &'static str,
pub product: &'static str,
pub fixture_grammar: &'static str,
pub policy: OmenaTestkitSnapshotGovernancePolicyV0,
pub seed_count: usize,
pub global_disable_rejected: bool,
pub unreferenced_reject_ready: bool,
pub hot_snapshot_age_audit_ready: bool,
pub known_failure_policy_ready: bool,
pub rejected_unreferenced_count: usize,
pub hot_snapshot_review_required_count: usize,
pub known_failure_count: usize,
pub known_failure_review_required_count: usize,
pub verdicts: Vec<OmenaTestkitSnapshotGovernanceVerdictV0>,
}
const SNAPSHOT_POLICY: OmenaTestkitSnapshotGovernancePolicyV0 =
OmenaTestkitSnapshotGovernancePolicyV0 {
fixture_grammar: "omena-fixture-v0",
snapshot_manifest_schema: "omena-testkit-snapshot-manifest-v0",
known_failure_schema: "omena-testkit-known-failures-v0",
allow_global_disable: false,
update_requires_review: true,
unreferenced_action: "reject",
hot_snapshot_max_age_days: 14,
known_failure_review_period_days: 30,
};
const SNAPSHOT_GOVERNANCE_SEEDS: &[OmenaTestkitSnapshotGovernanceSeedV0] = &[
OmenaTestkitSnapshotGovernanceSeedV0 {
snapshot_id: "style-facts-current",
fixture_id: "shared-style-fixture",
snapshot_path: "snapshots/shared-style-fixture/style-facts.snap.json",
referenced_by_fixture: true,
hot_snapshot: false,
age_days: 3,
known_failure: None,
},
OmenaTestkitSnapshotGovernanceSeedV0 {
snapshot_id: "orphan-style-facts",
fixture_id: "removed-fixture",
snapshot_path: "snapshots/removed-fixture/style-facts.snap.json",
referenced_by_fixture: false,
hot_snapshot: false,
age_days: 2,
known_failure: None,
},
OmenaTestkitSnapshotGovernanceSeedV0 {
snapshot_id: "hot-lsp-hover",
fixture_id: "lsp-hover-scenario",
snapshot_path: "snapshots/lsp-hover-scenario/hover.snap.json",
referenced_by_fixture: true,
hot_snapshot: true,
age_days: 21,
known_failure: None,
},
OmenaTestkitSnapshotGovernanceSeedV0 {
snapshot_id: "known-failure-source-rename",
fixture_id: "dynamic-source-rename-scenario",
snapshot_path: "snapshots/dynamic-source-rename-scenario/rename.snap.json",
referenced_by_fixture: true,
hot_snapshot: true,
age_days: 5,
known_failure: Some(OmenaTestkitKnownFailureRecordV0 {
rationale: "issue-38 dynamic identifier rename path is tracked as an M4 gate",
owner: "m4-axis-a-testkit",
age_days: 31,
has_expiry_or_review_policy: true,
}),
},
];
pub fn summarize_omena_testkit_snapshot_governance_report() -> OmenaTestkitSnapshotGovernanceReportV0
{
let verdicts = SNAPSHOT_GOVERNANCE_SEEDS
.iter()
.map(snapshot_governance_verdict)
.collect::<Vec<_>>();
let rejected_unreferenced_count = verdicts
.iter()
.filter(|verdict| verdict.rejected_unreferenced)
.count();
let hot_snapshot_review_required_count = verdicts
.iter()
.filter(|verdict| verdict.hot_snapshot_review_required)
.count();
let known_failure_count = SNAPSHOT_GOVERNANCE_SEEDS
.iter()
.filter(|seed| seed.known_failure.is_some())
.count();
let known_failure_review_required_count = verdicts
.iter()
.filter(|verdict| verdict.known_failure_review_required)
.count();
let known_failure_policy_ready = SNAPSHOT_GOVERNANCE_SEEDS
.iter()
.filter_map(|seed| seed.known_failure.as_ref())
.all(|known_failure| {
!known_failure.rationale.trim().is_empty()
&& !known_failure.owner.trim().is_empty()
&& known_failure.has_expiry_or_review_policy
});
OmenaTestkitSnapshotGovernanceReportV0 {
schema_version: "0",
product: "omena-testkit.snapshot-governance",
fixture_grammar: SNAPSHOT_POLICY.fixture_grammar,
policy: SNAPSHOT_POLICY,
seed_count: SNAPSHOT_GOVERNANCE_SEEDS.len(),
global_disable_rejected: !SNAPSHOT_POLICY.allow_global_disable,
unreferenced_reject_ready: rejected_unreferenced_count > 0
&& SNAPSHOT_POLICY.unreferenced_action == "reject",
hot_snapshot_age_audit_ready: hot_snapshot_review_required_count > 0,
known_failure_policy_ready,
rejected_unreferenced_count,
hot_snapshot_review_required_count,
known_failure_count,
known_failure_review_required_count,
verdicts,
}
}
fn snapshot_governance_verdict(
seed: &OmenaTestkitSnapshotGovernanceSeedV0,
) -> OmenaTestkitSnapshotGovernanceVerdictV0 {
let rejected_unreferenced =
!seed.referenced_by_fixture && SNAPSHOT_POLICY.unreferenced_action == "reject";
let hot_snapshot_review_required =
seed.hot_snapshot && seed.age_days > SNAPSHOT_POLICY.hot_snapshot_max_age_days;
let known_failure_review_required = seed.known_failure.as_ref().is_some_and(|known_failure| {
known_failure.age_days > SNAPSHOT_POLICY.known_failure_review_period_days
});
let known_failure_policy_complete = seed.known_failure.as_ref().is_none_or(|known_failure| {
!known_failure.rationale.trim().is_empty()
&& !known_failure.owner.trim().is_empty()
&& known_failure.has_expiry_or_review_policy
});
let action = if rejected_unreferenced {
"reject"
} else if hot_snapshot_review_required || known_failure_review_required {
"review"
} else {
"accept"
};
OmenaTestkitSnapshotGovernanceVerdictV0 {
snapshot_id: seed.snapshot_id,
fixture_id: seed.fixture_id,
rejected_unreferenced,
hot_snapshot_review_required,
known_failure_review_required,
known_failure_policy_complete,
action,
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn snapshot_governance_rejects_unreferenced_snapshots() {
let report = summarize_omena_testkit_snapshot_governance_report();
assert_eq!(report.product, "omena-testkit.snapshot-governance");
assert_eq!(report.fixture_grammar, "omena-fixture-v0");
assert!(report.global_disable_rejected);
assert!(report.policy.update_requires_review);
assert!(report.unreferenced_reject_ready);
assert_eq!(report.rejected_unreferenced_count, 1);
assert!(
report
.verdicts
.iter()
.any(|verdict| verdict.snapshot_id == "orphan-style-facts"
&& verdict.rejected_unreferenced
&& verdict.action == "reject")
);
}
#[test]
fn snapshot_governance_audits_hot_snapshots_and_known_failures() {
let report = summarize_omena_testkit_snapshot_governance_report();
assert!(report.hot_snapshot_age_audit_ready);
assert_eq!(report.hot_snapshot_review_required_count, 1);
assert!(report.known_failure_policy_ready);
assert_eq!(report.known_failure_count, 1);
assert_eq!(report.known_failure_review_required_count, 1);
assert!(report.verdicts.iter().any(|verdict| verdict.snapshot_id
== "known-failure-source-rename"
&& verdict.known_failure_review_required
&& verdict.known_failure_policy_complete
&& verdict.action == "review"));
}
}