SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Model-cache tests trust an unknown source commit, so they pass without git (#4221)
Dennis Klappeb201c283c7cb
diff --git a/crates/engine/Cargo.toml b/crates/engine/Cargo.tomlindex 23b35b38b8..1c3babcc6c 100644--- a/crates/engine/Cargo.toml+++ b/crates/engine/Cargo.toml@@ -46,6 +46,8 @@ log = { workspace = true }web-time = { workspace = true }[dev-dependencies]+# Model-cache tests also run in a source tarball build (no git commit).+solidcraft-io = { workspace = true, features = ["trust-unknown-source"] }# Normal CI exercises profiling assertions without enabling the production feature.solidcraft-sketch = { workspace = true, features = ["solver-profiling"] }diff --git a/crates/io/Cargo.toml b/crates/io/Cargo.tomlindex 5f4ef8c16d..fe3aef46aa 100644--- a/crates/io/Cargo.toml+++ b/crates/io/Cargo.toml@@ -8,6 +8,10 @@ license.workspace = true[lints]workspace = true+[features]+# Tests only: trust a model cache even when the build has no git commit.+trust-unknown-source = []+[dependencies]solidcraft-geom = { workspace = true }solidcraft-kernel = { workspace = true }diff --git a/crates/io/src/design.rs b/crates/io/src/design.rsindex 5e48f94bd0..95a1778415 100644--- a/crates/io/src/design.rs+++ b/crates/io/src/design.rs@@ -964,6 +964,13 @@ mod tests {saved_model(vec![solidcraft_kernel::box_solid(solidcraft_geom::Vec3::ZERO, solidcraft_geom::Vec3::new(10., 20., 30.)).unwrap()])}+ #[test]+ fn a_build_of_unknown_source_never_trusts_a_cache_outside_tests() {+ assert!(!native_cache::source_trusted("unknown", false));+ assert!(native_cache::source_trusted("unknown", true));+ assert!(native_cache::source_trusted("0123abc", false));+ }+#[test]fn native_cache_round_trip_and_preview_defer_original_sources() {let mut doc = Document::new("Native cache");diff --git a/crates/io/src/design/native_cache.rs b/crates/io/src/design/native_cache.rsindex 1701d6729c..edd797fe22 100644--- a/crates/io/src/design/native_cache.rs+++ b/crates/io/src/design/native_cache.rs@@ -207,8 +207,14 @@ fn current(manifest: &Value, document: &[u8]) -> bool {&& is("app", env!("CARGO_PKG_VERSION"))&& is("build", &build())&& is("document", &digest(document))- // A development build of unknown source never trusts a cache.- && env!("SOLIDCRAFT_SOURCE_COMMIT") != "unknown"+ && source_trusted(env!("SOLIDCRAFT_SOURCE_COMMIT"), cfg!(any(test, feature = "trust-unknown-source")))+}++/// A build of unknown source (no git) never trusts a cache, unless `in_tests`: test builds+/// trust it so the cache tests also pass in a source tarball (the `trust-unknown-source`+/// feature is only enabled by dev-dependencies).+pub(super) fn source_trusted(commit: &str, in_tests: bool) -> bool {+ commit != "unknown" || in_tests}pub(super) fn read_geometry_with<R: Read + Seek>(reader: &mut PackageReader<R>, document: &[u8]) -> Result<SavedModel> {