diff --git a/xtask/src/web_fonts.rs b/xtask/src/web_fonts.rs index d30ef58c8e..8ce093bd2b 100644 --- a/xtask/src/web_fonts.rs +++ b/xtask/src/web_fonts.rs @@ -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::>()) + .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);