//! Snapshot test for the WIT mirror. //! //! The SDK ships its own copy of `wit/world.wit` so the proc-macro //! can embed it via `include_str!` at compile time. The hash MUST //! match the platform's frozen v1.0 hash. If this test fails, the //! mirror has drifted and the SDK cannot guarantee binary //! compatibility with the platform. #![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)] use std::path::PathBuf; use sha2::{Digest, Sha256}; /// Identical to FROZEN_WIT_SHA256 in /// fai/chain :: crates/chain_runtime/tests/wit_freeze.rs. /// Update both repos in lockstep, never one alone. /// 2026-07-05 — WIT 1.0.0 → 1.1.0 (additive: host.emit-event). The SDK /// wit/world.wit is now byte-identical to the platform's, so the two /// frozen hashes match exactly. const PLATFORM_FROZEN_WIT_SHA256: &str = "2ba9d6c61c4c77d081679603a9389aef663429ec80f9c386cf9b1ca9d353bf6f"; fn world_wit_path() -> PathBuf { PathBuf::from(env!("CARGO_MANIFEST_DIR")) .parent() .expect("crates parent") .parent() .expect("workspace root") .join("wit") .join("world.wit") } #[test] fn wit_mirror_matches_platform_frozen_hash() { let path = world_wit_path(); let bytes = std::fs::read(&path).unwrap_or_else(|e| panic!("read {}: {e}", path.display())); let mut hasher = Sha256::new(); hasher.update(&bytes); let actual = format!("{:x}", hasher.finalize()); assert_eq!( actual, PLATFORM_FROZEN_WIT_SHA256, "\n\nwit/world.wit in this repo has drifted from the platform's\n\ frozen v1.0 hash. The SDK MUST mirror the platform exactly\n\ or modules built with this SDK will not be wire-compatible.\n\n\ If the platform intentionally bumped to a new minor (e.g.\n\ v1.1 with additive changes), update BOTH:\n\ 1. wit/world.wit here to match the platform copy\n\ 2. PLATFORM_FROZEN_WIT_SHA256 in this test\n\n\ If the platform is still on the old hash, revert this WIT\n\ change.\n\n\ actual hash: {actual}\n" ); }