sail_api/project.rs
1//! Managed workspace verification results, independently versioned from reports.
2
3use serde::{Deserialize, Serialize};
4
5use crate::output::Report;
6
7/// Current version of the managed project-result envelope.
8pub const SCHEMA_VERSION: u32 = 2;
9
10/// A complete invocation of managed Cargo verification.
11#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12pub struct ProjectResult {
13 /// Document discriminator, always `sail-project-result`.
14 pub kind: String,
15 /// Envelope version; embedded reports retain their own schema version.
16 pub schema_version: u32,
17 /// Unique establishing invocation identifier.
18 pub run_id: String,
19 /// Canonical Cargo workspace root.
20 pub workspace: String,
21 /// Verification configuration and executable identity digest.
22 pub context_sha256: String,
23 /// Content digest of the declared input revision when the run started.
24 pub input_revision: String,
25 /// Whether inputs remained unchanged while the invocation ran.
26 pub currentness: Currentness,
27 /// Cargo-Verus process exit status, absent on signal termination.
28 pub exit_code: Option<i32>,
29 /// Reports for every selected verification target observed by Cargo.
30 pub targets: Vec<TargetResult>,
31 /// Measurements of this invocation, never replayed historical counters.
32 pub execution: Execution,
33 /// Coverage limitations or recovery notes.
34 pub notes: Vec<String>,
35 /// Setup or infrastructure failure, never a solver verdict.
36 pub error: Option<crate::output::ErrorInfo>,
37 /// Explicitly selected source engine (ADR 0027); absent for stock runs.
38 /// Each target report records whether the engine or its stock fallback
39 /// established it.
40 #[serde(default, skip_serializing_if = "Option::is_none")]
41 pub engine: Option<EngineIdentity>,
42 /// Present when Sail could not bind this invocation's setup to a proof
43 /// receipt (`SAIL3112`, ADR 0046). Such a run reuses and records no proof
44 /// receipts, and its result is never `current`. Absent for runs that
45 /// can reuse proofs.
46 #[serde(default, skip_serializing_if = "Option::is_none")]
47 pub no_reuse: Option<NoReuse>,
48}
49
50/// Name of the one target of a run verified as plain `cargo verus verify`
51/// ([`VerifiedAs::PlainCargoVerus`]): its report covers the whole run.
52pub const PLAIN_TARGET: &str = "cargo verus verify";
53
54/// Why and how a run was verified without proof reuse (`SAIL3112`).
55#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
56pub struct NoReuse {
57 /// Always `SAIL3112`.
58 pub code: String,
59 /// The setup Sail could not bind to a proof receipt.
60 pub reason: String,
61 /// How the run was verified.
62 pub verified_as: VerifiedAs,
63}
64
65/// How a run without proof reuse was verified.
66#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
67#[serde(rename_all = "kebab-case")]
68pub enum VerifiedAs {
69 /// Exactly as plain `cargo verus verify` verifies it, in the invocation's
70 /// own Cargo target, with Sail's solver cache. `targets` holds one
71 /// requested target named [`PLAIN_TARGET`] whose report covers every
72 /// crate Verus verified; a crate Cargo found up to date has no report.
73 /// `context_sha256` and `input_revision` are empty.
74 PlainCargoVerus,
75 /// By managed verification in Sail's own target, with per-target
76 /// reports (a process-loader variable is set).
77 Managed,
78}
79
80/// The validated source engine of a project run.
81#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
82pub struct EngineIdentity {
83 /// The engine name (`interactive`).
84 pub name: String,
85 /// SHA-256 of the validated engine build manifest, as lowercase hex.
86 pub manifest_sha256: String,
87}
88
89/// Relationship of a result to the workspace's current declared inputs.
90#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
91#[serde(rename_all = "kebab-case")]
92pub enum Currentness {
93 /// Declared inputs did not change during verification.
94 Current,
95 /// Inputs changed; the establishing result is historical.
96 Historical,
97 /// Input coverage could not be established.
98 Unknown,
99}
100
101/// Where a compiler-boundary dependency proof was established.
102#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
103#[serde(rename_all = "kebab-case")]
104pub enum DependencyBuildKind {
105 /// A verified dependency packaged with a release.
106 Release,
107 /// An earlier full verification on this machine, after fresh native compilation.
108 MachineLocal,
109}
110
111/// Provenance retained when a dependency invocation replays a complete proof.
112#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
113pub struct DependencyBuildOrigin {
114 /// Scope of the dependency build.
115 pub kind: DependencyBuildKind,
116 /// Runtime identity and exact compiler-boundary entry key.
117 pub identity: String,
118 /// Invocation which actually established the proof, rather than its replay.
119 pub establishing_run: String,
120}
121
122/// One Cargo target's proof report, with an explicit establishing invocation.
123#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
124pub struct TargetResult {
125 /// Cargo's package ID, including version and source.
126 pub package_id: String,
127 /// Cargo target name.
128 pub target: String,
129 /// Target kind (`lib`, `bin`, and so on).
130 pub kind: Vec<String>,
131 /// Invocation which actually established the embedded report. A shipped
132 /// proof uses the nonlocal namespace `shipped:<build identity>/<entry key>`;
133 /// it does not name a local replay run.
134 pub establishing_run: String,
135 /// True when Cargo's fresh artifact and its complete proof receipt matched.
136 pub reused: bool,
137 /// Exact invocation arguments when an unchanged partial-scope report was
138 /// reused. This never establishes a complete target proof and does not
139 /// contribute to `Execution::reused_targets`.
140 #[serde(default, skip_serializing_if = "Option::is_none")]
141 pub scope_reuse: Option<Vec<String>>,
142 /// True for an explicitly selected verification target; false for dependencies.
143 #[serde(default)]
144 pub requested: bool,
145 /// True only for successful, complete target verification.
146 pub complete: bool,
147 /// Original report; its timing and provenance belong to `establishing_run`.
148 pub report: Report,
149 /// Set when this run placed the target's compiled, verified artifacts in a
150 /// new Cargo target from Sail's dependency store (ADR 0045): the key of the
151 /// store entry. Plain Cargo-Verus would have verified this dependency in
152 /// this invocation, so a renderer that reproduces plain output prints its
153 /// recorded result here. `establishing_run` names the run, in another
154 /// workspace, that verified it.
155 #[serde(default, skip_serializing_if = "Option::is_none")]
156 pub dependency_store: Option<String>,
157 /// Origin of a replayed dependency proof (ADR 0048), preserved through
158 /// later receipt reuse. Native prerequisites execute before boundary lookup.
159 #[serde(default, skip_serializing_if = "Option::is_none")]
160 pub dependency_build: Option<DependencyBuildOrigin>,
161}
162
163/// Current invocation's execution counters.
164#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
165pub struct Execution {
166 /// Number of target verification subprocesses started in this invocation.
167 /// For [`VerifiedAs::PlainCargoVerus`], this counts the one aggregate
168 /// Cargo-Verus driver result, even if Cargo verifies zero or several crates;
169 /// it is zero when setup or the driver fails without an aggregate result.
170 /// It does not measure per-crate verifier or solver work in that mode.
171 pub verifier_invocations: u64,
172 /// Number of targets whose reports were reused from complete receipts.
173 pub reused_targets: u64,
174 /// Total wall-clock time including Cargo and input validation.
175 pub wall_ms: f64,
176}
177
178#[cfg(test)]
179mod tests {
180 use super::{NoReuse, VerifiedAs};
181
182 /// `no_reuse` matches its JSON Schema, and the schema refuses a
183 /// document that drops how the run was verified.
184 #[test]
185 fn no_reuse_matches_its_schema() {
186 let schema: serde_json::Value =
187 serde_json::from_str(include_str!("../schema/project-result-v2.json"))
188 .unwrap_or_default();
189 let schema = &schema["properties"]["no_reuse"];
190 for verified_as in [VerifiedAs::PlainCargoVerus, VerifiedAs::Managed] {
191 let value = serde_json::to_value(NoReuse {
192 code: "SAIL3112".to_owned(),
193 reason: "`--tests` is not bound to a proof receipt".to_owned(),
194 verified_as,
195 })
196 .unwrap_or_default();
197 assert_eq!(
198 crate::schema::validate(schema, &value),
199 Vec::<String>::new()
200 );
201 let mut missing = value.clone();
202 if let Some(object) = missing.as_object_mut() {
203 object.remove("verified_as");
204 }
205 assert_ne!(
206 crate::schema::validate(schema, &missing),
207 Vec::<String>::new()
208 );
209 }
210 assert_eq!(
211 serde_json::to_value(VerifiedAs::PlainCargoVerus).ok(),
212 Some(serde_json::json!("plain-cargo-verus"))
213 );
214 }
215}