xtask: a test packages the real web-font list and checks every served face, Gujarati included

With a craft-fonts checkout in CRAFT_FONTS_DIR, the Trunk hook runs on crates/text/web-fonts.txt
into a temporary site, and every startup and demand face must be under fonts/ui/ with the bytes
the craft-fonts manifest hashes. It skips without a checkout unless CRAFT_FONTS_REQUIRED=1.
This commit is contained in:
ruchirguitar committed 2026-12-03 21:32:54 +05:30
1 parent f3348a6502
commit 4fd3d9f22d
1 file changed
+33
+33
View File
@@ -218,6 +218,39 @@ mod tests {
assert!(at.join("LICENSE.txt").exists() && !at.join("LICENSE.html").exists());
}
/// The real hook on the real list: every `startup` and `demand` face (Gujarati included) lands
/// in the packaged site under `fonts/ui/`, byte for byte the file the craft-fonts manifest
/// hashes. Needs a craft-fonts checkout in `CRAFT_FONTS_DIR`; skips without one unless
/// `CRAFT_FONTS_REQUIRED=1`.
#[test]
fn the_packaged_site_serves_every_interface_face_as_the_manifest_hashes_it() {
let root = Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap();
let Some(dir) = std::env::var_os("CRAFT_FONTS_DIR").filter(|v| !v.is_empty()).map(PathBuf::from) else {
assert!(std::env::var("CRAFT_FONTS_REQUIRED").as_deref() != Ok("1"), "CRAFT_FONTS_REQUIRED=1 but CRAFT_FONTS_DIR is unset");
eprintln!("skipping: set CRAFT_FONTS_DIR to a craft-fonts checkout");
return;
};
let dir = if dir.is_absolute() { dir } else { root.join(dir) };
let site = tempfile::tempdir().unwrap();
run_with(root, Some(dir.clone()), Some(site.path().to_path_buf())).unwrap();
let list = std::fs::read_to_string(root.join("crates/text/web-fonts.txt")).unwrap();
let manifest = std::fs::read_to_string(dir.join("fonts/manifest.txt")).unwrap();
let mut checked = Vec::new();
for e in list::parse_list(&list).unwrap().into_iter().filter(|e| e.startup || e.demand) {
let row = manifest
.lines()
.map(|l| l.split(" | ").map(str::trim).collect::<Vec<_>>())
.find(|r| r.first() == Some(&e.family) && r.get(1) == Some(&e.style));
let Some(row) = row else { continue }; // an older craft-fonts lacks it; build.rs skips it too
let file = row[2].strip_prefix("fonts/").unwrap();
let bytes = std::fs::read(site.path().join(SERVED_URL).join(file)).unwrap_or_else(|err| panic!("{SERVED_URL}{file}: {err}"));
assert_eq!(sha256::hex(&bytes), row[6], "{SERVED_URL}{file} differs from the manifest");
checked.push(e.family.to_owned());
}
assert!(checked.iter().any(|f| f == "Noto Sans Gujarati"), "the Gujarati face was not published: {checked:?}");
}
#[test]
fn without_craft_fonts_the_hook_does_nothing() {
let (_, _, site, _) = fixture("noop", None);