From b890ae00711cec5297d112cd5b94e249b956eaf7 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 20 Aug 2026 07:30:45 +0000 Subject: [PATCH] Tests: mock the Version Check API where a minor update must be on offer Three scenarios install WordPress, downgrade core to an older release and then expect wordpress.org to offer an in-branch (minor) update for it: * core-check-update.feature "Check for update via Version Check API" * core-update.feature "Update to the latest minor release" * core-update.feature "Update WordPress locale when using --minor" Whether that offer is returned at all is decided per site: the Version Check API buckets sites by the URL sent in the `wp_install` request header and only serves the in-branch `autoupdate` offers to some of them. Every test site is installed at the same URL, so all jobs share one bucket, and the bucketing is reshuffled with every WordPress release. After the WordPress 7.1 release that bucket stopped receiving the offers, leaving `wp core check-update` with only the major update to report and `wp core update --minor` with nothing to update to, and all Behat jobs failed on exactly these three scenarios. Mock the version-check response in those scenarios so they no longer depend on which bucket the test site lands in. The offered packages are real, so the updates are still performed against real archives, and the expected versions are now fixed instead of tracking whatever wordpress.org currently considers the latest release of a branch. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_011sevK5u2P9Egf2Vae5QRu6 --- features/core-check-update.feature | 29 +++++++++++++++++++++++++---- features/core-update.feature | 24 ++++++++++++++++++++++-- 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/features/core-check-update.feature b/features/core-check-update.feature index 63877dbf..8a5e9ac2 100644 --- a/features/core-check-update.feature +++ b/features/core-check-update.feature @@ -5,13 +5,26 @@ Feature: Check for more recent versions Scenario: Check for update via Version Check API Given a WP install And I try `wp theme install twentytwenty --activate` + # The Version Check API only offers in-branch (minor) updates to a subset of + # sites, bucketed by the site URL, so the response is mocked to stay stable. + And that HTTP requests to https://api.wordpress.org/core/version-check/1.7/ will respond with: + """ + HTTP/1.1 200 OK + Content-Type: application/json + + {"offers":[{"response":"upgrade","download":"https://downloads.wordpress.org/release/wordpress-6.0.zip","locale":"en_US","packages":{"full":"https://downloads.wordpress.org/release/wordpress-6.0.zip","no_content":false,"new_bundled":false,"partial":false,"rollback":false},"current":"6.0","version":"6.0","php_version":"5.6.20","mysql_version":"5.0"},{"response":"autoupdate","download":"https://downloads.wordpress.org/release/wordpress-5.8.1.zip","locale":"en_US","packages":{"full":"https://downloads.wordpress.org/release/wordpress-5.8.1.zip","no_content":false,"new_bundled":false,"partial":"https://downloads.wordpress.org/release/wordpress-5.8.1-partial-0.zip","rollback":false},"current":"5.8.1","version":"5.8.1","php_version":"5.6.20","mysql_version":"5.0"}]} + """ When I run `wp core download --version=5.8 --force` Then STDOUT should not be empty When I run `wp core check-update --format=csv` - Then STDOUT should match #{WP_VERSION-latest},major,https://downloads.(w|wordpress).org/release/wordpress-{WP_VERSION-latest}.zip# - And STDOUT should match #{WP_VERSION-5.8-latest},minor,https://downloads.(w|wordpress).org/release/wordpress-{WP_VERSION-5.8-latest}-partial-0.zip# + Then STDOUT should be: + """ + version,update_type,package_url + 5.8.1,minor,https://downloads.wordpress.org/release/wordpress-5.8.1-partial-0.zip + 6.0,major,https://downloads.wordpress.org/release/wordpress-6.0.zip + """ When I run `wp core check-update --format=count` Then STDOUT should be: @@ -20,7 +33,11 @@ Feature: Check for more recent versions """ When I run `wp core check-update --major --format=csv` - Then STDOUT should match #{WP_VERSION-latest},major,https://downloads.(w|wordpress).org/release/wordpress-{WP_VERSION-latest}.zip# + Then STDOUT should be: + """ + version,update_type,package_url + 6.0,major,https://downloads.wordpress.org/release/wordpress-6.0.zip + """ When I run `wp core check-update --major --format=count` Then STDOUT should be: @@ -29,7 +46,11 @@ Feature: Check for more recent versions """ When I run `wp core check-update --minor --format=csv` - Then STDOUT should match #{WP_VERSION-5.8-latest},minor,https://downloads.(w|wordpress).org/release/wordpress-{WP_VERSION-5.8-latest}-partial-0.zip# + Then STDOUT should be: + """ + version,update_type,package_url + 5.8.1,minor,https://downloads.wordpress.org/release/wordpress-5.8.1-partial-0.zip + """ When I run `wp core check-update --minor --format=count` Then STDOUT should be: diff --git a/features/core-update.feature b/features/core-update.feature index 7092b0ef..60d731ab 100644 --- a/features/core-update.feature +++ b/features/core-update.feature @@ -100,6 +100,16 @@ Feature: Update WordPress core Scenario: Update to the latest minor release (PHP 7.2 compatible with WP >= 4.9) Given a WP install And I try `wp theme install twentytwenty --activate` + # The Version Check API only offers in-branch (minor) updates to a subset of + # sites, bucketed by the site URL, so the response is mocked to stay stable. + # The packages are real, so the update itself is still performed for real. + And that HTTP requests to https://api.wordpress.org/core/version-check/1.7/ will respond with: + """ + HTTP/1.1 200 OK + Content-Type: application/json + + {"offers":[{"response":"upgrade","download":"https://downloads.wordpress.org/release/wordpress-6.3.zip","locale":"en_US","packages":{"full":"https://downloads.wordpress.org/release/wordpress-6.3.zip","no_content":false,"new_bundled":false,"partial":false,"rollback":false},"current":"6.3","version":"6.3","php_version":"7.0.0","mysql_version":"5.0"},{"response":"autoupdate","download":"https://downloads.wordpress.org/release/wordpress-6.2.11.zip","locale":"en_US","packages":{"full":"https://downloads.wordpress.org/release/wordpress-6.2.11.zip","no_content":false,"new_bundled":false,"partial":false,"rollback":false},"current":"6.2.11","version":"6.2.11","php_version":"7.0.0","mysql_version":"5.0"}]} + """ When I run `wp core download --version=6.2.5 --force` Then STDOUT should contain: @@ -111,7 +121,7 @@ Feature: Update WordPress core When I try `wp core update --minor` Then STDOUT should contain: """ - Updating to version {WP_VERSION-6.2-latest} + Updating to version 6.2.11 """ And STDOUT should contain: """ @@ -128,7 +138,7 @@ Feature: Update WordPress core When I run `wp core version` Then STDOUT should be: """ - {WP_VERSION-6.2-latest} + 6.2.11 """ # This test downgrades to an older WordPress version, but the SQLite plugin requires 6.4+ @@ -547,6 +557,16 @@ Feature: Update WordPress core Scenario: Update WordPress locale when using --minor Given a WP install And an empty cache + # The Version Check API only offers in-branch (minor) updates to a subset of + # sites, bucketed by the site URL, so the response is mocked to stay stable. + # The packages are real, so the update itself is still performed for real. + And that HTTP requests to https://api.wordpress.org/core/version-check/1.7/ will respond with: + """ + HTTP/1.1 200 OK + Content-Type: application/json + + {"offers":[{"response":"autoupdate","download":"https://downloads.wordpress.org/release/wordpress-6.5.10.zip","locale":"en_US","packages":{"full":"https://downloads.wordpress.org/release/wordpress-6.5.10.zip","no_content":false,"new_bundled":false,"partial":false,"rollback":false},"current":"6.5.10","version":"6.5.10","php_version":"7.0.0","mysql_version":"5.0"}]} + """ # Using `try` in case there are checksum warnings. When I try `wp core download --version=6.5 --locale=de_DE --force`