use cotton_core::definitions::{revision::content_hash, BUILTIN_DEFINITIONS_HASH}; use std::{fs, path::Path}; fn collect(root: &Path, dir: &Path, files: &mut Vec<(String, Vec)>) { for entry in fs::read_dir(dir).unwrap() { let path = entry.unwrap().path(); if path.is_dir() { collect(root, &path, files); } else if path .extension() .is_some_and(|extension| extension == "json") { files.push(( path.strip_prefix(root) .unwrap() .to_str() .unwrap() .replace('\\', "/"), fs::read(path).unwrap(), )); } } } /// RULE: The compiled definitions revision hashes every kits path and byte (`kits/` is every app's /// kit plus the shell, exactly what build.rs hashes), so a changed or added definition is visible /// without a committed bump or a file inventory to maintain. #[test] fn compiled_revision_matches_definition_content() { let crate_dir = std::env::var_os("CARGO_MANIFEST_DIR").map(std::path::PathBuf::from).expect("cargo sets the runtime manifest directory"); let mut files = Vec::new(); let kit = crate_dir.join("kits"); collect(&kit, &kit, &mut files); files.sort(); assert_eq!( BUILTIN_DEFINITIONS_HASH, content_hash(files.iter().map(|(p, b)| (p.as_str(), b.as_slice()))) ); files.push(("synthetic-new-definition.json".into(), b"{}".to_vec())); assert_ne!( BUILTIN_DEFINITIONS_HASH, content_hash(files.iter().map(|(p, b)| (p.as_str(), b.as_slice()))) ); }