@@ -566,6 +566,16 @@ async function runBootProbe(phase: string, bucket: R2Bucket): Promise<Response>
566566 }
567567 }
568568
569+ if ( [ "canonical-current-user" , "canonical-init" , "canonical-site-status" , "canonical-wp-loaded" ] . includes ( phase ) ) {
570+ const runtime = await bootWordPressRuntime ( "do-not-attempt-installing" , true , true , undefined , await packagedCanonicalMarkdownSeed ( ) , new Uint8Array ( markdownPrimaryBootstrapIndex ) , "https://canonical-probe.invalid" , { } , bucket , true )
571+ try {
572+ const evidence = ( await runtime . php . run ( { code : canonicalLifecycleProbeCode ( phase ) } ) ) . text . trim ( )
573+ return probeResponse ( phase , JSON . parse ( evidence ) as Record < string , boolean | number | string > )
574+ } finally {
575+ runtime . php . exit ( )
576+ }
577+ }
578+
569579 if ( phase === "canonical-wordpress" || phase === "canonical-bootstrap-setup" ) {
570580 const canonicalSeed = await packagedCanonicalMarkdownSeed ( )
571581 const runtime = await bootWordPressRuntime ( "do-not-attempt-installing" , true , true , undefined , canonicalSeed , new Uint8Array ( markdownPrimaryBootstrapIndex ) , "https://canonical-probe.invalid" , { } , bucket , true )
@@ -993,6 +1003,41 @@ file_put_contents($settings_path, str_replace($needle, $replacement, $settings))
9931003require '/wordpress/wp-load.php';`
9941004}
9951005
1006+ function canonicalLifecycleProbeCode ( phase : string ) : string {
1007+ const stops : Record < string , { needle : string ; after ?: boolean } > = {
1008+ "canonical-current-user" : { needle : "// Set up current user." } ,
1009+ "canonical-init" : { needle : "do_action( 'init' );" , after : true } ,
1010+ "canonical-site-status" : { needle : "// Check site status." } ,
1011+ "canonical-wp-loaded" : { needle : "do_action( 'wp_loaded' );" , after : true } ,
1012+ }
1013+ const stop = stops [ phase ]
1014+ if ( ! stop ) throw new Error ( `Unknown canonical lifecycle probe phase: ${ phase } ` )
1015+
1016+ return `<?php
1017+ $settings_path = '/wordpress/wp-settings.php';
1018+ $settings = file_get_contents($settings_path);
1019+ $needle = ${ JSON . stringify ( stop . needle ) } ;
1020+ if (substr_count($settings, $needle) !== 1) {
1021+ throw new Exception('WordPress canonical lifecycle probe needle was not uniquely found.');
1022+ }
1023+ $stop = <<<'PHP'
1024+ echo json_encode(array(
1025+ 'wordpressVersion' => $wp_version,
1026+ 'bootstrapPhase' => '${ phase } ',
1027+ 'completed' => true,
1028+ 'memoryBytes' => memory_get_usage(true),
1029+ 'peakMemoryBytes' => memory_get_peak_usage(true),
1030+ 'wpCronInitAttached' => false !== has_action('init', 'wp_cron'),
1031+ 'updateScheduleInitAttached' => false !== has_action('init', 'wp_schedule_update_checks'),
1032+ 'privacyScheduleInitAttached' => false !== has_action('init', 'wp_schedule_delete_old_privacy_export_files'),
1033+ ));
1034+ return;
1035+ PHP;
1036+ $replacement = ${ stop . after ? "$needle . \"\\n\" . \$stop" : "$stop . \"\\n\" . $needle" } ;
1037+ file_put_contents($settings_path, str_replace($needle, $replacement, $settings));
1038+ require '/wordpress/wp-load.php';`
1039+ }
1040+
9961041async function bootWordPressRuntime (
9971042 wordpressInstallMode : WordPressInstallMode = "install-from-existing-files" ,
9981043 includeSqlite = true ,
@@ -1195,6 +1240,6 @@ function instantiatePrecompiledWasm(module: WebAssembly.Module) {
11951240 return ( imports : WebAssembly . Imports , receiveInstance : ( instance : WebAssembly . Instance , wasmModule : WebAssembly . Module ) => void ) => receiveInstance ( new WebAssembly . Instance ( module , imports ) , module )
11961241}
11971242
1198- function probeResponse ( phase : string , evidence : Record < string , number | string > ) : Response {
1243+ function probeResponse ( phase : string , evidence : Record < string , boolean | number | string > ) : Response {
11991244 return Response . json ( { schema : "wp-codebox/cloudflare-boot-probe/v1" , phase, completed : true , evidence } )
12001245}
0 commit comments