wpcomsh: Add unauthenticated REST endpoint for Gutenberg version#48147
wpcomsh: Add unauthenticated REST endpoint for Gutenberg version#48147
Conversation
Introduce `GET /wpcomsh/v1/gutenberg-version`, gated by the
`gutenberg-version-endpoint` site sticker via
`wpcomsh_is_site_sticker_active()` so only designated test sites
expose it. Returns `{ "version": "<GUTENBERG_VERSION>" }` or
`{ "version": null }` when the plugin isn't active.
Used by the team `gbstatus` tool to report Gutenberg versions across
Atomic edge and production without requiring per-site application
passwords.
Co-Authored-By: Claude <noreply@anthropic.com>
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! Wpcomsh plugin:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
Code Coverage SummaryCoverage changed in 11 files. Only the first 5 are listed here.
1 file is newly checked for coverage.
|
Cover route registration, response shape, and permission callback behavior (with and without the `gutenberg-version-endpoint` sticker) using the existing `Atomic_Persistent_Data` test mock. Co-Authored-By: Claude <noreply@anthropic.com>
The permission callback tests use the `Atomic_Persistent_Data` mock's `set()`/`delete()` methods, which don't exist on the real class that runs under the `wpcloud` testsuite. Exclude the test from `wpcloud` and add it to `other`, matching the existing pattern used by FrontendNoticesTest, WpcomFeaturesTest, etc. Co-Authored-By: Claude <noreply@anthropic.com>
…point tests Phan analyzes against the production `Atomic_Persistent_Data` class, which lacks the `set()`/`delete()` methods that only exist on the test mock. Match the existing suppression pattern used for FrontendNoticesTest, PlanNoticesTest, WpcomFeaturesTest, and FeatureHookTest. Co-Authored-By: Claude <noreply@anthropic.com>
…f a blog sticker Blog stickers require an allowlist entry in wpcom's `atomic_site_stickers()` before they propagate to `Atomic_Persistent_Data` on the Atomic side, which makes enabling the endpoint a cross-repo operation. A WP option set via WP-CLI on each designated site is a simpler, self-contained toggle and removes the need for the test mock, so the tests can now run in the wpcloud testsuite and the phan suppression is no longer needed. Co-Authored-By: Claude <noreply@anthropic.com>
The WoA edge cache was serving stale 401/200 responses after the `wpcomsh_expose_gutenberg_version` option was toggled, because unauthenticated REST responses don't get `Cache-Control: no-cache` by default. Filter `rest_post_dispatch` to attach no-cache headers to responses for this route (covers both the 200 success path and the 401 permission-denied path). Co-Authored-By: Claude <noreply@anthropic.com>
paulopmt1
left a comment
There was a problem hiding this comment.
It's working as expected @markbiek. Thanks for thinking of ways to improve the Gutenberg deployment process!
Just to confirm that we want this only on Atomic sites, otherwise, if we want it also on simple sites, the jetpack-mu-plugin would be the place for this.
| ) | ||
| ); | ||
|
|
||
| add_filter( 'rest_post_dispatch', 'wpcomsh_rest_api_gutenberg_version_nocache', 10, 3 ); |
There was a problem hiding this comment.
Can you check if this feedback makes a difference here?
The rest_post_dispatch filter runs for every REST response site-wide, just to do a single string comparison on routes that don't match. Negligible cost, but scoping is slightly noisier than needed.
Alternative: register the filter from inside the route callback, or use rest_pre_serve_request / a route-specific hook.
Co-authored-by: Paulo Marcos Trentin <paulo@paulotrentin.com.br>
That's correct! We can get the Gutenberg version information for Simple sites from a different source. |



Proposed changes
Adds
GET /wpcomsh/v1/gutenberg-version, a minimal endpoint that reports the active Gutenberg plugin version on sites where it's explicitly enabled. This will be used by thegbstatusscript that's still in development.{ "version": "<GUTENBERG_VERSION>" }, or{ "version": null }when the plugin isn't activewpcomsh_expose_gutenberg_versionWP option. Sites where this option is not truthy return 401. Enable per site via WP-CLI.Cache-Control: no-cache, no-store, must-revalidate, max-age=0on both success and error responses so the option state is respected promptly. The WoA edge cache may still serve a stale response for a brief window; callers should include a cache-buster query param (e.g.?cb=<timestamp>) to be safe.Does this pull request change what data or activity we track or use?
No
Testing instructions
Install this branch on a WoA test site (see comment below for Jetpack Beta Tester steps; you'll need
define( 'JETPACK_AUTOLOAD_DEV', true );inwp-config.phpon WoA). All subsequentcurlexamples use a timestamp query param to sidestep the WoA edge cache.With no option set, confirm the endpoint returns 401:
Enable the option on the site by ssh'ing into the site and running:
Confirm the endpoint now returns
{ "version": "<some version>" }(or{ "version": null }if Gutenberg isn't active):Delete the option and confirm the endpoint returns 401 again:
Co-Authored-By: Claude noreply@anthropic.com