diff --git a/.github/workflows/ci-rs.yml b/.github/workflows/ci-rs.yml index c5f6609b8..c6814fc60 100644 --- a/.github/workflows/ci-rs.yml +++ b/.github/workflows/ci-rs.yml @@ -19,6 +19,7 @@ env: CI: true # insta snapshots behave differently on ci SCCACHE_GHA_ENABLED: "true" RUSTC_WRAPPER: "sccache" + HUGR_TEST_SCHEMA: "1" # different strings for install action and feature name # adapted from https://github.com/TheDan64/inkwell/blob/master/.github/workflows/test.yml LLVM_VERSION: "14.0" diff --git a/hugr-core/src/envelope/package_json.rs b/hugr-core/src/envelope/package_json.rs index 6a2b62b75..3bc7fe748 100644 --- a/hugr-core/src/envelope/package_json.rs +++ b/hugr-core/src/envelope/package_json.rs @@ -51,6 +51,17 @@ pub(super) fn to_json_writer<'h>( modules: hugrs.into_iter().map(HugrSer).collect(), extensions: extensions.iter().map(std::convert::AsRef::as_ref).collect(), }; + + // Validate the hugr serializations against the schema. + #[cfg(all(test, not(miri)))] + if std::env::var("HUGR_TEST_SCHEMA").is_ok_and(|x| !x.is_empty()) { + use crate::hugr::serialize::test::check_hugr_serialization_schema; + + for hugr in &pkg_ser.modules { + check_hugr_serialization_schema(hugr.0); + } + } + serde_json::to_writer(writer, &pkg_ser)?; Ok(()) } diff --git a/hugr-core/src/hugr/serialize/test.rs b/hugr-core/src/hugr/serialize/test.rs index 2b500ed03..5b224b168 100644 --- a/hugr-core/src/hugr/serialize/test.rs +++ b/hugr-core/src/hugr/serialize/test.rs @@ -175,6 +175,18 @@ fn ser_roundtrip_check_schema