@@ -152,10 +152,11 @@ static function ( string $bytes, array $metadata ): bool {
152152 $ manifest ['final_result ' ]['url_batch_run ' ]['fetch_cache ' ] = $ manifest ['fetch_cache ' ];
153153 $ cache ->cleanup_adopted ();
154154 return $ manifest ['final_result ' ];
155- }$ importer = $ importer ?? static fn ( array $ artifact , array $ import_args ) => Static_Site_Importer_Theme_Generator::import_website_artifact ( $ artifact , $ import_args );
156- $ shared_plan = new Static_Site_Importer_Shared_Resource_Plan ( $ workspace );
157- $ cursor = Static_Site_Importer_Artifact_Batch_Cursor::hydrate ( $ manifest ['batches ' ] );
158- $ effective_batches = 0 ;
155+ }
156+ $ importer = $ importer ?? static fn ( array $ artifact , array $ import_args ) => Static_Site_Importer_Theme_Generator::import_website_artifact ( $ artifact , $ import_args );
157+ $ shared_plan = new Static_Site_Importer_Shared_Resource_Plan ( $ workspace );
158+ $ cursor = Static_Site_Importer_Artifact_Batch_Cursor::hydrate ( $ manifest ['batches ' ] );
159+ $ effective_batches = 0 ;
159160 $ manifest ['checkpoint_diagnostics ' ] = is_array ( $ manifest ['checkpoint_diagnostics ' ] ?? null ) ? $ manifest ['checkpoint_diagnostics ' ] : array ();
160161 while ( true ) {
161162 $ index = Static_Site_Importer_Artifact_Batch_Cursor::next ( $ cursor );
@@ -188,7 +189,7 @@ static function ( string $bytes, array $metadata ): bool {
188189 if ( is_wp_error ( $ ready_args ) ) {
189190 return self ::failed ( $ run_manifest , $ workspace , $ manifest , $ cursor , $ index , $ ready_args , $ cache );
190191 }
191- $ ready_runtime = Static_Site_Importer_URL_Site_Collector::collect ( $ batch_entry , $ ready_args , $ fetcher );
192+ $ ready_runtime = Static_Site_Importer_URL_Site_Collector::collect ( $ batch_entry , $ ready_args , $ fetcher );
192193 if ( is_wp_error ( $ ready_runtime ) ) {
193194 if ( self ::deadline_error ( $ ready_runtime ) ) {
194195 $ manifest ['batches ' ] = self ::legacy_batches ( $ cursor );
@@ -236,11 +237,11 @@ static function ( string $bytes, array $metadata ): bool {
236237 return self ::failed ( $ run_manifest , $ workspace , $ manifest , $ cursor , $ index , $ ready_result , $ cache );
237238 }
238239 } else {
239- $ cursor [ $ index ]['state ' ] = 'page_ready ' ;
240- $ cursor [ $ index ]['result ' ] = self ::result_evidence ( $ ready_result , $ ready_runtime );
240+ $ cursor [ $ index ]['state ' ] = 'page_ready ' ;
241+ $ cursor [ $ index ]['result ' ] = self ::result_evidence ( $ ready_result , $ ready_runtime );
241242 $ manifest ['page_ready_materialized ' ] = true ;
242- $ batch = $ cursor [ $ index ];
243- $ manifest ['batches ' ] = self ::legacy_batches ( $ cursor );
243+ $ batch = $ cursor [ $ index ];
244+ $ manifest ['batches ' ] = self ::legacy_batches ( $ cursor );
244245 self ::checkpoint_cache ( $ manifest , $ cache );
245246 $ write = $ run_manifest ->save ( $ manifest );
246247 if ( is_wp_error ( $ write ) ) {
@@ -261,7 +262,7 @@ static function ( string $bytes, array $metadata ): bool {
261262 if ( is_wp_error ( $ collect_args ) ) {
262263 return self ::failed ( $ run_manifest , $ workspace , $ manifest , $ cursor , $ index , $ collect_args , $ cache );
263264 }
264- $ runtime = Static_Site_Importer_URL_Site_Collector::collect ( $ batch_entry , $ collect_args , $ fetcher );
265+ $ runtime = Static_Site_Importer_URL_Site_Collector::collect ( $ batch_entry , $ collect_args , $ fetcher );
265266 if ( is_wp_error ( $ runtime ) ) {
266267 if ( self ::deadline_error ( $ runtime ) ) {
267268 $ manifest ['batches ' ] = self ::legacy_batches ( $ cursor );
@@ -380,7 +381,7 @@ static function ( string $bytes, array $metadata ): bool {
380381 }
381382 ++$ effective_batches ;
382383 $ final = self ::terminal_result_evidence ( $ result );
383- unset( $ result , $ runtime , $ raw , $ compiled_staged , $ import_args , $ staged , $ shared );
384+ unset( $ result , $ runtime , $ import_args , $ staged , $ shared );
384385 }
385386 if ( 'plan ' === (string ) ( $ input ['operation ' ] ?? 'apply ' ) ) {
386387 $ final = self ::compose_complete_plan ( $ workspace , $ cursor );
@@ -418,8 +419,8 @@ private static function prepare_staged_plans( Static_Site_Importer_Artifact_Run_
418419 if ( is_wp_error ( $ hydrated ) ) {
419420 return $ hydrated ;
420421 }
421- $ files = array_column ( $ hydrated , null , 'path ' );
422- $ shared_paths = array_fill_keys ( array_keys ( $ files ), true );
422+ $ files = array_column ( $ hydrated , null , 'path ' );
423+ $ shared_paths = array_fill_keys ( array_keys ( $ files ), true );
423424 $ artifact ['files ' ] = is_array ( $ artifact ['files ' ] ?? null ) ? $ artifact ['files ' ] : array ();
424425 foreach ( $ artifact ['files ' ] as &$ file ) {
425426 if ( is_array ( $ file ) && isset ( $ shared_paths [ (string ) ( $ file ['path ' ] ?? '' ) ] ) ) {
@@ -431,8 +432,8 @@ private static function prepare_staged_plans( Static_Site_Importer_Artifact_Run_
431432 }
432433 unset( $ file );
433434 $ shared_artifact ['files ' ] = array_values ( $ files );
434- $ stored = self ::load_payload_checkpoint ( $ workspace , 'staged-compiler-shared.json ' , array ( 'resource_digest ' => $ resource_digest ) );
435- $ shared_prepared = is_wp_error ( $ stored ) || ! is_array ( $ stored );
435+ $ stored = self ::load_payload_checkpoint ( $ workspace , 'staged-compiler-shared.json ' , array ( 'resource_digest ' => $ resource_digest ) );
436+ $ shared_prepared = is_wp_error ( $ stored ) || ! is_array ( $ stored );
436437 try {
437438 $ prepare_shared = array ( $ compiler , 'prepareShared ' );
438439 $ prepare_page = array ( $ compiler , 'preparePage ' );
@@ -447,12 +448,15 @@ private static function prepare_staged_plans( Static_Site_Importer_Artifact_Run_
447448 }
448449 }
449450 $ page_checkpoint = 'staged-compiler-pages/ ' . $ batch_id . '.json ' ;
450- $ page_plans = self ::load_payload_checkpoint ( $ workspace , $ page_checkpoint , array ( 'resource_digest ' => $ resource_digest , 'snapshot_sha256 ' => $ snapshot_sha256 ) );
451+ $ page_plans = self ::load_payload_checkpoint ( $ workspace , $ page_checkpoint , array (
452+ 'resource_digest ' => $ resource_digest ,
453+ 'snapshot_sha256 ' => $ snapshot_sha256 ,
454+ ) );
451455 $ page_prepared = 0 ;
452456 if ( is_wp_error ( $ page_plans ) || ! is_array ( $ page_plans ) ) {
453457 $ page_plans = array ();
454458 $ page_ids = array ();
455- foreach ( $ artifact ['files ' ] ?? array () as $ file ) {
459+ foreach ( $ artifact ['files ' ] as $ file ) {
456460 if ( ! is_array ( $ file ) || 'text/html ' !== strtolower ( (string ) ( $ file ['mime_type ' ] ?? '' ) ) || '' === (string ) ( $ file ['path ' ] ?? '' ) ) {
457461 continue ;
458462 }
@@ -462,10 +466,13 @@ private static function prepare_staged_plans( Static_Site_Importer_Artifact_Run_
462466 continue ;
463467 }
464468 $ page_ids [ $ page_id ] = true ;
465- $ page_plans [] = call_user_func ( $ prepare_page , $ artifact , $ shared , $ page_id );
469+ $ page_plans [] = call_user_func ( $ prepare_page , $ artifact , $ shared , $ page_id );
466470 }
467471 $ page_prepared = count ( $ page_plans );
468- $ write = self ::store_payload_checkpoint ( $ workspace , $ page_checkpoint , $ page_plans , array ( 'resource_digest ' => $ resource_digest , 'snapshot_sha256 ' => $ snapshot_sha256 ) );
472+ $ write = self ::store_payload_checkpoint ( $ workspace , $ page_checkpoint , $ page_plans , array (
473+ 'resource_digest ' => $ resource_digest ,
474+ 'snapshot_sha256 ' => $ snapshot_sha256 ,
475+ ) );
469476 if ( is_wp_error ( $ write ) ) {
470477 return $ write ;
471478 }
@@ -486,7 +493,7 @@ private static function store_payload_checkpoint( Static_Site_Importer_Artifact_
486493 if ( is_wp_error ( $ externalized ) ) {
487494 return $ externalized ;
488495 }
489- $ plan_json = wp_json_encode ( $ externalized , JSON_UNESCAPED_SLASHES );
496+ $ plan_json = wp_json_encode ( $ externalized , JSON_UNESCAPED_SLASHES );
490497 $ normalized = is_string ( $ plan_json ) ? json_decode ( $ plan_json , true ) : null ;
491498 if ( ! is_array ( $ normalized ) ) {
492499 return new WP_Error ( 'static_site_importer_payload_checkpoint_invalid ' , 'An artifact payload checkpoint could not be serialized. ' );
@@ -505,7 +512,7 @@ private static function store_payload_checkpoint( Static_Site_Importer_Artifact_
505512 private static function load_payload_checkpoint ( Static_Site_Importer_Artifact_Run_Workspace $ workspace , string $ path , array $ identity , bool $ hydrate = true ): array |WP_Error |null {
506513 $ raw = $ workspace ->read_raw ( $ path );
507514 $ checkpoint = is_string ( $ raw ) ? json_decode ( $ raw , true ) : null ;
508- if ( ! is_array ( $ checkpoint ) || 'static-site-importer/artifact-payload-checkpoint/v1 ' !== ( $ checkpoint ['schema ' ] ?? '' ) || $ identity !== ( $ checkpoint ['identity ' ] ?? null ) || ! is_array ( $ checkpoint ['plan ' ] ?? null ) ) {
515+ if ( ! is_array ( $ checkpoint ) || 'static-site-importer/artifact-payload-checkpoint/v1 ' !== ( $ checkpoint ['schema ' ] ?? '' ) || ( $ checkpoint ['identity ' ] ?? null ) !== $ identity || ! is_array ( $ checkpoint ['plan ' ] ?? null ) ) {
509516 return null ;
510517 }
511518 if ( ! hash_equals ( (string ) ( $ checkpoint ['plan_sha256 ' ] ?? '' ), hash ( 'sha256 ' , (string ) wp_json_encode ( $ checkpoint ['plan ' ], JSON_UNESCAPED_SLASHES ) ) ) ) {
@@ -523,14 +530,18 @@ private static function externalize_staged_plan_payloads( Static_Site_Importer_A
523530 $ payload = $ resource ['body ' ];
524531 $ hash = hash ( 'sha256 ' , $ payload );
525532 $ ref = 'collection-payloads/ ' . $ hash . '.payload ' ;
526- if ( $ workspace ->read_raw ( $ ref ) !== $ payload ) {
533+ if ( $ payload !== $ workspace ->read_raw ( $ ref ) ) {
527534 $ stored = $ workspace ->publish_raw ( $ ref , $ payload );
528535 if ( is_wp_error ( $ stored ) ) {
529536 return $ stored ;
530537 }
531538 }
532539 unset( $ resource ['body ' ] );
533- $ resource ['checkpoint_payload ' ] = array ( 'bytes ' => strlen ( $ payload ), 'sha256 ' => $ hash , 'ref ' => $ ref );
540+ $ resource ['checkpoint_payload ' ] = array (
541+ 'bytes ' => strlen ( $ payload ),
542+ 'sha256 ' => $ hash ,
543+ 'ref ' => $ ref ,
544+ );
534545 }
535546 unset( $ resource );
536547 }
@@ -553,7 +564,12 @@ private static function externalize_staged_plan_payloads( Static_Site_Importer_A
553564 }
554565 }
555566 unset( $ file [ $ encoding ] );
556- $ file ['checkpoint_payload ' ] = array ( 'encoding ' => $ encoding , 'bytes ' => strlen ( $ payload ), 'sha256 ' => $ hash , 'ref ' => $ ref );
567+ $ file ['checkpoint_payload ' ] = array (
568+ 'encoding ' => $ encoding ,
569+ 'bytes ' => strlen ( $ payload ),
570+ 'sha256 ' => $ hash ,
571+ 'ref ' => $ ref ,
572+ );
557573 }
558574 unset( $ file );
559575 return $ value ;
@@ -621,14 +637,14 @@ private static function with_collection_checkpoint( Static_Site_Importer_Artifac
621637 'mode ' => $ mode ,
622638 'routes_hash ' => hash ( 'sha256 ' , (string ) wp_json_encode ( array_values ( $ routes ), JSON_UNESCAPED_SLASHES ) ),
623639 );
624- $ state = self ::load_payload_checkpoint ( $ workspace , $ path , $ identity , false );
640+ $ state = self ::load_payload_checkpoint ( $ workspace , $ path , $ identity , false );
625641 if ( is_wp_error ( $ state ) ) {
626642 return $ state ;
627643 }
628644 if ( is_array ( $ state ) ) {
629645 $ args ['_collection_state ' ] = $ state ;
630646 }
631- $ args ['_collection_checkpoint ' ] = static function ( ?array $ next ) use ( $ workspace , $ path , $ identity ): bool |string |WP_Error {
647+ $ args ['_collection_checkpoint ' ] = static function ( ?array $ next ) use ( $ workspace , $ path , $ identity ): bool |string |WP_Error {
632648 if ( null === $ next ) {
633649 return $ workspace ->delete ( $ path );
634650 }
@@ -853,23 +869,23 @@ private static function cache_counters( array $counters ): array {
853869 private static function retained_runtime ( Static_Site_Importer_Artifact_Run_Workspace $ workspace , string $ stable , string $ indexed , string $ legacy , array $ routes , array &$ diagnostics = array () ): ?array {
854870 $ diagnostics ['lookups ' ] = (int ) ( $ diagnostics ['lookups ' ] ?? 0 ) + 1 ;
855871 foreach ( array_values ( array_unique ( array ( $ stable , $ indexed , $ legacy ) ) ) as $ source ) {
856- $ workspace_source = 'batches/ ' === substr ( $ source , 0 , 8 );
872+ $ workspace_source = 'batches/ ' === substr ( $ source , 0 , 8 );
857873 $ raw_workspace_runtime = false ;
858874 if ( $ workspace_source ) {
859- $ raw = $ workspace ->read_raw ( $ source );
875+ $ raw = $ workspace ->read_raw ( $ source );
860876 if ( ! is_string ( $ raw ) ) {
861877 $ diagnostics ['missing ' ] = (int ) ( $ diagnostics ['missing ' ] ?? 0 ) + 1 ;
862878 }
863879 $ decoded = is_string ( $ raw ) ? json_decode ( $ raw , true ) : null ;
864880 if ( 'static-site-importer/artifact-payload-checkpoint/v1 ' === ( $ decoded ['schema ' ] ?? '' ) ) {
865881 $ candidate = self ::load_payload_checkpoint ( $ workspace , $ source , array ( 'kind ' => 'collected_runtime ' ) );
866882 if ( is_wp_error ( $ candidate ) ) {
867- $ diagnostics ['verification_failures ' ] = (int ) ( $ diagnostics ['verification_failures ' ] ?? 0 ) + 1 ;
883+ $ diagnostics ['verification_failures ' ] = (int ) ( $ diagnostics ['verification_failures ' ] ?? 0 ) + 1 ;
868884 $ diagnostics ['last_verification_error ' ] = $ candidate ->get_error_code ();
869885 }
870886 $ candidate = is_array ( $ candidate ) ? $ candidate : null ;
871887 } else {
872- $ candidate = is_array ( $ decoded ) ? $ decoded : null ;
888+ $ candidate = is_array ( $ decoded ) ? $ decoded : null ;
873889 $ raw_workspace_runtime = is_array ( $ candidate );
874890 }
875891 } elseif ( is_file ( $ source ) ) {
@@ -915,7 +931,7 @@ private static function invalidate_prepared_batches( Static_Site_Importer_Artifa
915931 return $ invalidated ;
916932 }
917933 private static function owns_runtime ( array $ runtime , array $ routes ): bool {
918- $ files = $ runtime ['source_metadata ' ]['snapshot ' ]['files ' ] ?? null ;
934+ $ files = $ runtime ['source_metadata ' ]['snapshot ' ]['files ' ] ?? null ;
919935 if ( ! is_array ( $ files ) ) {
920936 return false ;
921937 }$ actual = array ();
@@ -1018,7 +1034,7 @@ private static function result_evidence( array $result, array $runtime ): array
10181034 );
10191035 }
10201036 private static function terminal_result_evidence ( array $ result ): array {
1021- $ evidence = array ( 'schema ' => 'static-site-importer/terminal-batch-result/v1 ' );
1037+ $ evidence = array ( 'schema ' => 'static-site-importer/terminal-batch-result/v1 ' );
10221038 $ report_path = '' !== (string ) ( $ result ['external_report_path ' ] ?? '' ) ? (string ) $ result ['external_report_path ' ] : (string ) ( $ result ['report_path ' ] ?? '' );
10231039 foreach ( $ result as $ key => $ value ) {
10241040 if ( is_string ( $ key ) && ( is_scalar ( $ value ) || null === $ value ) ) {
@@ -1061,12 +1077,12 @@ private static function merge_external_assets( array $aggregate, array $current,
10611077 );
10621078 }
10631079 private static function aggregate_result ( array $ manifest , string $ path , array $ terminal ): array {
1064- $ batch_quality = array_values ( array_filter ( array_map ( static fn ( array $ batch ): mixed => self ::quality_evidence ( $ batch ['result ' ]['quality ' ] ?? null ), $ manifest ['batches ' ] ), static fn ( $ quality ): bool => null !== $ quality ) );
1080+ $ batch_quality = array_values ( array_filter ( array_map ( static fn ( array $ batch ): mixed => self ::quality_evidence ( $ batch ['result ' ]['quality ' ] ?? null ), $ manifest ['batches ' ] ), static fn ( $ quality ): bool => null !== $ quality ) );
10651081 $ terminal_result = self ::terminal_result_evidence ( $ terminal );
10661082 if ( is_array ( $ terminal ['plan ' ] ?? null ) ) {
10671083 $ terminal_result ['plan ' ] = $ terminal ['plan ' ];
10681084 }
1069- $ evidence = array (
1085+ $ evidence = array (
10701086 'status ' => 'completed ' ,
10711087 'run_manifest ' => $ path ,
10721088 'fetch_cache ' => $ manifest ['fetch_cache ' ] ?? array (),
@@ -1142,7 +1158,7 @@ private static function continuation_result( array $manifest, string $path, int
11421158 'max_invocation_seconds ' => $ max_invocation_seconds ,
11431159 'continuation_reason ' => $ reason ,
11441160 'next_work ' => $ next_work ,
1145- 'checkpoint_diagnostics ' => $ manifest ['checkpoint_diagnostics ' ] ?? array (),
1161+ 'checkpoint_diagnostics ' => $ manifest ['checkpoint_diagnostics ' ] ?? array (),
11461162 ),
11471163 'batch_materialization ' => $ manifest ['batches ' ],
11481164 );
0 commit comments