@@ -696,11 +696,15 @@ describe("Builder", () => {
696696 expect ( actionsAssertion ) . toBeDefined ( ) ;
697697 if ( isActionsAssertion ( actionsAssertion ) ) {
698698 const actions = actionsAssertion . data . actions ;
699- const editedAction = actions . find ( ( a : any ) => a . action === "c2pa.edited" ) ;
699+ const editedAction = actions . find (
700+ ( a : any ) => a . action === "c2pa.edited" ,
701+ ) ;
700702 expect ( editedAction ) . toBeDefined ( ) ;
701703 expect ( editedAction ?. action ) . toBe ( "c2pa.edited" ) ;
702704 } else {
703- throw new Error ( "Actions assertion does not have the expected structure" ) ;
705+ throw new Error (
706+ "Actions assertion does not have the expected structure" ,
707+ ) ;
704708 }
705709 } ) ;
706710
@@ -760,5 +764,48 @@ describe("Builder", () => {
760764 expect ( addedIngredient ?. instance_id ) . toBe ( "ingredient-12345" ) ;
761765 expect ( addedIngredient ?. relationship ) . toBe ( "componentOf" ) ;
762766 } ) ;
767+
768+ it ( "should add ingredient from reader" , async ( ) => {
769+ const builder1 = Builder . new ( ) ;
770+ builder1 . setIntent ( "edit" as any ) ;
771+ const signer = LocalSigner . newSigner ( publicKey , privateKey , "es256" ) ;
772+ const dest1 : DestinationBufferAsset = {
773+ buffer : null ,
774+ } ;
775+ builder1 . sign ( signer , source , dest1 ) ;
776+
777+ // Read the signed file back with Reader
778+ const reader = await Reader . fromAsset ( {
779+ buffer : dest1 . buffer ! as Buffer ,
780+ mimeType : "image/jpeg" ,
781+ } ) ;
782+ expect ( reader ) . not . toBeNull ( ) ;
783+
784+ // Create a new builder and add ingredient from the reader
785+ const builder2 = Builder . new ( ) ;
786+ const ingredient = builder2 . addIngredientFromReader ( reader ! ) ;
787+ expect ( ingredient ) . toBeDefined ( ) ;
788+
789+ // Verify the ingredient was added to the builder
790+ const definition = builder2 . getManifestDefinition ( ) ;
791+ expect ( definition . ingredients ) . toBeDefined ( ) ;
792+ expect ( definition . ingredients ! . length ) . toBeGreaterThan ( 0 ) ;
793+
794+ // Sign again with the new builder
795+ const dest2 : DestinationBufferAsset = {
796+ buffer : null ,
797+ } ;
798+ builder2 . sign ( signer , source , dest2 ) ;
799+
800+ // Verify the ingredient is in the signed manifest
801+ const reader2 = await Reader . fromAsset ( {
802+ buffer : dest2 . buffer ! as Buffer ,
803+ mimeType : "image/jpeg" ,
804+ } ) ;
805+ expect ( reader2 ) . not . toBeNull ( ) ;
806+ const activeManifest = reader2 ! . getActive ( ) ;
807+ expect ( activeManifest ?. ingredients ) . toBeDefined ( ) ;
808+ expect ( activeManifest ?. ingredients ?. length ) . toBe ( 1 ) ;
809+ } ) ;
763810 } ) ;
764811} ) ;
0 commit comments