Some checks failed
CI / Linux x86_64 (Forgejo) (push) Failing after 1s
Brings the module SDK to WIT 1.1 in lockstep with the platform and
exposes the new host.emit-event as an ergonomic ctx.emit(name,
payload). Modules emit ephemeral progress/stream events (progress,
token streaming) delivered live to a following client and never
persisted.
- wit/world.wit → 1.1.0 (host.emit-event + use types.{payload}).
- host.rs: an emit hook (thread-local fn pointer; guest is
single-threaded). The #[fai_module] expansion installs a closure
reaching the real WIT emit-event import at the start of each
invocation; Context::emit calls through it. Outside a hub (unit
tests) it is a silent no-op.
- examples/progress: reference module emitting progress + token events;
builds clean for wasm32-wasip2, proving the ergonomics end-to-end.
The SDK keeps shielding module authors: emit is the whole surface, no
wit_bindgen in sight.
Signed-off-by: flemming-it <sf@flemming.it>
56 lines
2.1 KiB
Rust
56 lines
2.1 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/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"
|
|
);
|
|
}
|