//! The resource caps and the stable-id acceptance of the curation inputs (R5.5 adjustments of //! R5.4, owner 2026-10-23 §3 and §6): an authored file over 4 MiB is refused by name before any //! parse allocation, the committed files keep a wide margin, and the stable-id grammar the //! applier enforces is the sheet contract's, not an equine list. #![allow(clippy::disallowed_methods, clippy::unwrap_used, clippy::expect_used)] use faunosteo_core::curation::draft::schema::MAX_CURATION_FILE_BYTES; use faunosteo_core::curation::draft::{parse_changeset, parse_references}; use faunosteo_core::domain::js::is_stable_id; const CURATION: &str = "../../supabase/seed/anatomical-sheets/equine/curation"; fn committed(name: &str) -> String { std::fs::read_to_string(format!("{CURATION}/{name}")).unwrap() } /// A valid-looking JSON text of exactly `len` bytes (spaces pad the tail). fn padded(len: usize) -> String { let mut text = String::from("{\"changes\":[]}"); text.push_str(&" ".repeat(len - text.len())); text } #[test] fn committed_files_keep_a_wide_margin_under_the_cap() { for name in ["changes.json", "references.json"] { let size = committed(name).len(); assert!(size * 10 < MAX_CURATION_FILE_BYTES, "{name}: {size} bytes"); } } #[test] fn a_file_over_the_cap_is_refused_by_name_before_the_parse() { let over = padded(MAX_CURATION_FILE_BYTES + 1); let changes = parse_changeset(&over).unwrap_err().to_string(); assert!( changes.starts_with("changes.json: larger than "), "{changes}" ); let references = parse_references(&over).unwrap_err().to_string(); assert!( references.starts_with("references.json: larger than "), "{references}" ); } #[test] fn a_file_at_the_cap_reaches_the_parser() { let at = padded(MAX_CURATION_FILE_BYTES); assert!(parse_changeset(&at).is_ok()); } #[test] fn stable_ids_of_any_species_are_accepted_and_the_rest_refused() { for id in [ "canine-skull", "feline_thorax-2", "0-bovine", "a", &"x".repeat(64), ] { assert!(is_stable_id(id), "{id}"); } for id in [ "", "Equine", "-x", "a b", "a/b", "a.b", "é", &"x".repeat(65), ] { assert!(!is_stable_id(id), "{id:?}"); } }