use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "lowercase")]
pub enum AnnotationKind {
Intent,
Assume,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "kebab-case")]
pub enum Status {
Verified,
Tested,
Neural,
Stale,
Orphan,
Forged,
Unknown,
PendingDeepen,
Counterexample,
Inconclusive,
}
#[aristo::intent(
"The terminal-clean states are exactly Verified, Tested, and Neural — \
an intent whose current code IS confirmed to hold under some \
verification method. Stale, Counterexample, Inconclusive, Unknown, \
and the B5b error states (Orphan / Forged / PendingDeepen) are NOT \
clean: each means the property is unproven, refuted, or untrusted for \
the current code. This is the single definition every surface — \
status counts, the badge rate, and the nudge engine's unverified \
backlog — shares, so they can never disagree on what 'verified' means.",
verify = "test",
id = "status_terminal_clean_is_verified_tested_neural"
)]
impl Status {
pub fn is_terminal_clean(self) -> bool {
matches!(self, Status::Verified | Status::Tested | Status::Neural)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
#[serde(untagged)]
pub enum VerifyLevel {
Bool(bool),
Method(VerifyMethod),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "lowercase")]
pub enum VerifyMethod {
Neural,
Test,
Full,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum CoveredRegion {
Function,
Statement,
ImplMethods,
ModuleInlineBody,
Type,
Field,
Crate,
Trait,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn annotation_kind_round_trips_lowercase() {
let v = serde_json::to_value(AnnotationKind::Intent).unwrap();
assert_eq!(v, serde_json::json!("intent"));
let back: AnnotationKind = serde_json::from_value(v).unwrap();
assert_eq!(back, AnnotationKind::Intent);
}
#[test]
fn status_pending_deepen_is_kebab_case() {
let v = serde_json::to_value(Status::PendingDeepen).unwrap();
assert_eq!(v, serde_json::json!("pending-deepen"));
let back: Status = serde_json::from_value(serde_json::json!("pending-deepen")).unwrap();
assert_eq!(back, Status::PendingDeepen);
}
#[test]
fn verify_level_accepts_bool_form() {
let level: VerifyLevel = serde_json::from_value(serde_json::json!(false)).unwrap();
assert_eq!(level, VerifyLevel::Bool(false));
let level: VerifyLevel = serde_json::from_value(serde_json::json!(true)).unwrap();
assert_eq!(level, VerifyLevel::Bool(true));
}
#[test]
fn verify_level_accepts_named_method_form() {
let level: VerifyLevel = serde_json::from_value(serde_json::json!("full")).unwrap();
assert_eq!(level, VerifyLevel::Method(VerifyMethod::Full));
}
#[test]
fn verify_level_rejects_unknown_string() {
let result: Result<VerifyLevel, _> = serde_json::from_value(serde_json::json!("partial"));
assert!(result.is_err());
}
#[test]
fn covered_region_uses_snake_case() {
let v = serde_json::to_value(CoveredRegion::ImplMethods).unwrap();
assert_eq!(v, serde_json::json!("impl_methods"));
let v = serde_json::to_value(CoveredRegion::ModuleInlineBody).unwrap();
assert_eq!(v, serde_json::json!("module_inline_body"));
}
#[test]
fn unknown_status_value_is_rejected() {
let result: Result<Status, _> = serde_json::from_value(serde_json::json!("partial"));
assert!(result.is_err());
}
#[test]
fn terminal_clean_is_exactly_verified_tested_neural() {
for s in [Status::Verified, Status::Tested, Status::Neural] {
assert!(s.is_terminal_clean(), "{s:?} should be terminal-clean");
}
for s in [
Status::Stale,
Status::Orphan,
Status::Forged,
Status::Unknown,
Status::PendingDeepen,
Status::Counterexample,
Status::Inconclusive,
] {
assert!(!s.is_terminal_clean(), "{s:?} must NOT be terminal-clean");
}
}
}