diff --git a/crates/presentar-core/build.rs b/crates/presentar-core/build.rs index 3f65b9c..68fdd58 100644 --- a/crates/presentar-core/build.rs +++ b/crates/presentar-core/build.rs @@ -8,28 +8,58 @@ fn main() { let cdir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("contracts"); if let Ok(es) = std::fs::read_dir(&cdir) { #[derive(serde::Deserialize, Default)] - struct CY { #[serde(default)] equations: std::collections::BTreeMap } + struct CY { + #[serde(default)] + equations: std::collections::BTreeMap, + } #[derive(serde::Deserialize, Default)] - struct EY { #[serde(default)] preconditions: Vec, #[serde(default)] postconditions: Vec } + struct EY { + #[serde(default)] + preconditions: Vec, + #[serde(default)] + postconditions: Vec, + } let (mut tp, mut tq) = (0, 0); for e in es.flatten() { let p = e.path(); - if p.extension().and_then(|x| x.to_str()) != Some("yaml") { continue; } - if p.file_name().is_some_and(|n| n.to_string_lossy().contains("binding")) { continue; } + if p.extension().and_then(|x| x.to_str()) != Some("yaml") { + continue; + } + if p.file_name() + .is_some_and(|n| n.to_string_lossy().contains("binding")) + { + continue; + } println!("cargo:rerun-if-changed={}", p.display()); - let s = p.file_stem().and_then(|x| x.to_str()).unwrap_or("x").to_uppercase().replace('-', "_"); + let s = p + .file_stem() + .and_then(|x| x.to_str()) + .unwrap_or("x") + .to_uppercase() + .replace('-', "_"); if let Ok(c) = std::fs::read_to_string(&p) { if let Ok(y) = serde_yaml_ng::from_str::(&c) { for (n, eq) in &y.equations { - let k = format!("CONTRACT_{}_{}", s, n.to_uppercase().replace('-', "_")); + let k = + format!("CONTRACT_{}_{}", s, n.to_uppercase().replace('-', "_")); if !eq.preconditions.is_empty() { - println!("cargo:rustc-env={k}_PRE_COUNT={}", eq.preconditions.len()); - for (i, v) in eq.preconditions.iter().enumerate() { println!("cargo:rustc-env={k}_PRE_{i}={v}"); } + println!( + "cargo:rustc-env={k}_PRE_COUNT={}", + eq.preconditions.len() + ); + for (i, v) in eq.preconditions.iter().enumerate() { + println!("cargo:rustc-env={k}_PRE_{i}={v}"); + } tp += eq.preconditions.len(); } if !eq.postconditions.is_empty() { - println!("cargo:rustc-env={k}_POST_COUNT={}", eq.postconditions.len()); - for (i, v) in eq.postconditions.iter().enumerate() { println!("cargo:rustc-env={k}_POST_{i}={v}"); } + println!( + "cargo:rustc-env={k}_POST_COUNT={}", + eq.postconditions.len() + ); + for (i, v) in eq.postconditions.iter().enumerate() { + println!("cargo:rustc-env={k}_POST_{i}={v}"); + } tq += eq.postconditions.len(); } } diff --git a/crates/presentar-terminal/src/app_tests.rs b/crates/presentar-terminal/src/app_tests.rs index b58c7b3..bf688e4 100644 --- a/crates/presentar-terminal/src/app_tests.rs +++ b/crates/presentar-terminal/src/app_tests.rs @@ -1195,9 +1195,13 @@ fn test_testable_backend_enable_mouse_capture() { assert!(!backend.is_mouse_captured()); backend.enable_mouse_capture().unwrap(); assert!(backend.is_mouse_captured()); - // Verify escape sequence was written - let output = backend.into_writer(); - assert!(!output.is_empty()); + // Verify escape sequence was written (Unix only — on Windows, crossterm + // uses the Console API instead of writing ANSI escape sequences) + #[cfg(not(target_os = "windows"))] + { + let output = backend.into_writer(); + assert!(!output.is_empty()); + } } #[test] diff --git a/crates/presentar/tests/contract_traits.rs b/crates/presentar/tests/contract_traits.rs index bd61e82..0ac4a01 100644 --- a/crates/presentar/tests/contract_traits.rs +++ b/crates/presentar/tests/contract_traits.rs @@ -9,9 +9,9 @@ //! Run with: `cargo test --test contract_traits` use provable_contracts::traits::{ - ActivationKernelV1, AdamwKernelV1, AttentionKernelV1, CrossEntropyKernelV1, - FlashAttentionV1, GqaKernelV1, LayernormKernelV1, MatmulKernelV1, RmsnormKernelV1, - RopeKernelV1, SiluKernelV1, SoftmaxKernelV1, SwigluKernelV1, + ActivationKernelV1, AdamwKernelV1, AttentionKernelV1, CrossEntropyKernelV1, FlashAttentionV1, + GqaKernelV1, LayernormKernelV1, MatmulKernelV1, RmsnormKernelV1, RopeKernelV1, SiluKernelV1, + SoftmaxKernelV1, SwigluKernelV1, }; /// Marker struct for reference scalar kernel implementations. @@ -189,7 +189,10 @@ fn rmsnorm_kernel_v1_properties() { // out ≈ [3/3.5355, 4/3.5355] ≈ [0.8485, 1.1314] assert!(out.len() == 2); let rms_out = (out.iter().map(|v| v * v).sum::() / out.len() as f32).sqrt(); - assert!((rms_out - 1.0).abs() < 1e-3, "rmsnorm output should have ~unit RMS"); + assert!( + (rms_out - 1.0).abs() < 1e-3, + "rmsnorm output should have ~unit RMS" + ); } #[test] @@ -221,7 +224,10 @@ fn cross_entropy_kernel_v1_properties() { } // exp(log_softmax) should sum to 1 let sum_exp: f32 = lsm.iter().map(|v| v.exp()).sum(); - assert!((sum_exp - 1.0).abs() < 1e-5, "exp(log_softmax) must sum to 1"); + assert!( + (sum_exp - 1.0).abs() < 1e-5, + "exp(log_softmax) must sum to 1" + ); // cross_entropy with one-hot target let targets = vec![0.0, 0.0, 1.0];