Skip to content

Commit

Permalink
Ensure Ingredient data_types make it to the store and back.
Browse files Browse the repository at this point in the history
  • Loading branch information
gpeacock committed Jul 17, 2024
1 parent aec9129 commit 3d38d6e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
2 changes: 2 additions & 0 deletions sdk/src/ingredient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,7 @@ impl Ingredient {
ingredient.metadata = ingredient_assertion.metadata;
ingredient.description = ingredient_assertion.description;
ingredient.informational_uri = ingredient_assertion.informational_uri;
ingredient.data_types = ingredient_assertion.data_types;
Ok(ingredient)
}

Expand Down Expand Up @@ -1265,6 +1266,7 @@ impl Ingredient {
ingredient_assertion
.informational_uri
.clone_from(&self.informational_uri);
ingredient_assertion.data_types.clone_from(&self.data_types);
claim.add_assertion(&ingredient_assertion)
}

Expand Down
42 changes: 34 additions & 8 deletions sdk/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2288,14 +2288,24 @@ pub(crate) mod tests {
"format": "text/plain",
"relationship": "inputTo",
"data": {
"format": "text/plain",
"identifier": "prompt.txt",
"data_types": [
"format": "text/plain",
"identifier": "prompt.txt",
"data_types": [
{
"type": "c2pa.types.generator.prompt"
}
]
}
},
{
"title": "Custom AI Model",
"format": "application/octet-stream",
"relationship": "inputTo",
"data_types": [
{
"type": "c2pa.types.generator.prompt"
"type": "c2pa.types.model"
}
]
}
]
}
]
}"#;
Expand Down Expand Up @@ -2347,7 +2357,8 @@ pub(crate) mod tests {
let (format, image) = m.thumbnail().unwrap();
assert_eq!(format, "image/jpeg");
assert_eq!(image.to_vec(), b"my value");
assert_eq!(m.ingredients().len(), 2);
assert_eq!(m.ingredients().len(), 3);
// Validate a prompt ingredient (with data field)
assert_eq!(m.ingredients()[1].relationship(), &Relationship::InputTo);
assert!(m.ingredients()[1].data_ref().is_some());
assert_eq!(m.ingredients()[1].data_ref().unwrap().format, "text/plain");
Expand All @@ -2356,6 +2367,14 @@ pub(crate) mod tests {
m.ingredients()[1].resources().get(id).unwrap().into_owned(),
b"pirate with bird on shoulder"
);
// Validate a custom AI model ingredient.
assert_eq!(m.ingredients()[2].title(), "Custom AI Model");
assert_eq!(m.ingredients()[2].relationship(), &Relationship::InputTo);
assert_eq!(
m.ingredients()[2].data_types().unwrap()[0].asset_type,
"c2pa.types.model"
);

// println!("{manifest_store}");
}

Expand Down Expand Up @@ -2400,7 +2419,7 @@ pub(crate) mod tests {
let (format, image) = m.thumbnail().unwrap();
assert_eq!(format, "image/jpeg");
assert_eq!(image.to_vec(), b"my value");
assert_eq!(m.ingredients().len(), 2);
assert_eq!(m.ingredients().len(), 3);
assert_eq!(m.ingredients()[1].relationship(), &Relationship::InputTo);
assert!(m.ingredients()[1].data_ref().is_some());
assert_eq!(m.ingredients()[1].data_ref().unwrap().format, "text/plain");
Expand All @@ -2409,6 +2428,13 @@ pub(crate) mod tests {
m.ingredients()[1].resources().get(id).unwrap().into_owned(),
b"pirate with bird on shoulder"
);
// Validate a custom AI model ingredient.
assert_eq!(m.ingredients()[2].title(), "Custom AI Model");
assert_eq!(m.ingredients()[2].relationship(), &Relationship::InputTo);
assert_eq!(
m.ingredients()[2].data_types().unwrap()[0].asset_type,
"c2pa.types.model"
);
// println!("{manifest_store}");
}

Expand Down

0 comments on commit 3d38d6e

Please sign in to comment.