use super::models::{AlloyContractReport, RestartRequeryEvidenceV1};
impl AlloyContractReport {
pub fn to_json_pretty(&self) -> String {
let metrics = self
.baseline_metric_names
.iter()
.map(|name| format!("\"{}\"", name))
.collect::<Vec<_>>()
.join(", ");
format!(
concat!(
"{{\n",
" \"scenario\": \"{}\",\n",
" \"assurance_scope\": \"{}\",\n",
" \"telemetry_scope\": \"{}\",\n",
" \"evidence_artifact_name\": \"{}\",\n",
" \"evidence_report_line\": \"{}\",\n",
" \"replay_bundle_artifact_name\": \"{}\",\n",
" \"scenario_manifest_summary\": \"{}\",\n",
" \"permits_release\": {},\n",
" \"health\": {{\n",
" \"component\": \"{}\",\n",
" \"readiness\": \"{}\",\n",
" \"liveness\": \"{}\",\n",
" \"degradation_reason\": {}\n",
" }},\n",
" \"trace\": {{\n",
" \"operation\": \"{}\",\n",
" \"trace_id\": \"{}\",\n",
" \"span_id\": \"{}\",\n",
" \"parent_span_id\": {},\n",
" \"correlation_id\": {}\n",
" }},\n",
" \"baseline_metric_names\": [{}]\n",
"}}\n"
),
self.scenario.scenario_id(),
self.scope,
self.telemetry_scope,
self.evidence_artifact_name,
self.evidence_report_line.replace('"', "\\\""),
self.replay_bundle_artifact_name,
self.scenario_manifest_summary.replace('"', "\\\""),
self.permits_release,
self.health_component,
self.health_readiness,
self.health_liveness,
self.degradation_reason
.as_ref()
.map(|value| format!("\"{}\"", value))
.unwrap_or_else(|| "null".to_string()),
self.trace_operation,
self.trace_id,
self.span_id,
self.parent_span_id
.as_ref()
.map(|value| format!("\"{}\"", value))
.unwrap_or_else(|| "null".to_string()),
self.correlation_id
.as_ref()
.map(|value| format!("\"{}\"", value))
.unwrap_or_else(|| "null".to_string()),
metrics,
)
}
}
impl RestartRequeryEvidenceV1 {
pub fn to_json_pretty(&self) -> String {
let assertions = self
.assertions
.iter()
.map(|assertion| {
format!(
concat!(
" {{\n",
" \"assertion_id\": \"{}\",\n",
" \"description\": \"{}\",\n",
" \"required\": {},\n",
" \"outcome\": \"{}\",\n",
" \"artifact_name\": \"{}\"\n",
" }}"
),
assertion.assertion_id,
assertion.description,
assertion.required,
assertion.outcome,
assertion.artifact_name
)
})
.collect::<Vec<_>>()
.join(",\n");
let artifacts = self
.attached_artifacts
.iter()
.map(|artifact| {
format!(
concat!(
" {{\n",
" \"artifact_name\": \"{}\",\n",
" \"media_type\": \"{}\",\n",
" \"role\": \"{}\"\n",
" }}"
),
artifact.artifact_name, artifact.media_type, artifact.role
)
})
.collect::<Vec<_>>()
.join(",\n");
let reproduction_commands = self
.replay_payload
.reproduction_commands
.iter()
.map(|command| format!(" \"{}\"", command))
.collect::<Vec<_>>()
.join(",\n");
format!(
concat!(
"{{\n",
" \"schema\": \"{}\",\n",
" \"assurance_scope\": \"{}\",\n",
" \"telemetry_scope\": \"{}\",\n",
" \"workload_identity\": {{\n",
" \"workload_id\": \"{}\",\n",
" \"workload_label\": \"{}\",\n",
" \"fixture_id\": \"{}\",\n",
" \"executor\": \"{}\",\n",
" \"commit_or_version\": \"{}\",\n",
" \"planner_surface\": \"{}\"\n",
" }},\n",
" \"checked_at_epoch_seconds\": {},\n",
" \"permits_release\": {},\n",
" \"assertions\": [\n{}\n",
" ],\n",
" \"attached_artifacts\": [\n{}\n",
" ],\n",
" \"replay_payload\": {{\n",
" \"replay_bundle_artifact_name\": \"{}\",\n",
" \"scenario_manifest_summary\": \"{}\",\n",
" \"trace_operation\": \"{}\",\n",
" \"trace_id\": \"{}\",\n",
" \"span_id\": \"{}\",\n",
" \"correlation_id\": {},\n",
" \"reproduction_commands\": [\n{}\n",
" ]\n",
" }}\n",
"}}\n"
),
self.schema,
self.assurance_scope,
self.telemetry_scope,
self.workload_identity.workload_id,
self.workload_identity.workload_label,
self.workload_identity.fixture_id,
self.workload_identity.executor,
self.workload_identity.commit_or_version,
self.workload_identity.planner_surface,
self.checked_at_epoch_seconds,
self.permits_release,
assertions,
artifacts,
self.replay_payload.replay_bundle_artifact_name,
self.replay_payload
.scenario_manifest_summary
.replace('"', "\\\""),
self.replay_payload.trace_operation,
self.replay_payload.trace_id,
self.replay_payload.span_id,
self.replay_payload
.correlation_id
.as_ref()
.map(|value| format!("\"{}\"", value))
.unwrap_or_else(|| "null".to_string()),
reproduction_commands,
)
}
}