|
| 1 | +# envlite — disable WP-Cron by default — implementation plan |
| 2 | + |
| 3 | +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. |
| 4 | +
|
| 5 | +**Goal:** After `envlite init`, the rendered `src/wp-config.php` defines `DISABLE_WP_CRON` as `true`, so `spawn_cron()` no longer fires a loopback request on every front-end hit served by `envlite serve` / `envlite up`. |
| 6 | + |
| 7 | +**Architecture:** One additional line injected by `envlite_phase7_render()` in the existing inject block, anchored on the same `/* That's all, stop editing! Happy publishing. */` marker. No new files, no new flags, no manifest schema changes. Spec text in `plans/ENVLITE_SPECIFICATION.md` updated to match. |
| 8 | + |
| 9 | +**Tech Stack:** PHP 7.4+, the existing test harness at `tools/local-env/tests/`, `envlite_phase7_render` / `envlite_phase7_install` in `tools/local-env/envlite.php`. |
| 10 | + |
| 11 | +**Design doc:** `plans/2026-05-11-envlite-disable-wp-cron-design.md`. |
| 12 | + |
| 13 | +--- |
| 14 | + |
| 15 | +## Background for an engineer with zero context |
| 16 | + |
| 17 | +- envlite is a PHP CLI at `tools/local-env/envlite.php` that brings a clean wordpress-develop checkout to a runnable state — see `plans/ENVLITE_SPECIFICATION.md` for the full spec. |
| 18 | +- Phase 7 (`envlite_phase7_render`, ~line 650) reads `wp-config-sample.php`, replaces DB constants, optionally swaps in fresh salts, injects two `define()` lines (`WP_HOME` / `WP_SITEURL`) immediately before the `/* That's all, stop editing! */` marker, then writes the result to `src/wp-config.php`. |
| 19 | +- WordPress's pseudo-cron mechanism fires `spawn_cron()` on every front-end HTTP request: a non-blocking loopback POST to `wp-cron.php`. Because `php -S` (envlite's runtime) serializes requests by default, that loopback is paid for on every page load with no benefit on a dev box, and creates head-of-line stalls when it is finally serviced. The fix is to define `DISABLE_WP_CRON` as `true` in the runtime config. |
| 20 | +- Phase 6 (`wp-tests-config.php`) is intentionally **not** changed — phpunit does not run inside an HTTP request lifecycle, so `spawn_cron()` is never invoked from a test run, and defining `DISABLE_WP_CRON` there would only risk interfering with cron-related tests. |
| 21 | + |
| 22 | +The codebase ships its own tiny test harness — there's no PHPUnit for envlite itself. Each test is a global function whose name starts with `test_` in `tools/local-env/tests/test_*.php`; `php tools/local-env/tests/run.php` discovers and runs them. Assertions are `envlite_assert` / `envlite_assert_eq` (defined in `tools/local-env/tests/harness.php`). |
| 23 | + |
| 24 | +--- |
| 25 | + |
| 26 | +## File structure |
| 27 | + |
| 28 | +| File | Action | Responsibility | |
| 29 | +|---|---|---| |
| 30 | +| `tools/local-env/envlite.php` | Modify (function `envlite_phase7_render` ~line 650) | Add `DISABLE_WP_CRON` to the inject block. | |
| 31 | +| `tools/local-env/tests/test_phase7.php` | Modify | New unit test asserting the line is present and positioned correctly. | |
| 32 | +| `plans/ENVLITE_SPECIFICATION.md` | Modify | Update Phase 7 step 5 inject block and add a "Why `DISABLE_WP_CRON` matters" paragraph. | |
| 33 | + |
| 34 | +No new files. No file splits. |
| 35 | + |
| 36 | +--- |
| 37 | + |
| 38 | +## Task 1: Pre-implementation sanity checks |
| 39 | + |
| 40 | +Two read-only checks the design depends on. Each is a 30-second confirmation. |
| 41 | + |
| 42 | +**Files:** read-only. |
| 43 | + |
| 44 | +- [ ] **Step 1: Confirm `wp-config-sample.php` does not already define `DISABLE_WP_CRON`.** |
| 45 | + |
| 46 | +Run: |
| 47 | +``` |
| 48 | +grep -nE "DISABLE_WP_CRON|ALTERNATE_WP_CRON|WP_CRON" wp-config-sample.php |
| 49 | +``` |
| 50 | + |
| 51 | +Expected: no output. (If the upstream sample has gained a cron-related define, the plan needs a rethink — the new inject would create a duplicate. Stop and reassess.) |
| 52 | + |
| 53 | +- [ ] **Step 2: Confirm the marker still appears exactly once in `wp-config-sample.php`.** |
| 54 | + |
| 55 | +Run: |
| 56 | +``` |
| 57 | +grep -c "That's all, stop editing" wp-config-sample.php |
| 58 | +``` |
| 59 | + |
| 60 | +Expected: `1`. (`envlite_phase7_render` already asserts this at runtime, but a hard divergence at the sample level would force a redesign of Phase 7's anchor before this plan can proceed.) |
| 61 | + |
| 62 | +No commit for this task — it's read-only verification. |
| 63 | + |
| 64 | +--- |
| 65 | + |
| 66 | +## Task 2: Add the failing test, then implement the inject |
| 67 | + |
| 68 | +Standard TDD: write the assertion, run the suite to confirm it fails, change `envlite_phase7_render`, run the suite to confirm it passes, commit. The whole task is a single commit — test plus implementation — because the test asserts a property of `envlite_phase7_render`'s output and there is nothing for the test to anchor to until the implementation lands. |
| 69 | + |
| 70 | +**Files:** |
| 71 | +- Modify: `tools/local-env/tests/test_phase7.php` |
| 72 | +- Modify: `tools/local-env/envlite.php` (function `envlite_phase7_render` ~line 696–697) |
| 73 | + |
| 74 | +- [ ] **Step 1: Write the failing test.** |
| 75 | + |
| 76 | +Append to `tools/local-env/tests/test_phase7.php`: |
| 77 | + |
| 78 | +```php |
| 79 | +function test_phase7_render_injects_disable_wp_cron_before_marker() { |
| 80 | + $sample = file_get_contents(dirname(__DIR__, 3) . '/wp-config-sample.php'); |
| 81 | + $out = envlite_phase7_render($sample, 8421, null); |
| 82 | + $cron = "define( 'DISABLE_WP_CRON', true );"; |
| 83 | + $site = "define( 'WP_SITEURL', 'http://127.0.0.1:8421' );"; |
| 84 | + $marker = "/* That's all, stop editing! Happy publishing. */"; |
| 85 | + // Exactly one occurrence of the new define. |
| 86 | + envlite_assert_eq(1, substr_count($out, $cron)); |
| 87 | + // Positioned after WP_SITEURL and before the marker. |
| 88 | + envlite_assert(strpos($out, $cron) > strpos($out, $site), 'DISABLE_WP_CRON must be after WP_SITEURL'); |
| 89 | + envlite_assert(strpos($out, $cron) < strpos($out, $marker), 'DISABLE_WP_CRON must be before marker'); |
| 90 | +} |
| 91 | +``` |
| 92 | + |
| 93 | +- [ ] **Step 2: Run the suite to verify the new test fails and nothing else regresses.** |
| 94 | + |
| 95 | +Run: |
| 96 | +``` |
| 97 | +php tools/local-env/tests/run.php |
| 98 | +``` |
| 99 | + |
| 100 | +Expected: every other test still passes; the new test fails with an assertion message from the `envlite_assert_eq(1, substr_count(...))` line because the rendered output does not yet contain the `DISABLE_WP_CRON` define. |
| 101 | + |
| 102 | +- [ ] **Step 3: Implement the inject in `envlite_phase7_render`.** |
| 103 | + |
| 104 | +In `tools/local-env/envlite.php`, locate the existing inject block in `envlite_phase7_render` (currently around lines 696–697): |
| 105 | + |
| 106 | +```php |
| 107 | + $inject = "define( 'WP_HOME', 'http://127.0.0.1:$port' );\n" |
| 108 | + . "define( 'WP_SITEURL', 'http://127.0.0.1:$port' );\n\n"; |
| 109 | +``` |
| 110 | + |
| 111 | +Replace it with: |
| 112 | + |
| 113 | +```php |
| 114 | + $inject = "define( 'WP_HOME', 'http://127.0.0.1:$port' );\n" |
| 115 | + . "define( 'WP_SITEURL', 'http://127.0.0.1:$port' );\n" |
| 116 | + . "define( 'DISABLE_WP_CRON', true );\n\n"; |
| 117 | +``` |
| 118 | + |
| 119 | +The trailing `\n\n` (the blank line separating the inject block from the marker) is preserved exactly as before. |
| 120 | + |
| 121 | +- [ ] **Step 4: Run the suite to verify everything passes.** |
| 122 | + |
| 123 | +Run: |
| 124 | +``` |
| 125 | +php tools/local-env/tests/run.php |
| 126 | +``` |
| 127 | + |
| 128 | +Expected: every test passes, including the new `test_phase7_render_injects_disable_wp_cron_before_marker`. The existing `test_phase7_render_injects_wp_home_siteurl_before_marker`, `test_phase7_render_substitutes_db_constants`, `test_phase7_render_replaces_salts_when_provided`, `test_phase7_render_keeps_sample_salts_when_null_provided`, `test_phase7_render_treats_salts_as_literal_not_backreferences`, and `test_phase7_render_normalizes_crlf_in_sample` must all still pass — the change is purely additive. |
| 129 | + |
| 130 | +- [ ] **Step 5: Commit.** |
| 131 | + |
| 132 | +```bash |
| 133 | +git add tools/local-env/envlite.php tools/local-env/tests/test_phase7.php |
| 134 | +git commit -m "feat(envlite): disable WP-Cron by default in Phase 7 runtime config" |
| 135 | +``` |
| 136 | + |
| 137 | +--- |
| 138 | + |
| 139 | +## Task 3: Update the specification |
| 140 | + |
| 141 | +The spec is the source of truth for envlite's behavior. The change to Phase 7's inject block and the "Why ... matters" paragraph need to land alongside the code so the spec doesn't drift. |
| 142 | + |
| 143 | +**Files:** |
| 144 | +- Modify: `plans/ENVLITE_SPECIFICATION.md` (Phase 7 section, ~lines 627–648) |
| 145 | + |
| 146 | +- [ ] **Step 1: Update Phase 7 step 5's inject block.** |
| 147 | + |
| 148 | +In `plans/ENVLITE_SPECIFICATION.md`, find this passage (Phase 7, step 5): |
| 149 | + |
| 150 | +``` |
| 151 | +5. Locate the literal marker |
| 152 | + `/* That's all, stop editing! Happy publishing. */` (appears exactly |
| 153 | + once in the sample) and inject the following two lines immediately |
| 154 | + *before* it, separated by a blank line: |
| 155 | +
|
| 156 | + ``` |
| 157 | + define( 'WP_HOME', 'http://127.0.0.1:<PORT>' ); |
| 158 | + define( 'WP_SITEURL', 'http://127.0.0.1:<PORT>' ); |
| 159 | + ``` |
| 160 | +
|
| 161 | + `<PORT>` is the value from Phase 1. |
| 162 | +``` |
| 163 | + |
| 164 | +Replace it with: |
| 165 | + |
| 166 | +``` |
| 167 | +5. Locate the literal marker |
| 168 | + `/* That's all, stop editing! Happy publishing. */` (appears exactly |
| 169 | + once in the sample) and inject the following three lines immediately |
| 170 | + *before* it, separated by a blank line: |
| 171 | +
|
| 172 | + ``` |
| 173 | + define( 'WP_HOME', 'http://127.0.0.1:<PORT>' ); |
| 174 | + define( 'WP_SITEURL', 'http://127.0.0.1:<PORT>' ); |
| 175 | + define( 'DISABLE_WP_CRON', true ); |
| 176 | + ``` |
| 177 | +
|
| 178 | + `<PORT>` is the value from Phase 1. |
| 179 | +``` |
| 180 | + |
| 181 | +- [ ] **Step 2: Add a "Why `DISABLE_WP_CRON` matters" paragraph.** |
| 182 | + |
| 183 | +In `plans/ENVLITE_SPECIFICATION.md`, find this paragraph (immediately after the `**Outputs:** src/wp-config.php.` line of Phase 7): |
| 184 | + |
| 185 | +``` |
| 186 | +**Why `WP_HOME` / `WP_SITEURL` matter:** WordPress generates absolute |
| 187 | +URLs in markup (admin links, redirects, REST endpoints). If they don't |
| 188 | +match the listening address (`http://127.0.0.1:<port>`), `wp-admin` |
| 189 | +redirects loop and asset URLs break. They go in the runtime config; the |
| 190 | +phpunit config doesn't care. |
| 191 | +``` |
| 192 | + |
| 193 | +Insert immediately after it, as a new paragraph: |
| 194 | + |
| 195 | +``` |
| 196 | +**Why `DISABLE_WP_CRON` matters:** WordPress runs pseudo-cron via |
| 197 | +`spawn_cron()` on every front-end HTTP request — a non-blocking |
| 198 | +loopback POST to `wp-cron.php`. envlite's runtime is PHP's built-in |
| 199 | +dev server (`php -S`), which serializes requests by default, so every |
| 200 | +front-end hit pays the cost of opening the loopback connection plus |
| 201 | +`spawn_cron()`'s send/recv timeout, and the loopback itself stalls |
| 202 | +the next browser request while it runs. `DISABLE_WP_CRON = true` |
| 203 | +suppresses `spawn_cron()` entirely; cron is not needed on a dev box. |
| 204 | +The phpunit config does not set this — phpunit runs outside an HTTP |
| 205 | +request lifecycle, so `spawn_cron()` never fires from tests. |
| 206 | +``` |
| 207 | + |
| 208 | +- [ ] **Step 3: Commit.** |
| 209 | + |
| 210 | +```bash |
| 211 | +git add plans/ENVLITE_SPECIFICATION.md |
| 212 | +git commit -m "docs(envlite): document Phase 7 DISABLE_WP_CRON in spec" |
| 213 | +``` |
| 214 | + |
| 215 | +--- |
| 216 | + |
| 217 | +## Task 4: End-to-end verification on this checkout |
| 218 | + |
| 219 | +Manual sequence (~2 minutes). Confirms the new define lands in the actual rendered file and that re-running `init` is a silent re-stamp on a previously-envlite-owned `src/wp-config.php`. |
| 220 | + |
| 221 | +**Files:** none modified. |
| 222 | + |
| 223 | +**Prerequisite:** working `node` ≥ 20.10 / `npm` ≥ 10.2.3 / `composer` ≥ 2 / PHP ≥ 7.4 with `pdo_sqlite`, `sqlite3`, `openssl`, `simplexml`, `zip`, `pcntl` (Unix). If any are missing, Phase 0 will fail-fast and tell you which. |
| 224 | + |
| 225 | +- [ ] **Step 1: Reset to a known-clean state.** |
| 226 | + |
| 227 | +Run: |
| 228 | +``` |
| 229 | +php tools/local-env/envlite.php clean --force |
| 230 | +``` |
| 231 | + |
| 232 | +Expected: exit 0, `.envlite/` and envlite-managed files removed. If the checkout has never been `init`-ed, this is a no-op. |
| 233 | + |
| 234 | +- [ ] **Step 2: Run a fresh `init`.** |
| 235 | + |
| 236 | +Run: |
| 237 | +``` |
| 238 | +php tools/local-env/envlite.php init |
| 239 | +``` |
| 240 | + |
| 241 | +Expected: exit 0, all 8 phases complete. |
| 242 | + |
| 243 | +- [ ] **Step 3: Confirm the define lands exactly once in the rendered file.** |
| 244 | + |
| 245 | +Run: |
| 246 | +``` |
| 247 | +grep -c "DISABLE_WP_CRON" src/wp-config.php |
| 248 | +``` |
| 249 | + |
| 250 | +Expected: `1`. |
| 251 | + |
| 252 | +- [ ] **Step 4: Confirm the define sits between `WP_SITEURL` and the marker.** |
| 253 | + |
| 254 | +Run: |
| 255 | +``` |
| 256 | +awk '/WP_SITEURL/{s=NR} /DISABLE_WP_CRON/{c=NR} /That.s all, stop editing/{m=NR} END{print s, c, m}' src/wp-config.php |
| 257 | +``` |
| 258 | + |
| 259 | +Expected: three ascending line numbers. (`s < c < m`.) |
| 260 | + |
| 261 | +- [ ] **Step 5: Confirm re-running `init` is a silent re-stamp.** |
| 262 | + |
| 263 | +Run: |
| 264 | +``` |
| 265 | +php tools/local-env/envlite.php init 2>&1 | grep -iE "overwrite|drift|prompt" || echo "no prompts" |
| 266 | +``` |
| 267 | + |
| 268 | +Expected: `no prompts`. The previous `init` recorded the manifest hash for the rendered output; the second `init` re-renders the same bytes and finds the manifest entry matches the file, so it silently re-stamps without prompting. |
| 269 | + |
| 270 | +- [ ] **Step 6: Smoke-test the dev site.** |
| 271 | + |
| 272 | +Start the dev server in one terminal: |
| 273 | +``` |
| 274 | +php tools/local-env/envlite.php serve |
| 275 | +``` |
| 276 | + |
| 277 | +In another terminal: |
| 278 | +``` |
| 279 | +PORT=$(cat .envlite/port) && curl -fsS "http://127.0.0.1:$PORT/" -o /dev/null && echo "front page OK" |
| 280 | +``` |
| 281 | + |
| 282 | +Expected: `front page OK`. (The point of disabling cron is to remove a per-request penalty; serving the front page proves the runtime still boots with the new constant.) |
| 283 | + |
| 284 | +Stop the server with Ctrl-C when done. |
| 285 | + |
| 286 | +No commit for this task — it is verification. |
| 287 | + |
| 288 | +--- |
| 289 | + |
| 290 | +## Done criteria |
| 291 | + |
| 292 | +- `php tools/local-env/tests/run.php` exits 0 with all tests (existing + new) passing. |
| 293 | +- A fresh `envlite init` produces a `src/wp-config.php` containing exactly one `define( 'DISABLE_WP_CRON', true );` line, positioned between `WP_SITEURL` and the marker. |
| 294 | +- The spec's Phase 7 section reflects the new inject block and the new "Why `DISABLE_WP_CRON` matters" paragraph. |
| 295 | +- Re-running `envlite init` on a previously-envlite-owned checkout silently re-stamps `src/wp-config.php` (no overwrite prompt). |
| 296 | +- The dev server still starts and serves the front page on the cached port. |
0 commit comments