use alloy_assurance::api as assurance_api;
use alloy_telemetry::api as telemetry_api;
use super::models::AlloyContractReport;
use super::scenario::ContractScenario;
pub fn contract_report(
scenario: ContractScenario,
commit_or_version: &str,
checked_at_epoch_seconds: u64,
) -> AlloyContractReport {
let replay_bundle = assurance_api::ReplayBundle::new(
scenario.scenario_id(),
"canonical-fixture-v1",
commit_or_version,
"embedded-evaluator",
);
let manifest = assurance_api::ScenarioManifest::new(
scenario.scenario_id(),
scenario.scenario_family(),
scenario.tags(),
);
let mut evidence = assurance_api::EvidenceEnvelope::new(
scenario.artifact_id(),
"canonical-fixture-v1",
commit_or_version,
"embedded-evaluator",
assurance_api::EvidenceLevel::ReleaseBlocking,
);
evidence.record_outcome(
assurance_api::ScenarioOutcome::Pass,
assurance_api::FailureClassification::None,
);
let health = telemetry_api::HealthSnapshot {
component: "iridium-embedded-evaluator",
readiness: telemetry_api::HealthState::Ready,
liveness: telemetry_api::HealthState::Live,
degradation_reason: None,
checked_at_epoch_seconds,
};
let trace = telemetry_api::TraceContext::child(
scenario.operation(),
"iridium-trace-embedded",
scenario.scenario_id(),
"iridium-root",
Some(scenario.scenario_id()),
);
let baseline_metric_names = telemetry_api::baseline_metric_catalog()
.iter()
.map(|metric| metric.name)
.collect::<Vec<_>>();
AlloyContractReport {
scenario,
scope: assurance_api::scope(),
evidence_artifact_name: evidence.artifact_name(),
evidence_report_line: evidence.report_line(),
replay_bundle_artifact_name: replay_bundle.artifact_name(),
scenario_manifest_summary: manifest.summary_line(),
permits_release: evidence.permits_release(),
telemetry_scope: telemetry_api::scope(),
health_component: health.component.to_string(),
health_readiness: match health.readiness {
telemetry_api::HealthState::Ready => "ready",
telemetry_api::HealthState::Live => "live",
telemetry_api::HealthState::NotReady => "not-ready",
},
health_liveness: match health.liveness {
telemetry_api::HealthState::Ready => "ready",
telemetry_api::HealthState::Live => "live",
telemetry_api::HealthState::NotReady => "not-ready",
},
degradation_reason: health.degradation_reason.map(ToString::to_string),
trace_operation: trace.operation.to_string(),
trace_id: trace.trace_id.to_string(),
span_id: trace.span_id.to_string(),
parent_span_id: trace.parent_span_id.map(ToString::to_string),
correlation_id: trace.correlation_id.map(ToString::to_string),
baseline_metric_names,
}
}