Skip to main content

scan_prose

Function scan_prose 

Source
pub fn scan_prose(root: &Path) -> (usize, Vec<EconomicsFinding>)
Expand description

Scan the repository’s hand-written prose for unsupported quantities, and return how many files were read with every finding.

Only tracked files are read: the prose set comes from git ls-files. A root git cannot list is a scan_failed finding, not an empty and therefore clean scan; so is a tracked file that exists and cannot be read. A generated file is skipped and not counted, and “generated” is decided by provenance only: listed in docs/generated/artifacts.json, under site/data/generated/ or site/content/, or stamped by its generator on its first line. A quantity in a fenced code block is still a finding, and its detail says it is in one. In docs/CLAIMS.yaml, read whether tracked or not, only claim: and note: values count. Files are read paragraph by paragraph (prose_quantities).

use majordomus_cli::economics::claims::scan_prose;
use std::process::Command;
let dir = tempfile::tempdir().unwrap();
let root = dir.path();
std::fs::create_dir_all(root.join("docs/generated")).unwrap();
std::fs::write(root.join("README.md"), "Install it.\nIt saves 40% of tokens.\n").unwrap();
let stamp = "<!-- generated by majordomus economics -->\n";
std::fs::write(root.join("docs/generated/economics.md"), format!("{stamp}It saves 40% of tokens.\n")).unwrap();
std::fs::write(root.join("docs/generated/notes.md"), "It saves 40% of tokens.\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 (scanned, findings) = scan_prose(root);
assert_eq!(scanned, 2, "the stamped report is not hand-written prose");
let at: Vec<_> = findings.iter().map(|f| (f.path.as_str(), f.line)).collect();
assert_eq!(at, [("README.md", Some(2)), ("docs/generated/notes.md", Some(1))], "no stamp, no exemption");

let outside = tempfile::tempdir().unwrap();
let (_, findings) = scan_prose(outside.path());
assert_eq!(findings[0].kind, "scan_failed", "nothing listed is not nothing found");