Detect actual, loaded WP version - #1503
Conversation
| }); | ||
|
|
||
| if (result.errors.length > 0) { | ||
| // TODO: Find a way to warn |
There was a problem hiding this comment.
You can use the logger for this
|
|
||
| if (!loadedVersion) { | ||
| // TODO: Is there something better than throwing at this stage? | ||
| return undefined; |
There was a problem hiding this comment.
Could we just return the default version?
There was a problem hiding this comment.
If this is empty, something is very wrong – like a broken or missing WordPress installation. I'd rather show a big error.
There was a problem hiding this comment.
OK, I will make this throw. That seems preferable for clarity, especially if we are planning to remove the uncertainty around requesting remote assets from older point releases. In that case, we are no longer running OK by coincidence but because we're actually doing the right thing.
|
@brandonpayton If we're loading a minified build from the browser storage, all bets are off. We might be loading WP 6.4.1 while playground.wordpress.net already has assets from 6.4.3. The files list may differ, and mixing assets from the two might lead to a broken state.
Let's always put it in the browser storage and expect to find it there. If it's missing from a minified build, that's an error. That would only happen if it gets deleted after we boot the minified bundle and before we finish downloading the zip file with the rest of the assets. Also, let's find a way to always load all the assets from 6.4.1. This will always work, but what do we do if those assets are missing from the browser storage? I have a few ideas:
|
| ): Promise<string | undefined> { | ||
| const result = await php.run({ | ||
| code: `<?php | ||
| if (is_file('${wordpressRoot}/wp-includes/version.php')) { |
There was a problem hiding this comment.
php.documentRoot should do the trick here. The entire codebase assumes WordPress lives there – if it doesn't, we have a larger problem.
There was a problem hiding this comment.
php.documentRoot should do the trick here. The entire codebase assumes WordPress lives there – if it doesn't, we have a larger problem.
Thanks, I ended up using requestHandler.documentRoot because php.documentRoot is marked as deprecated.
| `, | ||
| }); | ||
|
|
||
| if (result.errors.length > 0) { |
There was a problem hiding this comment.
AFAIR php.run() throws on failure. result.errors is just stderr
There was a problem hiding this comment.
AFAIR php.run() throws on failure. result.errors is just stderr
Thanks! Will skip considering result.errors then.
| // from browser storage is the default version when it is actually something else. | ||
| // Incorrectly assuming WP version can break things like remote asset retrieval | ||
| // for minified WP builds. | ||
| const loadedWordPressVersion = await getLoadedWordPressVersion( |
There was a problem hiding this comment.
Is this relevant for non-minified builds? Assets-wise, probably not, but it seems like it would enable displaying "6.6-nightly" in the UI, correct?
There was a problem hiding this comment.
Is this relevant for non-minified builds? Assets-wise, probably not, but it seems like it would enable displaying "6.6-nightly" in the UI, correct?
Yes, I wasn't planning to do it as part of this PR but was thinking we could show the detected version in the UI.
@adamziel the main case I am thinking of is today's browser storage contents before we started shipping the remote asset listing. If people used browser storage before then, they would not have the listing, and requests for remote assets break. It's why I reverted the second request routing attempt. We're no longer deleting that file, so it should exist for all new browser storage. But for people who are loading from older browser storage, it is broken. What do you think we should do here? Retrieve the listing file, just let it be broken, or something else? |
@adamziel nevermind, I see you are discussing that path here :)
|
I think we should do this work in the following steps, as separate PRs:
@WordPress/playground-maintainers what do you think? note: We also need to consider what to do about "nightly" as a special case. |
|
With the new unit tests, we encountered this failure in CI: Is it possible this is due to some test parallelization and shared FS? Otherwise, I'm not sure why this would be failing. The WP nightly zip here does not have a wp_version that includes the string "beta". |
The latest WP nightly build on trunk does include "beta" in its version string, which explains why the test is failing. We can't assume the nightly version contains "alpha". |
|
Since the "nightly" version is transient and unstable day-to-day, it is now explicitly skipped in the version detection unit tests. As an aside: |
0a796e6 to
fe3c268
Compare
It looks like we can still detect the nightly version. The nightly version with "beta" in the string has a numeric suffix and looks like: The actual beta version looks like: I've tightened nightly version detection and re-enabled testing for it. |
Users might bring their own builds, and we want to allow any declared version as long as it is non-empty.
|
This is ready for another review. Please see this comment for a proposed path forward. |
|
Please see this comment for the overall plan: |
|
I’ll re-review tomorrow |
| const loadedWordPressVersion = await getLoadedWordPressVersion( | ||
| requestHandler | ||
| ); | ||
| if (isSupportedWordPressVersion(loadedWordPressVersion)) { |
There was a problem hiding this comment.
With this check we won't always expose apiEndpoint.wordPressVersion which seems confusing. It makes it seem like we're not running any WordPress version if the version string doesn't match the pattern. What's an upside?
There was a problem hiding this comment.
Ah, this actually overrides the previous value of wordPressVersion. Still, can't we always override?
There was a problem hiding this comment.
Ah, this actually overrides the previous value of wordPressVersion. Still, can't we always override?
@adamziel This is the version used to download static assets. I think we should make it so that we just don't attempt static asset downloads for unsupported versions but plan to do that in a follow up PR.
There was a problem hiding this comment.
I changed my mind and updated this PR to tolerate an undefined staticAssetsDirectory when loading an unsupported WP version. It didn't seem right to land this in an in-between state.
In addition, instead of clobbering the requested WordPress version with the detected version, I made them different properties:
requestedWordPressVersionloadedWordPressVersion
adamziel
left a comment
There was a problem hiding this comment.
I've left a question about the version number check, but other than that this PR looks good to me!
Motivation for the change, related issues
When loading from browser storage, Playground can incorrectly assume the loaded WP version is the default version when it is actually something else. This can cause issues where remote assets are requested from the wrong version of WP.
In addition, this work is needed to support a follow-up PR where we retrieve the
wordpress-remote-asset-pathslisting from the website when it is not already present within browser storage.Implementation details
This PR adds two functions, one for detecting the version using
wp-includes/version.php, and another for determining whether the detected version is one of the WP versions supported through the Playground web app.These functions are used when initializing worker threads to detect the version of WP that was booted.
If detection fails, the WordPress version is left set to the default version.
Testing Instructions (or ideally a Blueprint)