diff --git a/crates/engine/Cargo.toml b/crates/engine/Cargo.toml index 23b35b38b..1c3babcc6 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.toml index 5f4ef8c16..fe3aef46a 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.rs index 5e48f94bd..95a177841 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.rs index 1701d6729..edd797fe2 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(reader: &mut PackageReader, document: &[u8]) -> Result {