Improve robustness of page cache test for Site Health#10855
Improve robustness of page cache test for Site Health#10855westonruter wants to merge 16 commits intoWordPress:trunkfrom
Conversation
This commit updates the page cache detection in Site Health by: - Using a stricter regex (\bhit\b) for detecting cache hits in response headers, preventing false positives (e.g., 'shit'). - Adding support for the X-Varnish header, identifying a cache hit when it contains two request IDs. - Adding documentation and source links for the supported headers. - Adding PHPUnit test cases to verify the new detection logic. Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
The x-srcache-store-status header uses 'STORE' or 'BYPASS', not 'HIT' or 'MISS'. This update ensures that 'STORE' is correctly identified as a positive page cache indicator. Also includes: - Documentation for srcache headers. - Explicit list of generic caching proxies (Squid, Go, Fastly, LiteSpeed) in comments. - Test cases for x-srcache-store-status and x-srcache-fetch-status. Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Gemini review: I have completed the review of the changes committed to the Commit ContextThe changes aim to improve the robustness of page cache detection in WordPress Site Health. Key improvements include:
Code Review
|
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
| 'x-cache-disabled' => static function ( $header_value ) { | ||
| return ( 'on' !== strtolower( $header_value ) ); | ||
| }, | ||
| 'x-srcache-store-status' => $cache_hit_callback, |
There was a problem hiding this comment.
This was incorrect. Now fixed.
| * @covers ::get_page_cache_headers() | ||
| * @covers ::check_for_page_caching() | ||
| */ | ||
| public function test_get_page_cache( $responses, $expected_status, $expected_label, $good_basic_auth = null, $delay_the_response = false ) { |
There was a problem hiding this comment.
Note that $good_basic_auth was previously only either null or false, so this is now changed to be an actual boolean with true or false.
dmsnell
left a comment
There was a problem hiding this comment.
sorry I can’t give a more thorough review at the moment. it’s nice seeing iteration on the screen.
| * @since 6.1.0 | ||
| * | ||
| * @return array List of client caching headers and their (optional) verification callbacks. | ||
| * @return array<string, ?callable> Mapping of page caching headers and their (optional) verification callbacks. |
There was a problem hiding this comment.
the previous comment explained what an empty value means, but this change removes that knowledge. was that intentional?
There was a problem hiding this comment.
I thought it was redundant, but it seems it isn't. How about this:
| * @return array<string, ?callable> Mapping of page caching headers and their (optional) verification callbacks. | |
| * @return array<string, ?callable> Mapping of page caching headers and their (optional) verification callbacks. | |
| A null value means a simple existence check is used for the header. |
| ), | ||
| 'expected_status' => 'good', | ||
| 'expected_label' => $good_label, | ||
| ), |
There was a problem hiding this comment.
because I’m not familiar with all of these systems, and don’t have any in front of me, I am not reviewing or verifying these tests.
I’m trusting that you confirmed that the responses correspond to what those projects actually produce and that the values here are factually representative.
the CommonCrawl archive would potentially be a valuable archive to mine for this kind of header behavior.
Co-authored-by: Dennis Snell <dennis.snell@automattic.com>
… value Co-authored-by: Dennis Snell <dennis.snell@automattic.com>
Co-authored-by: Dennis Snell <dennis.snell@automattic.com>
| /** | ||
| * Custom caching headers. | ||
| * | ||
| * These do not seem to be actually used by any caching layers. There were first introduced in a Site Health | ||
| * test in the AMP plugin. They were copied into the Performance Lab plugin's Site Health test before they | ||
| * were merged into core. | ||
| * | ||
| * @link https://github.com/ampproject/amp-wp/pull/6849 | ||
| * @link https://github.com/WordPress/performance/pull/263 | ||
| * @link https://core.trac.wordpress.org/changeset/54043 | ||
| */ | ||
| 'x-cache-enabled' => static function ( $header_value ) { | ||
| return 'true' === strtolower( $header_value ); | ||
| return ( 'true' === strtolower( $header_value ) ); | ||
| }, | ||
| 'x-cache-disabled' => static function ( $header_value ) { | ||
| return ( 'on' !== strtolower( $header_value ) ); | ||
| }, |
There was a problem hiding this comment.
I'm inclined to remove these entirely since it seems they were originally introduced erroneously in the AMP plugin. I can't find any caching layers that actually use them. There are a few hundred mentions of them on GitHub, nevertheless: https://github.com/search?q=%2Fx-cache-(enabled%7Cdisabled)%2F&type=code
This improves the robustness of page cache detection in Site Health by refining the response header validation and expanding support for common caching layers.
Logic & Header Improvements
$cache_hit_callbacknow uses a word-boundary regular expression (/\bhit\b/i) instead of a simple substring check. This prevents false positives from header values likeshit. 💩X-SRCache-Store-StatusCorrection: Fixed the validation for this header to check for the correct valueSTORE(the module's indicator for a successful cache storage) instead ofHIT.X-Varnishheader, specifically identifying a hit when the header contains two request IDs (e.g.,123 456), as documented in the Varnish FAQ.srcache,Varnish) and explicitly listed supported generic proxies (Squid, Go, Fastly, LiteSpeed) in comments.PHPUnit Test Enhancements
Tests_Admin_wpSiteHealthto verify:X-Varnishhits vs. misses.X-SRCache-Store-Status(STORE) andX-SRCache-Fetch-Status(HIT).x-cache: shit).ETag,Last-Modified, andVia.Code Quality
class-wp-site-health.phpand the test suite usingcomposer formatto ensure adherence to WordPress Coding Standards.Trac ticket: https://core.trac.wordpress.org/ticket/64370
Use of AI Tooling
The above PR description was drafted by Gemini, and Gemini CLI was involved in authoring some commits (as attributed via
co-authored-by).This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.