- 1
//! The supported baseline, and the one message that refuses anything older. - 2
//! - 3
//! `AGENTS.md` invariant 29: state written before [`BASELINE`] is refused, - 4
//! never partially read and never migrated. Every caller that can tell it is - 5
//! looking at pre-baseline state renders [`refusal`] rather than inventing - 6
//! its own wording — one message means an operator learns the remedy once. - 7
- 8
/// The oldest version whose on-disk state this build will accept. - 9
pub const BASELINE: &str = "2.0.0"; - 10
- 11
/// True when `version` predates [`BASELINE`]. An unparseable version is - 12
/// treated as pre-baseline: every build from the baseline onward stamps a - 13
/// semver string, so anything else was written by something older. - 14
pub fn is_pre_baseline(version: &str) -> bool { - 15
let Ok(found) = semver::Version::parse(version.trim().trim_start_matches('v')) else { - 16
return true; - 17
}; - 18
let Ok(baseline) = semver::Version::parse(BASELINE) else { - 19
return false; - 20
}; - 21
found < baseline - 22
} - 23
- 24
/// The refusal an operator reads. `what` names the artifact ("this data", - 25
/// "the install manifest") so the sentence stays specific without each - 26
/// caller rewriting the remedy. - 27
pub fn refusal(what: &str, found_version: &str) -> String { - 28
let found = found_version.trim(); - 29
let found = if found.is_empty() { - 30
"an unknown version" - 31
} else { - 32
found - 33
}; - 34
format!( - 35
"{what} was written by vak {found}, which predates the {BASELINE} baseline.\n\ - 36
Versions before {BASELINE} are not supported and cannot be upgraded in place.\n\ - 37
\n \ - 38
vak self uninstall --purge then install {BASELINE} and run setup\n\ - 39
\n\ - 40
Your project files are untouched; only vak's own state is removed." - 41
) - 42
} - 43
- 44
#[cfg(test)] - 45
#[allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)] - 46
mod tests { - 47
use super::*; - 48
- 49
#[test] - 50
fn versions_below_the_baseline_are_refused() { - 51
assert!(is_pre_baseline("1.0.3")); - 52
assert!(is_pre_baseline("0.11.51")); - 53
assert!(is_pre_baseline("v1.9.9")); - 54
} - 55
- 56
#[test] - 57
fn the_baseline_and_anything_above_it_is_accepted() { - 58
assert!(!is_pre_baseline(BASELINE)); - 59
assert!(!is_pre_baseline("2.0.1")); - 60
assert!(!is_pre_baseline("3.0.0")); - 61
} - 62
- 63
#[test] - 64
fn an_unreadable_version_is_pre_baseline_not_trusted() { - 65
// Every build from the baseline on stamps semver, so a stamp we - 66
// cannot parse was written by something older -- failing closed - 67
// here is what keeps a corrupt or ancient file from being read. - 68
assert!(is_pre_baseline("")); - 69
assert!(is_pre_baseline("not-a-version")); - 70
} - 71
- 72
#[test] - 73
fn the_refusal_names_the_artifact_the_version_and_the_remedy() { - 74
let msg = refusal("The install manifest", "1.0.3"); - 75
assert!(msg.contains("The install manifest")); - 76
assert!(msg.contains("1.0.3")); - 77
assert!(msg.contains(BASELINE)); - 78
assert!(msg.contains("vak self uninstall --purge")); - 79
assert!(msg.contains("Your project files are untouched")); - 80
} - 81
} - 82
Indexing the workspace…
Vakyartha documentation is discovering safe artifacts, anchors, and source references.