From d10e7d4418036f5b3d044514def572c51e26f06a Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 20 Sep 2026 16:51:52 +0000 Subject: [PATCH] Make spotlight stage test deterministic The "Use spotlight mode to filter out the zero-ish values" scenario expected `wp_loaded:after` to survive `--spotlight`. That pseudo-hook only covers the gap between the end of the `wp_loaded` hook and the end of WordPress bootstrap, so its metrics are usually zero-ish and it was kept or dropped purely depending on machine timing, causing the test to fail intermittently. Add a mu-plugin that runs a database query on `init` and `wp_loaded`, so those hooks always have a non-zero `query_count`, and assert on those rows instead. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_01KMXj3JCBjdNqDouLgzeKSy --- features/profile-stage.feature | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/features/profile-stage.feature b/features/profile-stage.feature index 54588cd4..45954b37 100644 --- a/features/profile-stage.feature +++ b/features/profile-stage.feature @@ -151,6 +151,18 @@ Feature: Profile the template render stage Scenario: Use spotlight mode to filter out the zero-ish values Given a WP install + # Run a query on these hooks so they always have a non-zero metric, + # regardless of how fast the machine running the tests is. + And a wp-content/mu-plugins/spotlight-test.php file: + """ + query( 'SELECT 1 AS spotlight_test' ); + } + add_action( 'init', 'wp_cli_profile_spotlight_query' ); + add_action( 'wp_loaded', 'wp_cli_profile_spotlight_query' ); + """ When I run `wp profile stage bootstrap --fields=hook` Then STDOUT should be a table containing rows: @@ -164,7 +176,7 @@ Feature: Profile the template render stage Then STDOUT should be a table containing rows: | hook | | init | - | wp_loaded:after | + | wp_loaded | @require-wp-4.0 Scenario: Admin URL runs as a backend request and skips frontend stages