//! Conformance of the integrity rules (review III.4): the fixtures under //! `tests/conformance` carry what the TypeScript rules reported (frozen by //! `packages/domain/tests/r2-conformance.test.ts`). This suite checks the Rust //! rules against them. //! //! V1-2.1 (M5) removed the SQL business mirror (`private.sheet_document_*`): SQL //! no longer re-checks the document's business rules, the Rust core is the only //! authority (contract §12.2). The former `the_sql_expectations…` and //! `the_pgtap_file_is_generated…` tests and the generated //! `supabase/tests/011_sheet_conformance.sql` went with it; the fixtures' `sql` //! key is left in place, unused. #![allow(clippy::disallowed_methods, clippy::unwrap_used, clippy::expect_used)] mod common; use faunosteo_core::domain::js::parse_json; use faunosteo_core::domain::sheet::check_sheet_document; use serde_json::Value; fn fixtures() -> Vec<(String, Value)> { let dir = format!("{}/tests/conformance", env!("CARGO_MANIFEST_DIR")); let mut names: Vec = std::fs::read_dir(&dir) .unwrap() .map(|entry| entry.unwrap().file_name().into_string().unwrap()) .filter(|name| name.ends_with(".json")) .collect(); names.sort(); names .into_iter() .map(|name| { let text = common::repo_file(&format!("crates/core/tests/conformance/{name}")); (name, parse_json(&text).unwrap()) }) .collect() } #[test] fn the_rust_rules_report_what_the_typescript_rules_reported() { let all = fixtures(); assert!(all.len() >= 25, "every rule family has a fixture"); for (name, fixture) in all { let outcome = check_sheet_document(fixture["document"].clone()); if fixture["rust"]["shape_error"] == Value::Bool(true) { assert!(outcome.is_err(), "{name}: the shape tier must refuse it"); continue; } let check = outcome.unwrap_or_else(|e| panic!("{name}: {e}")); let issues = serde_json::to_value(&check.issues).unwrap(); assert_eq!(issues, fixture["rust"]["issues"], "{name}"); } }