From b53d5210aba7df371d94a49b21c75fc9d50d488c Mon Sep 17 00:00:00 2001 From: Chris Huber Date: Mon, 1 Jun 2026 15:07:54 -0400 Subject: [PATCH 1/2] fix: refresh bench REST routes after activation --- examples/bench-plugin/bench-plugin.php | 15 +++++++++++++++ examples/bench-plugin/tests/bench/noop.php | 6 +++++- .../src/bench-command-handlers.ts | 4 ++++ scripts/recipe-bench-smoke.ts | 1 + 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/examples/bench-plugin/bench-plugin.php b/examples/bench-plugin/bench-plugin.php index e907a99..a3a595c 100644 --- a/examples/bench-plugin/bench-plugin.php +++ b/examples/bench-plugin/bench-plugin.php @@ -10,3 +10,18 @@ function wp_codebox_bench_plugin_value(): int { return 7; } + +add_action( + 'rest_api_init', + static function (): void { + register_rest_route( + 'wp-codebox-bench/v1', + '/value', + array( + 'methods' => 'GET', + 'callback' => static fn (): array => array( 'value' => wp_codebox_bench_plugin_value() ), + 'permission_callback' => '__return_true', + ) + ); + } +); diff --git a/examples/bench-plugin/tests/bench/noop.php b/examples/bench-plugin/tests/bench/noop.php index b28105d..3c5d2bc 100644 --- a/examples/bench-plugin/tests/bench/noop.php +++ b/examples/bench-plugin/tests/bench/noop.php @@ -1,9 +1,13 @@ response_to_data( $response, false ); + return array( 'metrics' => array( - 'fixture_value' => wp_codebox_bench_plugin_value(), + 'fixture_value' => wp_codebox_bench_plugin_value(), + 'rest_route_visible' => isset( $data['value'] ) && 7 === (int) $data['value'] ? 1 : 0, ), 'metadata' => array( 'fixture' => 'bench-plugin', diff --git a/packages/runtime-playground/src/bench-command-handlers.ts b/packages/runtime-playground/src/bench-command-handlers.ts index dfa50bf..ac64b34 100644 --- a/packages/runtime-playground/src/bench-command-handlers.ts +++ b/packages/runtime-playground/src/bench-command-handlers.ts @@ -155,6 +155,10 @@ foreach ($plugins_to_activate as $plugin_to_activate) { throw new RuntimeException($activation->get_error_message()); } } +if (did_action('rest_api_init')) { + $GLOBALS['wp_rest_server'] = null; + do_action('rest_api_init', rest_get_server()); +} function wp_codebox_bench_run_configured_workload(array $workload, string $plugin_path) { $steps = isset($workload['run']) && is_array($workload['run']) ? $workload['run'] : array($workload); diff --git a/scripts/recipe-bench-smoke.ts b/scripts/recipe-bench-smoke.ts index df01d1c..26af69a 100644 --- a/scripts/recipe-bench-smoke.ts +++ b/scripts/recipe-bench-smoke.ts @@ -87,6 +87,7 @@ assert.equal(scenario.id, "noop") assert.equal(scenario.file, "tests/bench/noop.php") assert.equal(scenario.iterations, 2) assert.equal(scenario.metrics.fixture_value_mean, 7) +assert.equal(scenario.metrics.rest_route_visible_mean, 1) assert.equal(scenario.metadata.fixture, "bench-plugin") const configured = output.benchResults.scenarios[1] assert.equal(configured.id, "configured-env") From 9aac939c6467e6ad4af1c0f0002f3cdf5731007d Mon Sep 17 00:00:00 2001 From: Chris Huber Date: Mon, 1 Jun 2026 15:10:40 -0400 Subject: [PATCH 2/2] fix: replay plugin load hooks for bench runs --- packages/runtime-playground/src/bench-command-handlers.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/runtime-playground/src/bench-command-handlers.ts b/packages/runtime-playground/src/bench-command-handlers.ts index ac64b34..bfce4c0 100644 --- a/packages/runtime-playground/src/bench-command-handlers.ts +++ b/packages/runtime-playground/src/bench-command-handlers.ts @@ -155,6 +155,10 @@ foreach ($plugins_to_activate as $plugin_to_activate) { throw new RuntimeException($activation->get_error_message()); } } +if (!empty($plugins_to_activate)) { + do_action('plugins_loaded'); + do_action('init'); +} if (did_action('rest_api_init')) { $GLOBALS['wp_rest_server'] = null; do_action('rest_api_init', rest_get_server());