use alloy_assurance::api as assurance_api;
use super::models::{
EvidenceArtifactRef, RestartRequeryAssertion, RestartRequeryEvidenceV1,
RestartRequeryReplayPayload, WorkloadIdentity,
};
use super::reports::contract_report;
use super::scenario::ContractScenario;
pub fn restart_requery_evidence_v1(
commit_or_version: &str,
checked_at_epoch_seconds: u64,
) -> RestartRequeryEvidenceV1 {
let evidence = canonical_restart_requery_evidence(commit_or_version);
let report = contract_report(
ContractScenario::Acceptance,
commit_or_version,
checked_at_epoch_seconds,
);
RestartRequeryEvidenceV1 {
schema: assurance_api::restart_requery_schema_id(),
assurance_scope: report.scope,
telemetry_scope: report.telemetry_scope,
workload_identity: WorkloadIdentity {
workload_id: evidence.workload.workload_id,
workload_label: "embedded restart/re-query durability path",
fixture_id: evidence.workload.dataset_family,
executor: evidence.replay.runner,
commit_or_version: commit_or_version.to_string(),
planner_surface: "plexus-serialized-plan",
},
checked_at_epoch_seconds,
permits_release: evidence.envelope.permits_release() && report.permits_release,
assertions: evidence
.assertions
.iter()
.map(|assertion| RestartRequeryAssertion {
assertion_id: assertion.assertion_id,
description: assertion.description,
required: true,
outcome: assertion.outcome.as_str().to_string(),
artifact_name: default_assertion_artifact_name(assertion.assertion_id).to_string(),
})
.collect(),
attached_artifacts: evidence
.artifacts
.iter()
.map(|artifact| EvidenceArtifactRef {
artifact_name: artifact.artifact_ref.to_string(),
media_type: artifact.media_type,
role: artifact.artifact_role,
})
.collect(),
replay_payload: RestartRequeryReplayPayload {
replay_bundle_artifact_name: report.replay_bundle_artifact_name,
scenario_manifest_summary: report.scenario_manifest_summary,
trace_operation: report.trace_operation,
trace_id: report.trace_id,
span_id: report.span_id,
correlation_id: report.correlation_id,
reproduction_commands: vec![
evidence.replay.reproduction_entrypoint.to_string(),
"cargo test --release --test storage_paths integration_embedded_driver_plexus_restart_round_trip -- --exact"
.to_string(),
"cargo test features::runtime::api::tests::plexus_paths::execute_serialized_plan_rejects_unsupported_op_capability -- --exact"
.to_string(),
],
},
}
}
fn canonical_restart_requery_evidence(
commit_or_version: &str,
) -> assurance_api::RestartRequeryEvidence<'static> {
let commit = Box::leak(commit_or_version.to_string().into_boxed_str());
assurance_api::RestartRequeryEvidence::new(
assurance_api::WorkloadIdentity::new(
"embedded-restart-requery",
"canonical-fixture-v1",
"plexus-serialized-plan",
"embedded-evaluator",
),
assurance_api::EvidenceEnvelope::new(
"acceptance-gate",
"canonical-fixture-v1",
commit,
"embedded-evaluator",
assurance_api::EvidenceLevel::ReleaseBlocking,
),
vec![
assurance_api::AssertionRecord::new(
"restart-recovery",
"Storage WAL recovery succeeds after reopen.",
assurance_api::ScenarioOutcome::Pass,
"exit_code=0",
"exit_code=0",
),
assurance_api::AssertionRecord::new(
"restart-requery-consistency",
"Embedded Plexus execution returns the same rows before and after restart.",
assurance_api::ScenarioOutcome::Pass,
"row_set=stable",
"row_set=stable",
),
assurance_api::AssertionRecord::new(
"capability-rejection",
"Unsupported Plexus plan capability is rejected deterministically.",
assurance_api::ScenarioOutcome::Pass,
"rejected=unsupported-capability",
"rejected=unsupported-capability",
),
],
vec![
assurance_api::AttachedArtifact::new(
"durability-report",
"durability_verification_report.json",
"application/json",
),
assurance_api::AttachedArtifact::new(
"durability-summary",
"durability_verification_report.md",
"text/markdown",
),
assurance_api::AttachedArtifact::new(
"assertion-log",
"durability_restart_recovery.log",
"text/plain",
),
assurance_api::AttachedArtifact::new(
"assertion-log",
"durability_restart_requery.log",
"text/plain",
),
assurance_api::AttachedArtifact::new(
"assertion-log",
"durability_capability_rejection.log",
"text/plain",
),
assurance_api::AttachedArtifact::new(
"replay-bundle",
Box::leak(
assurance_api::ReplayBundle::new(
"embedded-restart-requery",
"canonical-fixture-v1",
commit,
"embedded-evaluator",
)
.artifact_name()
.into_boxed_str(),
),
"application/json",
),
],
assurance_api::ReplayPayload::new(
"embedded-restart-requery",
assurance_api::ReplayBundle::new(
"embedded-restart-requery",
"canonical-fixture-v1",
commit,
"embedded-evaluator",
),
"cargo test --release --test storage_paths integration_wal_recovery_path -- --exact",
"embedded-evaluator",
),
)
}
fn default_assertion_artifact_name(assertion_id: &str) -> &'static str {
match assertion_id {
"restart-recovery" => "durability_restart_recovery.log",
"restart-requery-consistency" => "durability_restart_requery.log",
"capability-rejection" => "durability_capability_rejection.log",
_ => "unknown.log",
}
}