Skip to content

fix(wordpress-source): fall back to official mirrors when the release host is unreachable and emit structured JSON errors - #2593

Closed
chubes4 wants to merge 1 commit into
mainfrom
fix/wordpress-source-lab
Closed

chubes4 wants to merge 1 commit into
mainfrom
fix/wordpress-source-lab

Conversation

@chubes4

@chubes4 chubes4 commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

Summary

wp-codebox wordpress-source --json exited 1 on a Linux CI runner, so host-PHP smoke tests and PHPUnit gates that depend on it got no WordPress core source (PHPUnit then discovered zero tests).

Root cause: for latest, the WordPress release API returns a downloads.w.org/release/wordpress-X.Y.Z.zip URL. That host was unreachable from the runner's network (connect EHOSTUNREACH), while downloads.wordpress.org and wordpress.org were reachable. The archive cache downloader tried exactly one URL, so one unreachable host made every cache miss fatal. The only error was a bare fetch failed, and --json printed nothing on stdout.

What changed

  • Mirror fallback (playground-cli-runner.ts): on a cache miss, the downloader now tries the URL the API returned, then https://downloads.wordpress.org/release/wordpress-<v>.zip, then https://wordpress.org/wordpress-<v>.zip. These mirrors are only added for release-shaped versions (including beta/RC), not for custom archive URLs. The first valid archive wins, and the source it came from is recorded as the cache validation sourceUrl. This also fixes Playground boot on the same networks, since it uses the same resolver.
  • Actionable network errors: undici's bare fetch failed now includes its cause (e.g. EHOSTUNREACH: connect EHOSTUNREACH …). When every source fails, one error names each URL and why it failed.
  • Structured --json errors (wordpress-source command): with --json, a failure now prints a single object to stdout: { "schema": "wp-codebox/wordpress-source/v1", "error": { "code", "message", "requestedVersion", "sourceUrl"? } }. The stable codes are wordpress-source-download-failed, wordpress-source-release-unresolved, wordpress-source-cache-locked, wordpress-source-invalid-version, wordpress-source-materialization-failed and wordpress-source-invalid-arguments.
    • Exit codes are unchanged: 1 means the source could not be materialized, 2 means bad arguments.
    • The one-line reason on stderr is unchanged.
    • Plain (non-JSON) output still keeps stdout empty on failure.
    • The success payload is unchanged. Error objects never include root, so existing callers that check .schema + .root still see the failure.

Verification

  • Before, on the affected Linux runner, with the managed WP Codebox build v0.33.0 that the WordPress extension resolves:
    • wordpress-source --json exited 1 with Unable to resolve Playground startup asset wordpress-archive-cache for WordPress 7.1.5 from https://downloads.w.org/release/wordpress-7.1.5.zip: fetch failed.
    • Node fetch to that URL failed with EHOSTUNREACH, and curl could not connect to it either.
    • curl -I to downloads.wordpress.org/release/wordpress-7.1.5.zip, wordpress.org/wordpress-7.1.5.zip and the version-check API each returned 200.
  • npm run build: passes.
  • tsx tests/wordpress-source.test.ts: passes. New coverage:
    • the mirror order for a downloads.w.org release URL, for RC versions, and for custom URLs (no mirrors);
    • an unreachable primary host falling through to downloads.wordpress.org, with the cache and source materialized and sourceUrl reporting the mirror;
    • every source unreachable, giving one error that names each URL and EHOSTUNREACH, with no archive left behind;
    • --json failures returning wordpress-source-download-failed, -materialization-failed, -invalid-version and -invalid-arguments, while plain failures keep stdout empty.
  • Also passing: tests/playground-wordpress-release-cache.test.ts, tests/playground-custom-archive-cache.test.ts, tests/playground-custom-archive-cache-process.test.ts, tests/archive-cache-orphaned-lease.test.ts and scripts/cli-json-failure-smoke.ts.
  • Built CLI run locally (macOS): wordpress-source --json returns the 7.1.5 source. --wp trunk --json exits 1 with the wordpress-source-invalid-version error object.

AI disclosure

Written by Claude (Anthropic) as a Pi subagent, dispatched directly (outside Homeboy Cook) at @chubes4's request; Claude wrote the code and tests.

… host is unreachable and emit structured JSON errors
chubes4 added a commit to Extra-Chill/homeboy that referenced this pull request Nov 23, 2026
…ved WordPress source, and zero-test suites (#18838)

## Summary

Three hardening changes to the bundled WordPress and Node.js extensions.
Each one targets a failure that a recent Lab Cook hit without explaining
it: a missing shared install helper, an unresolved WordPress source, and
a PHPUnit run that executed zero tests.

Refs Automattic/wp-codebox#2593

## What changed

**1. Shared helper guard**
- `extensions/wordpress/scripts/deps/deps-runner.sh`,
`extensions/nodejs/scripts/deps/deps-runner.sh` and
`extensions/wordpress/scripts/lib/local-workspace-prepare.mjs` now check
that the shared `scripts/lib/local-workspace-install.sh` exists before
using it. It is a shared asset from
`extensions/homeboy-extension-root.json`.
- If the file is missing, each one fails before running the package
manager. The error names the expected shared path and the fix: `homeboy
extension install https://github.com/Extra-Chill/homeboy --id
<wordpress|nodejs>`. Before this change you got a bare `No such file or
directory` followed by `npm ci` exit 1.

**2. wordpress-source error detail**
- When `wp-codebox wordpress-source --json` exits non-zero,
`homeboy_wp_codebox_wordpress_source()` now reads the structured
`{schema, error:{code,message}}` envelope from stdout first. It puts
`code: message` into `HOMEBOY_WP_CODEBOX_WORDPRESS_SOURCE_ERROR`.
- Older wp-codebox builds print nothing on stdout. For those it falls
back to the last stderr line, as it did before.

**3. No silent zero-test runs**
- New boolean setting `standalone_php_requires_wordpress_core` (default
`false`). When it is set and the WordPress source cannot be resolved,
the standalone PHP step fails up front with `ERROR: WordPress core
source could not be resolved ...: <reason>`, and the unrun smokes count
as failed. Without the setting the behavior stays as it was: one warning
line. In both cases, failing standalone smokes now print a `NOTE:`
repeating the resolution reason whenever core was unavailable.
- In the WP Codebox PHPUnit adapter, a sandbox suite whose PHPUnit
config declares `<directory>` entries that contain test files on disk
now fails when it executes zero tests. It prints
`PHPUNIT_ZERO_TESTS_FAILED: suite "<name>" declares N test file(s) under
<dirs> but PHPUnit executed 0 tests`. Before, the default
`phpunit_no_tests` policy reported it as skipped.
- An explicit `phpunit_no_tests` setting still wins. Homeboy merges
manifest defaults into `HOMEBOY_SETTINGS_JSON`, so "explicit" could not
be detected while the default was `"skipped"`. The manifest default is
now `""`. Unset still behaves as `skipped` everywhere else
(`test-runner.sh` and `normalizedTestStatus`).
- Suites whose declared directories contain no test files still get the
default skip.
- Docs: `README.md`, `docs/TESTING.md` and the `wordpress.json` setting
descriptions are updated.

**Tests**
- New
`extensions/wordpress/tests/shared-install-helper-missing-smoke.sh`:
simulates an installed layout whose shared `scripts/lib` lacks the
helper. Both deps runners and the prepare-step bridge must fail with the
clear message, without the bare source error and without running the
package manager.
- Extended
`extensions/wordpress/scripts/test/standalone-wordpress-core-root-smoke.sh`:
  - A structured stdout error must win over the stderr line.
- With `standalone_php_requires_wordpress_core`, an unresolved source
(structured error and offline cases) must fail the step, include the
reason, and not run the smokes.
  - A resolved source must still run the smokes normally.
- New
`extensions/wordpress/tests/wp-codebox-phpunit-declared-zero-tests-smoke.mjs`,
using a fake wp-codebox CLI:
  - Declared suite with test files and zero executed: fails.
  - Explicit `phpunit_no_tests: skipped`: skips.
  - Explicit `phpunit_no_tests: fail`: fails.
  - Declared directories with no test files: default skip.
- The new tests are registered in `extensions/wordpress/homeboy.json`
self-checks.

## Verification

Per operator instruction, no `cargo build/test/check/clippy` was run.

Run locally:
- `bash -n` on every changed or new shell file, and `node --check` on
the changed or new `.mjs` files.
- `shellcheck` on the changed shell files: no new findings. The warning
count is the same or lower than on `main` for each file.
- `bash
extensions/wordpress/tests/shared-install-helper-missing-smoke.sh`:
passes. It fails against the `main` versions of the three changed files.
- `bash
extensions/wordpress/scripts/test/standalone-wordpress-core-root-smoke.sh`:
passes. It fails against the `main` versions of `wp-codebox-paths.sh`
and `test-runner.sh`.
- `node
extensions/wordpress/tests/wp-codebox-phpunit-declared-zero-tests-smoke.mjs`:
passes. It fails against the `main` adapter.
- Regression runs that pass:
- Shell smokes: `local-workspace-deps-lifecycle-smoke.sh` (wordpress),
`local-workspace-deps-install-smoke.sh` (nodejs),
`full-suite-no-phpunit-smoke.sh`,
`standalone-php-failure-evidence-smoke.sh`,
`standalone-dependency-env-smoke.sh`,
`test-runner-file-routing-smoke.sh`,
`test-inventory-standalone-smoke.sh`,
`wp-codebox-cli-resolution-smoke.sh`.
- Adapter smokes:
`wp-codebox-phpunit-{bounded-output,evidence,host-suite,managed-default-suite,managed-selection,multi-suite,multisite,recipe-run-ledger,runtime-crash,runtime-service-diagnosis,timeout-diagnostics,timeout-options}-smoke.mjs`
and `wp-codebox-database-service-smoke.mjs`.
- Local setup needed for these runs:
- The runner smokes need Homeboy's runtime helper env vars, so I pointed
`HOMEBOY_RUNTIME_*` at the in-repo
`crates/homeboy-core/src/extension/runtime/*.sh` files.
- The adapter smokes need a stubbed
`extensions/wordpress/vendor/{autoload.php,wp-phpunit/wp-phpunit}`. It
was created only for the run, removed afterwards, and not committed.
- Not verified locally: `wp-codebox-phpunit-aggregate-smoke.mjs` needs
the real composer `vendor/bin/phpunit`.
`wp-codebox-phpunit-target-activation-smoke.mjs` needs
`HOMEBOY_RUNTIME_SETTINGS_HELPER` from the harness. Both fail the same
way on unmodified `main` in this environment. The aggregate smoke's
zero-test cases set `phpunit_no_tests` explicitly, so the new rule
leaves them unchanged.

## AI disclosure
Written by Claude (Anthropic) as a Pi subagent, dispatched directly
(outside Homeboy Cook) at @chubes4's request; Claude wrote the code and
tests.
@chubes4

chubes4 commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator Author

Closing: the Lab's egress allowlist now includes downloads.w.org, so wordpress-source works there without code changes. Download fallbacks are not needed. AI assistance: Franklin (Anthropic Claude via Roadie/Pi), directed by Chris Huber.

@chubes4 chubes4 closed this Nov 23, 2026
@chubes4
chubes4 deleted the fix/wordpress-source-lab branch November 23, 2026 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant