chain-module-sdk-rust/crates/chain-module-sdk/tests/wit_freeze.rs
flemming-it 98e98e9371
Some checks failed
CI / Linux x86_64 (Forgejo) (push) Failing after 2s
refactor: rename crate fai-module-sdk -> chain-module-sdk
The SDK is product-scoped (Ch∆In's module SDK), not a generic vendor
crate — a future Brain SDK would collide. Crate + macros renamed to
chain-module-sdk[-macros]; repo + dir follow.

Signed-off-by: flemming-it <sf@flemming.it>
2026-06-16 11:26:37 +02:00

53 lines
1.9 KiB
Rust

//! 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/platform :: crates/fai_runtime/tests/wit_freeze.rs.
/// Update both repos in lockstep, never one alone.
const PLATFORM_FROZEN_WIT_SHA256: &str =
"6f4e2266a4264832a16fe5a3704622cd978b290b90f3300c3ed236d98b689b5f";
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"
);
}