Skip to main content

label_diagnostics

Function label_diagnostics 

Source
pub fn label_diagnostics(root: &Path) -> Vec<Diagnostic>
Expand description

Every version label typed into hand-written prose outside a declared history, and every history entry that cannot be honoured.

The label is the finding, not the version: v0.1 on a page that describes the tool as it stands was true the day it was typed and is wrong the day after the next release, while nothing that derives the version can reach it. A document that is about a past version names it in LABEL_HISTORY with a reason. That list is held from both sides: an entry with no reason, one naming a path that is not tracked prose, and one whose document no longer carries a label are each refused, so the list cannot outlive what it exempts.

use majordomus_cli::release::version::{label_diagnostics, LABEL_HISTORY};
use std::process::Command;
let dir = tempfile::tempdir().unwrap();
let root = dir.path();
std::fs::create_dir_all(root.join("docs")).unwrap();
std::fs::create_dir_all(root.join(".ai/repo")).unwrap();
std::fs::write(root.join("README.md"), "What v0.1 does not do.\nRelease v0.3.1 shipped.\n").unwrap();
std::fs::write(root.join("docs/DESIGN.md"), "The v0.1 specification.\n").unwrap();
std::fs::write(root.join(LABEL_HISTORY), "docs/DESIGN.md the design phase, dated\n").unwrap();
let git = |a: &[&str]| {
    Command::new("git")
        .env_remove("GIT_DIR").env_remove("GIT_WORK_TREE").env_remove("GIT_INDEX_FILE")
        .arg("-C").arg(root).args(a).output().unwrap()
};
git(&["init", "-q"]);
git(&["add", "-A"]);
let found = label_diagnostics(root);
assert_eq!(found.len(), 1, "{found:?}");
assert!(found[0].message.starts_with("README.md:1 "), "{}", found[0].message);

std::fs::write(root.join("docs/DESIGN.md"), "The founding specification.\n").unwrap();
let found = label_diagnostics(root);
assert_eq!(found[1].id, "version-label-history-invalid", "an exemption outliving its label");