sail_api/repair.rs
1//! Focused repair checks and complete validation.
2//!
3//! Explanations, baselines and comparisons are in [`crate::evidence`].
4
5use serde::{Deserialize, Serialize};
6
7use crate::project::ProjectResult;
8
9/// Independent repair contract version.
10pub const VERSION: u32 = 1;
11
12/// Source-engine batch output; each phase retains its independent proof report.
13#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14pub struct BatchResult {
15 /// Complete selected-function phase, absent if it did not produce evidence.
16 pub focus: Option<ProjectResult>,
17 /// Independent complete requested-target phase. A standalone repair
18 /// document (the repair worker's output, `sail repair-check --output json`)
19 /// carries it. A job result omits it: the job's `result` is this phase,
20 /// so readers receive the graph once.
21 #[serde(default, skip_serializing_if = "Option::is_none")]
22 pub full: Option<ProjectResult>,
23 /// Hash of the validated optional engine build manifest.
24 pub manifest_sha256: String,
25 /// Number of Verus driver subprocesses actually started by this batch.
26 /// An engine batch can run ghost verification and final executable checks
27 /// inside one driver; this is not the number of internal Rust sessions.
28 pub compiler_invocations: u64,
29 /// True only for engine-supported focus/full batching within compiler calls.
30 pub batched: bool,
31 /// Exact focus selection was unavailable or ambiguous; full evidence is retained.
32 #[serde(default, skip_serializing_if = "Option::is_none")]
33 pub selection_error: Option<crate::output::ErrorInfo>,
34 /// The engine faulted before any target could fall back individually
35 /// (ADR 0027). `full` is then an independent stock verification, retained
36 /// as evidence; it never accepts the repair.
37 #[serde(default, skip_serializing_if = "Option::is_none")]
38 pub engine_fault: Option<crate::output::ErrorInfo>,
39}
40
41impl BatchResult {
42 /// Whether selection succeeded and full validation established current complete evidence.
43 /// Preliminary focus success cannot authorize a repair, and neither can a
44 /// stock fallback after an engine fault. Without a full phase, false.
45 #[must_use]
46 pub fn accepted(&self) -> bool {
47 self.full
48 .as_ref()
49 .is_some_and(|full| self.accepted_with(full))
50 }
51
52 /// [`Self::accepted`] with the full phase supplied separately, as in a job
53 /// result whose `result` holds it.
54 #[must_use]
55 pub fn accepted_with(&self, full: &ProjectResult) -> bool {
56 self.selection_error.is_none() && self.engine_fault.is_none() && accepted(full)
57 }
58}
59
60/// Whether an independently completed full report authorizes a repair.
61///
62/// Summary counts are derived evidence, not acceptance authority: the report
63/// must be internally consistent and every function must be confirmed verified.
64#[must_use]
65pub fn accepted(full: &ProjectResult) -> bool {
66 crate::acceptance::complete_selection(full).is_some()
67}
68
69/// Explicit selected target/function; never guessed from semantic dependencies.
70#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
71pub struct Selection {
72 /// Cargo package selection.
73 pub package: String,
74 /// Explicit binary name; library selection is unique within the package.
75 pub target: Option<String>,
76 /// `lib` or `bin`; target names alone are ambiguous.
77 pub kind: String,
78 /// Exact crate-qualified function identifier as reported by Verus.
79 pub function: String,
80}
81
82/// Repair submission uses the existing environment/revision request contract.
83#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
84pub struct Submission {
85 /// Verification context, arguments and originating environment.
86 pub verification: crate::jobs::Submission,
87 /// Explicit target/function selection.
88 pub selection: Selection,
89}
90
91/// Finished repair response; accepted is derived rather than trusted from storage.
92#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
93pub struct ResultDocument {
94 /// Independent contract version.
95 pub version: u32,
96 /// Complete phase evidence.
97 pub batch: BatchResult,
98 /// Derived from successful selection and the independently finalized full report.
99 pub accepted: bool,
100}
101
102impl From<BatchResult> for ResultDocument {
103 fn from(batch: BatchResult) -> Self {
104 Self {
105 version: VERSION,
106 accepted: batch.accepted(),
107 batch,
108 }
109 }
110}