Skip to content

fix: stream large site apply scripts through stdin - #193

Merged
noeltock merged 2 commits into
mainfrom
block-theme/site-apply-stdin
Oct 12, 2026
Merged

noeltock merged 2 commits into
mainfrom
block-theme/site-apply-stdin

Conversation

@noeltock

@noeltock noeltock commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

Problem

Applying a native page can put the mutation script over Linux's single-argument limit. The CLI then reports an uncertain transport outcome after earlier dependency imports, without creating the page.

Solution

The default local transport sends the unchanged PHP script through wp eval-file - on stdin. Explicit transport callbacks keep their existing eval argument contract. Identity checks, ownership checks, markers and readback stay in the same script.

Behaviour that changes or must stay true Read first Proof
Large native content reaches WP-CLI without a large argv entry src/site/apply-wpcli.ts Real subprocess regression with more than 300 KB, exact bytes and EOF
Transport failures stay generic and preserve uncertainty siteApplyWpCli / runWithInput Existing apply refusal and recovery tests
Injected transport callbacks stay compatible siteApplyWpCli Existing callback-based apply suite

Diff

3 files, +66 / -8.

 siteApplyWpCli
- default: execFile(wp, [...selection, 'eval', script])
+ default: spawn(wp, [...selection, 'eval-file', '-'])
+          stdin.end('<?php\n' + unchangedScript)
  injected: transport(wp, [...selection, 'eval', unchangedScript])
+ runWithInput: fail on process/pipe errors, nonzero exit or stdout above 1 MiB
+ site-apply test: short argv, full large payload, PHP prefix and EOF
+ site-cli test: include captured child diagnostics on assertion failure

Testing & verification

Reviewed revision: d3703262dcaf11545b04334ba51aa5200f32c43e · Environment: local macOS Node, OrbStack Linux CLI, WordPress 7.1 / PHP 8.4.

  • npm test -- dev/test/site-apply.test.ts: 26 passed.

  • npm run typecheck: passed.

  • npm run verify: 974 passed, 4 skipped, 1 failed in the unrelated discovered-strict site compile CLI case. Its standalone canonical reproduction returned 0; the full site-cli.test.ts focused rerun passed all 4 cases. The failing assertion now preserves child output. The full local run remains failed.

  • Actual general CLI apply created a native page and a subsequent apply updated it through the stdin transport. The creation resumed a retained partial operation after explicit operator reconciliation of known absent page writes; it is not a clean one-shot bootstrap result.

  • An equal-sized benign argument failed in the Linux container with argument list too long, establishing the transport limit separately from application behavior.

  • npm run build, npm run check:private, npm run pack:check: passed.

  • Exact-head CI 38300397477: Node 22.13/24, packed consumer, WordPress proof and CI scope passed.

Not verified: the failed local full-suite case has no confirmed cause, although both clean CI runs passed. No production apply or release.

Risk / rollout

Wrappers around WP-CLI must forward stdin (for example docker exec -i). Callback transports retain their contract. Detection: transport errors still stop the apply and retain operation evidence. Rollback: revert this commit; that restores the argument-size failure and does not undo prior WordPress writes.

@noeltock
noeltock merged commit 389651a into main Oct 12, 2026
8 checks passed
@noeltock
noeltock deleted the block-theme/site-apply-stdin branch October 12, 2026 20:11
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