Skip to content

Commit b890ae0

Browse files
committed
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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011sevK5u2P9Egf2Vae5QRu6
1 parent 52041f6 commit b890ae0

2 files changed

Lines changed: 47 additions & 6 deletions

File tree

‎features/core-check-update.feature‎

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,26 @@ Feature: Check for more recent versions
55
Scenario: Check for update via Version Check API
66
Given a WP install
77
And I try `wp theme install twentytwenty --activate`
8+
# The Version Check API only offers in-branch (minor) updates to a subset of
9+
# sites, bucketed by the site URL, so the response is mocked to stay stable.
10+
And that HTTP requests to https://api.wordpress.org/core/version-check/1.7/ will respond with:
11+
"""
12+
HTTP/1.1 200 OK
13+
Content-Type: application/json
14+
15+
{"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"}]}
16+
"""
817

918
When I run `wp core download --version=5.8 --force`
1019
Then STDOUT should not be empty
1120

1221
When I run `wp core check-update --format=csv`
13-
Then STDOUT should match #{WP_VERSION-latest},major,https://downloads.(w|wordpress).org/release/wordpress-{WP_VERSION-latest}.zip#
14-
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#
22+
Then STDOUT should be:
23+
"""
24+
version,update_type,package_url
25+
5.8.1,minor,https://downloads.wordpress.org/release/wordpress-5.8.1-partial-0.zip
26+
6.0,major,https://downloads.wordpress.org/release/wordpress-6.0.zip
27+
"""
1528

1629
When I run `wp core check-update --format=count`
1730
Then STDOUT should be:
@@ -20,7 +33,11 @@ Feature: Check for more recent versions
2033
"""
2134

2235
When I run `wp core check-update --major --format=csv`
23-
Then STDOUT should match #{WP_VERSION-latest},major,https://downloads.(w|wordpress).org/release/wordpress-{WP_VERSION-latest}.zip#
36+
Then STDOUT should be:
37+
"""
38+
version,update_type,package_url
39+
6.0,major,https://downloads.wordpress.org/release/wordpress-6.0.zip
40+
"""
2441

2542
When I run `wp core check-update --major --format=count`
2643
Then STDOUT should be:
@@ -29,7 +46,11 @@ Feature: Check for more recent versions
2946
"""
3047

3148
When I run `wp core check-update --minor --format=csv`
32-
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#
49+
Then STDOUT should be:
50+
"""
51+
version,update_type,package_url
52+
5.8.1,minor,https://downloads.wordpress.org/release/wordpress-5.8.1-partial-0.zip
53+
"""
3354

3455
When I run `wp core check-update --minor --format=count`
3556
Then STDOUT should be:

‎features/core-update.feature‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@ Feature: Update WordPress core
100100
Scenario: Update to the latest minor release (PHP 7.2 compatible with WP >= 4.9)
101101
Given a WP install
102102
And I try `wp theme install twentytwenty --activate`
103+
# The Version Check API only offers in-branch (minor) updates to a subset of
104+
# sites, bucketed by the site URL, so the response is mocked to stay stable.
105+
# The packages are real, so the update itself is still performed for real.
106+
And that HTTP requests to https://api.wordpress.org/core/version-check/1.7/ will respond with:
107+
"""
108+
HTTP/1.1 200 OK
109+
Content-Type: application/json
110+
111+
{"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"}]}
112+
"""
103113

104114
When I run `wp core download --version=6.2.5 --force`
105115
Then STDOUT should contain:
@@ -111,7 +121,7 @@ Feature: Update WordPress core
111121
When I try `wp core update --minor`
112122
Then STDOUT should contain:
113123
"""
114-
Updating to version {WP_VERSION-6.2-latest}
124+
Updating to version 6.2.11
115125
"""
116126
And STDOUT should contain:
117127
"""
@@ -128,7 +138,7 @@ Feature: Update WordPress core
128138
When I run `wp core version`
129139
Then STDOUT should be:
130140
"""
131-
{WP_VERSION-6.2-latest}
141+
6.2.11
132142
"""
133143

134144
# This test downgrades to an older WordPress version, but the SQLite plugin requires 6.4+
@@ -547,6 +557,16 @@ Feature: Update WordPress core
547557
Scenario: Update WordPress locale when using --minor
548558
Given a WP install
549559
And an empty cache
560+
# The Version Check API only offers in-branch (minor) updates to a subset of
561+
# sites, bucketed by the site URL, so the response is mocked to stay stable.
562+
# The packages are real, so the update itself is still performed for real.
563+
And that HTTP requests to https://api.wordpress.org/core/version-check/1.7/ will respond with:
564+
"""
565+
HTTP/1.1 200 OK
566+
Content-Type: application/json
567+
568+
{"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"}]}
569+
"""
550570

551571
# Using `try` in case there are checksum warnings.
552572
When I try `wp core download --version=6.5 --locale=de_DE --force`

0 commit comments

Comments
 (0)