Make imported asset fingerprints deterministic

This commit is contained in:
Rbanh committed 2026-07-13 11:23:06 -04:00
1 parent a048233fce
commit e1b2f86a49
27 files changed
+798 -135

No files matched your search

+2 -7
View File
@@ -266,13 +266,8 @@ pub struct AnimationManifestSource {
pub dependencies: Vec<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct AnimationSourceFingerprint {
pub byte_len: u64,
pub modified_unix_secs: u64,
/// BLAKE3 hash of the source file bytes.
pub content_hash: String,
}
/// Backward-compatible name for the shared imported-source fingerprint contract.
pub type AnimationSourceFingerprint = crate::AssetSourceFingerprint;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct AnimationSkeletonRecord {
+50
View File
@@ -0,0 +1,50 @@
use serde::{Deserialize, Serialize};
/// Stable identity for the exact bytes of an imported project source.
///
/// Filesystem timestamps are deliberately excluded: Git and LFS do not preserve checkout mtimes,
/// so they cannot participate in a portable authored-data contract.
#[derive(Debug, Clone, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct AssetSourceFingerprint {
pub byte_len: u64,
#[serde(default)]
pub content_hash: String,
}
impl AssetSourceFingerprint {
pub fn from_bytes(bytes: &[u8]) -> Self {
Self {
byte_len: bytes.len() as u64,
content_hash: blake3::hash(bytes).to_hex().to_string(),
}
}
pub fn is_complete(&self) -> bool {
self.content_hash.len() == 64
&& self
.content_hash
.bytes()
.all(|byte| byte.is_ascii_digit() || (b'a'..=b'f').contains(&byte))
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn exact_bytes_define_source_identity() {
let first = AssetSourceFingerprint::from_bytes(b"asset-a");
let same = AssetSourceFingerprint::from_bytes(b"asset-a");
let same_size_change = AssetSourceFingerprint::from_bytes(b"asset-b");
assert_eq!(first, same);
assert_ne!(first, same_size_change);
assert_eq!(first.byte_len, same_size_change.byte_len);
assert!(first.is_complete());
let mut noncanonical = first;
noncanonical.content_hash.make_ascii_uppercase();
assert!(!noncanonical.is_complete());
}
}
+2
View File
@@ -6,6 +6,7 @@
mod actor;
mod animation;
mod asset_fingerprint;
pub mod brush_math;
mod components;
mod hydration;
@@ -18,6 +19,7 @@ mod rendering_profile_asset;
pub use actor::{infer_actor_kind, validate_actor, ActorValidationError};
pub use animation::*;
pub use asset_fingerprint::AssetSourceFingerprint;
pub use components::*;
pub use hydration::{
cascade_config_from_rendering, flush_level_object_hydration,