use std::path::Path;
use std::process::Command;
fn workspace_root() -> std::path::PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR"))
.join("../..")
.canonicalize()
.unwrap()
}
fn read_readme() -> String {
std::fs::read_to_string(workspace_root().join("README.md"))
.expect("README.md must exist at workspace root")
}
#[test]
fn test_readme_has_install_command() {
let readme = read_readme();
assert!(
readme.contains("cargo install aprender"),
"FALSIFY-README-001: README.md must contain 'cargo install aprender'"
);
}
#[test]
fn test_readme_has_apr_run_example() {
let readme = read_readme();
assert!(
readme.contains("apr run"),
"FALSIFY-README-002: README.md must contain 'apr run' usage example"
);
}
#[test]
fn test_readme_no_apr_cli_install() {
let readme = read_readme();
assert!(
!readme.contains("cargo install apr-cli"),
"FALSIFY-README-003: README.md must not contain 'cargo install apr-cli'"
);
}
#[test]
fn test_readme_no_stale_install_refs() {
let readme = read_readme();
for old in &[
"cargo install trueno",
"cargo install realizar",
"cargo install entrenar",
"cargo install batuta",
] {
assert!(
!readme.contains(old),
"FALSIFY-README-004: README.md must not contain '{old}'"
);
}
}
#[test]
fn test_readme_crate_count_matches_workspace() {
let readme = read_readme();
let crates_dir = workspace_root().join("crates");
let crate_count = std::fs::read_dir(&crates_dir)
.expect("read crates/")
.filter_map(Result::ok)
.filter(|e| e.path().is_dir())
.count();
let count_str = format!("**{crate_count}**");
assert!(
readme.contains(&count_str),
"FALSIFY-README-005: README lacks `**{crate_count}**` matching `ls crates/`"
);
}
#[test]
fn test_hero_svg_accessible() {
let svg = std::fs::read_to_string(workspace_root().join("docs/hero.svg"))
.expect("docs/hero.svg must exist");
assert!(
svg.contains(r#"role="img""#),
"FALSIFY-SVG-002: hero.svg missing role=img"
);
assert!(
svg.contains("aria-label"),
"FALSIFY-SVG-002: hero.svg missing aria-label"
);
assert!(
svg.contains("<title>"),
"FALSIFY-SVG-002: hero.svg missing <title>"
);
}
#[test]
fn test_readme_has_framework_comparison() {
let readme = read_readme();
assert!(
readme.contains("candle-vs-apr"),
"README must cite paiml/candle-vs-apr for reproducible inference benchmarks"
);
assert!(
readme.contains("ground-truth-apr-ludwig"),
"README must cite paiml/ground-truth-apr-ludwig for reproducible training benchmarks"
);
}
#[test]
fn test_hero_svg_valid() {
let svg_path = workspace_root().join("docs/hero.svg");
let content = std::fs::read_to_string(&svg_path).expect("read hero.svg");
assert!(
content.trim().starts_with("<svg"),
"FALSIFY-SVG-003: not valid SVG"
);
assert!(
content.trim().ends_with("</svg>"),
"FALSIFY-SVG-003: not valid SVG"
);
}
#[test]
fn test_every_crate_has_readme() {
let ws_root = workspace_root();
let crates_dir = ws_root.join("crates");
let mut missing = Vec::new();
if let Ok(entries) = std::fs::read_dir(&crates_dir) {
for entry in entries.flatten() {
if !entry.path().join("Cargo.toml").exists() {
continue; }
if !entry.path().join("README.md").exists() {
missing.push(entry.file_name().to_string_lossy().to_string());
}
}
}
assert!(
missing.is_empty(),
"FALSIFY-README-CRATE-001: Crates missing README.md: {:?}",
missing
);
}
#[test]
fn test_every_readme_links_monorepo() {
let ws_root = workspace_root();
let crates_dir = ws_root.join("crates");
let mut no_link = Vec::new();
if let Ok(entries) = std::fs::read_dir(&crates_dir) {
for entry in entries.flatten() {
let readme = entry.path().join("README.md");
if !readme.exists() {
continue;
}
let content = std::fs::read_to_string(&readme).unwrap_or_default();
if !content.contains("paiml/aprender") {
no_link.push(entry.file_name().to_string_lossy().to_string());
}
}
}
assert!(
no_link.is_empty(),
"FALSIFY-README-CRATE-002: READMEs without monorepo link: {:?}",
no_link
);
}