use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ModelManifest {
pub name: String,
pub model_type: String,
pub dataset: String,
pub dimensions: usize,
pub entities: usize,
pub relations: usize,
pub sha256: String,
pub source: String,
pub license: String,
pub citation: String,
pub version: String,
pub created: String,
pub notes: Option<String>,
}
#[cfg(test)]
mod tests {
use super::*;
fn sample_manifest() -> ModelManifest {
ModelManifest {
name: "test-model".to_string(),
model_type: "TransE".to_string(),
dataset: "FB15k-237".to_string(),
dimensions: 200,
entities: 14541,
relations: 237,
sha256: "abc123def456".to_string(),
source: "file:///seeds/test.ckpt".to_string(),
license: "Apache-2.0".to_string(),
citation: "Test Citation".to_string(),
version: "1.0.0".to_string(),
created: "2026-05-01".to_string(),
notes: Some("Test notes".to_string()),
}
}
#[test]
fn test_manifest_serialize_deserialize_toml() {
let m = sample_manifest();
let toml_str = toml::to_string(&m).expect("serialize to TOML");
let back: ModelManifest = toml::from_str(&toml_str).expect("deserialize from TOML");
assert_eq!(m, back);
}
#[test]
fn test_manifest_serialize_deserialize_json() {
let m = sample_manifest();
let json_str = serde_json::to_string(&m).expect("serialize to JSON");
let back: ModelManifest = serde_json::from_str(&json_str).expect("deserialize from JSON");
assert_eq!(m, back);
}
#[test]
fn test_manifest_notes_optional() {
let toml_str = r#"
name = "minimal"
model_type = "DistMult"
dataset = "WN18RR"
dimensions = 100
entities = 40943
relations = 11
sha256 = "deadbeef"
source = "file:///seeds/minimal.ckpt"
license = "MIT"
citation = "Nobody 2026"
version = "0.1.0"
created = "2026-05-01"
"#;
let m: ModelManifest = toml::from_str(toml_str).expect("parse without notes");
assert!(m.notes.is_none());
assert_eq!(m.model_type, "DistMult");
}
}