@@ -156,56 +156,127 @@ test("generates a Studio CLI import payload for the Figma handoff", async () =>
156156 assert . ok ( artifact . studioImportPayload . files . some ( ( file ) => file . path === "website/index.html" ) ) ;
157157} ) ;
158158
159- test ( "generates a Studio Figma source payload for the primary handoff " , async ( ) => {
159+ test ( "generates a source-first Figma handoff payload with debug summary " , async ( ) => {
160160 const { toFigmaSourcePayload } = await loadPayloadModule ( ) ;
161161 const selection = {
162162 id : "root" ,
163163 name : "Studio Figma Source Demo" ,
164164 type : "DOCUMENT" ,
165165 exportedAt : "2026-01-01T00:00:00.000Z" ,
166- root : { id : "doc" , name : "Document" , type : "DOCUMENT" , visible : true } ,
166+ root : {
167+ id : "doc" ,
168+ name : "Document" ,
169+ type : "DOCUMENT" ,
170+ visible : true ,
171+ children : [
172+ {
173+ id : "page-1" ,
174+ name : "Landing" ,
175+ type : "PAGE" ,
176+ visible : true ,
177+ children : [
178+ {
179+ id : "frame-1" ,
180+ name : "Hero" ,
181+ type : "FRAME" ,
182+ visible : true ,
183+ children : [
184+ {
185+ id : "headline" ,
186+ name : "Headline" ,
187+ type : "TEXT" ,
188+ visible : true ,
189+ characters : "Import with Studio" ,
190+ } ,
191+ ] ,
192+ } ,
193+ ] ,
194+ } ,
195+ ] ,
196+ } ,
167197 source : {
168198 provider : "figma" ,
169199 plugin : "figma-to-wordpress-studio" ,
170200 fileKey : "abc123" ,
171201 fileName : "Studio Figma Source Demo" ,
172202 editorType : "figma" ,
173- currentPage : { id : "page" , name : "Landing" } ,
203+ currentPage : { id : "page-1 " , name : "Landing" } ,
174204 } ,
175205 selectionIntent : {
176206 scope : "selected-nodes" ,
177- pageId : "page" ,
207+ pageId : "page-1 " ,
178208 pageName : "Landing" ,
179- selectedNodeIds : [ "frame" ] ,
180- rootNodeIds : [ "frame" ] ,
209+ selectedNodeIds : [ "frame-1 " ] ,
210+ rootNodeIds : [ "frame-1 " ] ,
181211 } ,
182212 currentPage : {
183- id : "page" ,
213+ id : "page-1 " ,
184214 name : "Landing" ,
185215 type : "PAGE" ,
186216 visible : true ,
187- children : [ { id : "frame" , name : "Hero" , type : "FRAME" , visible : true } ] ,
217+ children : [
218+ {
219+ id : "frame-1" ,
220+ name : "Hero" ,
221+ type : "FRAME" ,
222+ visible : true ,
223+ children : [
224+ {
225+ id : "headline" ,
226+ name : "Headline" ,
227+ type : "TEXT" ,
228+ visible : true ,
229+ characters : "Import with Studio" ,
230+ } ,
231+ ] ,
232+ } ,
233+ ] ,
188234 } ,
189- selectedNodes : [ { id : "frame" , name : "Hero" , type : "FRAME" , visible : true } ] ,
190- assets : [ ] ,
235+ selectedNodes : [
236+ {
237+ id : "frame-1" ,
238+ name : "Hero" ,
239+ type : "FRAME" ,
240+ visible : true ,
241+ children : [
242+ {
243+ id : "headline" ,
244+ name : "Headline" ,
245+ type : "TEXT" ,
246+ visible : true ,
247+ characters : "Import with Studio" ,
248+ } ,
249+ ] ,
250+ } ,
251+ ] ,
252+ assets : [ { id : "asset-1" , name : "Hero.png" , format : "PNG" , dataUrl : "data:image/png;base64,YQ==" } ] ,
191253 } ;
192- const sourcePayload = toFigmaSourcePayload ( selection , {
254+ const artifact = {
193255 title : selection . name ,
194256 html : "" ,
195257 css : "" ,
196258 studioImportPayload : { schema : "blocks-engine/php-transformer/site-artifact/v1" } ,
197259 files : { } ,
198- diagnostics : [ ] ,
199- } ) ;
260+ diagnostics : [ { level : "warning" , nodeId : "frame-1" , nodeName : "Hero" , message : "Review layout" } ] ,
261+ } ;
262+ const source = toFigmaSourcePayload ( selection , artifact , "handoff-123" ) ;
200263
201- assert . equal ( sourcePayload . schema , "wordpress-studio/figma-source/v1" ) ;
202- assert . equal ( sourcePayload . source . metadata . fileKey , "abc123" ) ;
203- assert . equal ( sourcePayload . intent . scope , "selected-nodes" ) ;
204- assert . equal ( sourcePayload . scenegraph . currentPage . id , "page" ) ;
205- assert . equal ( sourcePayload . scenegraph . selectedNodes [ 0 ] . id , "frame" ) ;
206- assert . equal ( sourcePayload . transform . route , "static-site-importer/figma" ) ;
207- assert . equal ( sourcePayload . transform . options . preserveSourceScenegraph , true ) ;
208- assert . equal ( sourcePayload . debug . generatedArtifact . schema , "blocks-engine/php-transformer/site-artifact/v1" ) ;
264+ assert . equal ( source . schema , "wordpress-studio/figma-source/v1" ) ;
265+ assert . equal ( source . source . metadata . fileKey , "abc123" ) ;
266+ assert . equal ( source . intent . scope , "selected-nodes" ) ;
267+ assert . deepEqual ( source . intent . selectedNodeIds , [ "frame-1" ] ) ;
268+ assert . equal ( source . scenegraph . currentPage . id , "page-1" ) ;
269+ assert . equal ( source . scenegraph . selectedNodes [ 0 ] . id , "frame-1" ) ;
270+ assert . equal ( source . transform . route , "static-site-importer/figma" ) ;
271+ assert . equal ( source . transform . options . preserveSourceScenegraph , true ) ;
272+ assert . equal ( source . debug . handoffId , "handoff-123" ) ;
273+ assert . equal ( source . debug . generatedArtifact . schema , "blocks-engine/php-transformer/site-artifact/v1" ) ;
274+ assert . equal ( source . debug . summary . scope , "selected-nodes" ) ;
275+ assert . equal ( source . debug . summary . selectedNodeCount , 1 ) ;
276+ assert . equal ( source . debug . summary . nodeCount , 2 ) ;
277+ assert . equal ( source . debug . summary . assetCount , 1 ) ;
278+ assert . equal ( source . debug . summary . diagnosticCount , artifact . diagnostics . length ) ;
279+ assert . equal ( source . debug . summary . warningCount , 1 ) ;
209280} ) ;
210281
211282test ( "reports missing image sources with node identity" , async ( ) => {
0 commit comments