build: stabilize the wp-env utilities - #597
Open
dcalhoun wants to merge 6 commits into
Open
Conversation
The Playground runtime has no persistent database, so every restart rebuilds WordPress from the Blueprint, recreating the admin user and discarding its application password. The credentials file is the one artifact that survives, so skipping setup when it exists guaranteed stale credentials after any stop/start cycle. Probe the REST API with the stored auth header instead, and regenerate on anything other than a clean 200. This makes `make wp-env-start` genuinely idempotent and removes the need for RESET=1, which existed only to force regeneration the probe now handles automatically. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GgetvxupoEHcxZzDhNE9Ko
XCFramework BuildThis PR's XCFramework is available for testing. Add the following to your .package(url: "https://github.com/wordpress-mobile/GutenbergKit", branch: "pr-build/597")Built from c6c82d5 |
Starting a second Playground server while one holds the port fails with EADDRINUSE, and wp-env deletes the PID file as it unwinds the failed start — even when that file names the healthy server already running. Both `wp-env stop` and `wp-env status` trust the PID file alone, so they then report success and "stopped" while the server keeps serving. The only way out was finding and killing the process by hand. Check the port before starting. When the running server is ours, skip the start and fall through to credential verification, making repeated `make wp-env-start` calls safe. When the port is held by an untracked process, report the PIDs and command lines along with the command that stops them, then exit. The guard reports rather than stopping anything itself. Each worktree gets its own work directory, and so its own PID file, while contending for one port, so a process holding it may be another worktree's healthy site. Telling them apart needs a person, and stopping the wrong one interrupts work elsewhere. The port and work directory come from wp-env's own config loader, so WP_ENV_HOME, WP_ENV_PORT, and a "port" key in .wp-env.json are honoured rather than assumed. `wp-env-clean` runs the same check, since `destroy` stops only the server its PID file names. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GgetvxupoEHcxZzDhNE9Ko
The mu-plugins directory is mounted into the running server, so dropping the URL override in or out takes effect on the next request. Restarting was never required: it rebuilt the site from scratch, discarding content and credentials, to apply a change the running server picks up on its own. Replace `wp-env-android` and `wp-env-android-reset` with a single `wp-env-android-urls` target taking MODE=on|off, mirroring the shape of `wp-env-media-failure`. Calling it with no MODE reports the current setting, which previously required inspecting the mu-plugins directory. The rename adds the noun the old name lacked. `wp-env-android` read as a mode you switch the whole environment into, obscuring that it changes only WordPress's URL output — the app's own credentials remap is separate and automatic. Documentation moves off the images-only framing for the same reason: block editor assets, theme styles, and REST links all remap too. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GgetvxupoEHcxZzDhNE9Ko
"remove all data (fresh start)" implied the site data was otherwise durable. It is not: the Playground runtime rebuilds from the Blueprint on every start, so content is already discarded by a plain stop. What destroy uniquely removes is the downloaded WordPress core, plugin, and theme files. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GgetvxupoEHcxZzDhNE9Ko
The setup script hardcoded localhost:8888 while the docs told users to change the port in .wp-env.json, so following that advice pointed provisioning at a site that had moved. Resolve the port from wp-env, as the guard now does. Also correct the command table's description of wp-env-clean, which claimed it removes "all local files" while the target's own help scopes it to downloaded WordPress, plugin, and theme files. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GgetvxupoEHcxZzDhNE9Ko
dcalhoun
force-pushed
the
fix/stabilize-wp-env-utilities
branch
from
August 21, 2026 20:04
19f593d to
c5a3080
Compare
dcalhoun
marked this pull request as ready for review
August 21, 2026 20:12
Added to address a deprecation warning: > ⚠ Warning: wp-env starts both development and tests environments by default. > This behavior is deprecated and will be removed in a future version. > To avoid this warning, add "testsEnvironment": false to your .wp-env.json. > The "env", "testsPort", and "testsEnvironment" options are also deprecated. > Use the --config option with a separate config file for test environments instead.
dcalhoun
commented
Aug 21, 2026
| "mappings": { | ||
| "wp-content/mu-plugins": "./wp-env/mu-plugins" | ||
| }, | ||
| "testsEnvironment": false, |
Member
Author
There was a problem hiding this comment.
Added to address a deprecation warning:
⚠ Warning: wp-env starts both development and tests environments by default.
This behavior is deprecated and will be removed in a future version.
To avoid this warning, add "testsEnvironment": false to your .wp-env.json.
The "env", "testsPort", and "testsEnvironment" options are also deprecated.
Use the --config option with a separate config file for test environments instead.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Three failure modes in the
wp-envmake targets: credentials went stale after every restart, a mistimed start could orphan the Playground server and wedge the environment, and the Android URL targets triggered that orphan by design.Why?
make wp-env-startproduced an environment the demo apps couldn't authenticate against, and recovering from a wedged server meant runninglsofandkillby hand.Stale credentials. The Playground runtime has no persistent database. Every start replays the Blueprint into a fresh database, recreating the
adminuser and discarding its application password. The credentials file is the one artifact that survives — so skipping setup when that file exists guaranteed stale credentials after any stop/start.Orphaned server. Starting a second server fails with
EADDRINUSE, and wp-env unlinks the PID file as it unwinds — including when that file names the healthy server still running.wp-env stopandwp-env statustrust the PID file alone, so afterwards they report✔ Stoppedandstatus: stoppedwhile the server keeps serving.Android targets.
wp-env-androidandwp-env-android-resetcalledwp-env-startwith nostopfirst, which is exactly the double-start above. The restart was never needed: mu-plugins are mounted into the running server, so the toggle applies on the next request.How?
Credentials — probe
/wp/v2/users/mewith the stored auth header; reuse on a clean200, regenerate otherwise. This removesRESET, which existed only to force the regeneration the probe now handles.Guard — check the port before starting (
bin/wp-env-guard.sh). Ours running → skip the start, verify credentials. Untracked process → report the PIDs, their command lines, and the command that stops them, then exit.It reports rather than stopping anything itself. Each worktree tracks its own environment while sharing one port, so a process holding it may be another worktree's healthy site; telling them apart needs a person, and stopping the wrong one interrupts work elsewhere.
The port and work directory come from wp-env's own config loader, so
WP_ENV_HOME,WP_ENV_PORT, and aportkey in.wp-env.jsonare all honoured.bin/wp-env-setup.shresolves the port the same way, so provisioning follows the site when it moves.Android — one
wp-env-android-urlstarget takingMODE=on|off. No restart, so content and credentials survive. With noMODEit reports the current setting and suggests the flag to change it. Docs move off the images-only framing, since block editor assets, theme styles, and REST links all remap too.Clean —
wp-env destroystops only the server named by its PID file, so it can report success while a server keeps holding the port.wp-env-cleanruns the same check afterwards and reports anything still listening, so the next start does not fail on it.Testing Instructions
make wp-env-start— environment starts, credentials provisioned.make wp-env-startagain — reports "already running" and finishes in seconds, noting that applying.wp-env.jsonchanges needs a stop first. (Previously:EADDRINUSE, orphaned server.)make wp-env-stop, thenmake wp-env-start. Open http://localhost:8888/wp-admin/ and confirm the editor loads. In the iOS or Android demo app, open Local WordPress and confirm it connects. (Previously: failed to authenticate.)make wp-env-android-urls— reportsoffand suggestsMODE=on.make wp-env-android-urls MODE=on— returns immediately, no restart. Rebuild the Android app, open Local WordPress in the emulator, and confirm images and block assets load.make wp-env-android-urls MODE=off— reverts; http://localhost:8888/wp-admin/ loads in a browser again.Accessibility Testing Instructions
N/A — developer tooling, no UI changes.