Model-cache tests trust an unknown source commit, so they pass without git (#4221)

Fixes #4045
This commit is contained in:
Dennis Klappe
2026-10-24 21:20:56 +00:00
committed by GitHub
parent a2ae3ffbe0
commit b201c283c7
4 changed files with 21 additions and 2 deletions
+2
View File
@@ -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"] }
+4
View File
@@ -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 }
+7
View File
@@ -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");
+8 -2
View File
@@ -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> {