//! The Worker's catalogue and definition keys are generated from this crate //! (`pnpm rules:catalogue`, which runs this test with //! COTTON_WRITE_OBJECT_CATALOGUE=1). Without it, a checked-in file that has //! drifted from the Rust fails here: the Rust is the one source. use cotton_tools::mcp::object_catalogue::{definition_keys_json, object_catalogue_json, pretty}; fn held(relative: &str, generated: String) { let path = std::path::Path::new(&std::env::var("CARGO_MANIFEST_DIR").expect("cargo sets CARGO_MANIFEST_DIR")).join("../..").join(relative); if std::env::var_os("COTTON_WRITE_OBJECT_CATALOGUE").is_some() { std::fs::write(&path, &generated).unwrap_or_else(|error| panic!("cannot write {relative}: {error}")); return; } let checked_in = std::fs::read_to_string(&path).unwrap_or_else(|error| panic!("cannot read {relative}: {error}")); assert!(checked_in == generated, "{relative} has drifted from the Rust: run pnpm rules:catalogue"); } #[test] fn the_workers_catalogue_is_the_rusts() { held("apps/business/src/mcp/catalogue.json", pretty(&object_catalogue_json())); } #[test] fn the_workers_definition_keys_are_the_rusts() { held("apps/business/src/definition_keys.json", pretty(&definition_keys_json())); }