Skip to content

build: stabilize the wp-env utilities - #597

Open
dcalhoun wants to merge 6 commits into
trunkfrom
fix/stabilize-wp-env-utilities
Open

build: stabilize the wp-env utilities#597
dcalhoun wants to merge 6 commits into
trunkfrom
fix/stabilize-wp-env-utilities

Conversation

@dcalhoun

@dcalhoun dcalhoun commented Aug 21, 2026

Copy link
Copy Markdown
Member

What?

Three failure modes in the wp-env make 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-start produced an environment the demo apps couldn't authenticate against, and recovering from a wedged server meant running lsof and kill by hand.

Stale credentials. The Playground runtime has no persistent database. Every start replays the Blueprint into a fresh database, recreating the admin user 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 stop and wp-env status trust the PID file alone, so afterwards they report ✔ Stopped and status: stopped while the server keeps serving.

Android targets. wp-env-android and wp-env-android-reset called wp-env-start with no stop first, 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/me with the stored auth header; reuse on a clean 200, regenerate otherwise. This removes RESET, 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 a port key in .wp-env.json are all honoured. bin/wp-env-setup.sh resolves the port the same way, so provisioning follows the site when it moves.

Android — one wp-env-android-urls target taking MODE=on|off. No restart, so content and credentials survive. With no MODE it 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.

Cleanwp-env destroy stops only the server named by its PID file, so it can report success while a server keeps holding the port. wp-env-clean runs the same check afterwards and reports anything still listening, so the next start does not fail on it.

Testing Instructions

  1. make wp-env-start — environment starts, credentials provisioned.
  2. make wp-env-start again — reports "already running" and finishes in seconds, noting that applying .wp-env.json changes needs a stop first. (Previously: EADDRINUSE, orphaned server.)
  3. make wp-env-stop, then make 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.)
  4. make wp-env-android-urls — reports off and suggests MODE=on.
  5. 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.
  6. 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.

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
@github-actions github-actions Bot added the [Type] Bug An existing feature does not function as intended label Aug 21, 2026
@dcalhoun dcalhoun changed the title fix: stabilize the wp-env utilities build: stabilize the wp-env utilities Aug 21, 2026
@dcalhoun dcalhoun added [Type] Build Tooling Issues or PRs related to build tooling and removed [Type] Bug An existing feature does not function as intended labels Aug 21, 2026
@wpmobilebot

wpmobilebot commented Aug 21, 2026

Copy link
Copy Markdown

XCFramework Build

This PR's XCFramework is available for testing. Add the following to your Package.swift:

.package(url: "https://github.com/wordpress-mobile/GutenbergKit", branch: "pr-build/597")

Built from c6c82d5

dcalhoun and others added 4 commits August 21, 2026 16:03
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
dcalhoun force-pushed the fix/stabilize-wp-env-utilities branch from 19f593d to c5a3080 Compare August 21, 2026 20:04
@dcalhoun
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.
Comment thread .wp-env.json
"mappings": {
"wp-content/mu-plugins": "./wp-env/mu-plugins"
},
"testsEnvironment": false,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
dcalhoun requested a review from nbradbury August 21, 2026 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Build Tooling Issues or PRs related to build tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants