pull: fix the flattened runtime root and delta re-pull after deferred files#268
pull: fix the flattened runtime root and delta re-pull after deferred files#268epeicher wants to merge 1 commit into
Conversation
Studio is moving from driving reprint as separate sub-commands (files-sync, db-sync, db-apply, flat-docroot, apply-runtime) to a single `reprint pull`. Two gaps surfaced: - apply-runtime targeted the raw download tree, not the flattened site, when a pull used --flatten-to. `pull` forwards `flatten_to` to flat-docroot, but `run_apply_runtime` reads `flat_document_root`. Derive the latter from the former in `validate_and_default_options` so a single `pull --flatten-to=X --runtime=...` roots the runtime at the flattened layout. - A delta re-pull tripped the mid-flight --filter guard. After a pull, its deferred "skipped-earlier" tail leaves filter=skipped-earlier / status=in_progress; the next `pull --filter=essential-files` hit the guard in ImportClient::run() before Pull::run() could prepare_repull() and clear that stale state. A completed pull (pull.stage===complete) about to re-pull now bypasses the guard. Adds unit tests for both in PullFilterOptionTest.
Replace the per-sub-command orchestration (downloadEssentialSiteFiles, refreshFlattenedSiteDirectory, downloadRemoteDatabase, applyDownloadedDatabase, generateRuntimeConfiguration) and the clearCompletedSubcommandState/--abort delta-reset with one `reprint pull` call. reprint owns the pipeline ordering (files-pull -> db-pull -> db-apply -> flat-docroot -> apply-runtime) and resets its own state for a delta re-pull via prepare_repull(), so the Studio-side --abort wiring and per-phase stage gating go away. - runFullPull() issues the single pull with the same sqlite geometry the old db-apply used (target sqlite under the raw content dir) plus --flatten-to, --runtime=playground-cli, --start-runtime=none and --output-dir, mounting the site + runtime dirs up front. - ensurePort moves before the pull so --new-site-url is available. - Collapse the stage machine from 9 stages to 5 (initialized -> pulled -> site-registered -> site-started -> completed). - Bump the PHP-WASM memory_limit to 1024M: the single long-lived fork holds the file-index high-water-mark across phases. Requires reprint's flatten_to->flat_document_root bridge and the re-pull filter-guard fix (WordPress/reprint#268).
Pull pipeline performance —
|
| Stage | PR | trunk | Δ | Status | Details |
|---|---|---|---|---|---|
playground-sqlite-db-pull |
9.75 s | 9.32 s | ⚪ +428 ms (+4.6%) | ✓ | condition=db-pull in PHP.wasm runtime=php.wasm 8.3 wp_mysql_parser=enabled mode=lexer native_lexer=verified native_token_stream=WP_MySQL_Native_Token_Stream native_token_count=18 native_parser=selected trunk: condition=db-pull in PHP.wasm runtime=php.wasm 8.3 wp_mysql_parser=enabled mode=lexer native_lexer=verified native_token_stream=WP_MySQL_Native_Token_Stream native_token_count=18 native_parser=selected |
playground-sqlite-db-apply |
3.65 s | 3.64 s | ⚪ +7 ms (+0.2%) | ✓ | condition=db-apply to SQLite in PHP.wasm runtime=php.wasm 8.3 wp_mysql_parser=enabled mode=parser native_lexer=verified native_token_stream=WP_MySQL_Native_Token_Stream native_token_count=18 native_parser=verified native_ast=WP_MySQL_Native_Parser_Node sqlite_driver_parser=verified trunk: condition=db-apply to SQLite in PHP.wasm runtime=php.wasm 8.3 wp_mysql_parser=enabled mode=parser native_lexer=verified native_token_stream=WP_MySQL_Native_Token_Stream native_token_count=18 native_parser=verified native_ast=WP_MySQL_Native_Parser_Node sqlite_driver_parser=verified |
| Total | 13.39 s | 12.96 s | ⚪ +434 ms (+3.4%) |
Numbers carry runner noise; treat single-run deltas as directional, not authoritative.
📈 Trunk performance history — commit-by-commit timeline.
There was a problem hiding this comment.
Pull request overview
This PR fixes two bugs in the composite pull command so that the full pipeline (preflight → files-pull → db-pull → db-apply → flat-docroot → apply-runtime) works correctly both on first run with flatten + runtime options and on delta re-pulls after deferred files have been fetched.
Changes:
- Derives
flat_document_rootfromflatten_toinvalidate_and_default_options()so thatpull --flatten-to=DIR --runtime=...generates a runtime rooted at the flattened layout rather than the raw download tree. - Exempts completed pull re-pulls (
pull.stage === "complete") from the mid-flight filter guard inImportClient::run(), allowingprepare_repull()to clear the stale sub-command state before the guard would otherwise block the filter change. - Adds two focused unit tests covering both fixes.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
packages/reprint-importer/src/lib/pull/class-pull.php |
Bridges flatten_to → flat_document_root in option validation so apply-runtime targets the flattened directory |
packages/reprint-importer/src/import.php |
Adds $is_repull check to the filter guard to exempt completed pulls about to delta re-pull |
tests/Import/PullFilterOptionTest.php |
Adds PullBridgeFakeClient test helper and two new tests for the flatten bridge and the re-pull guard bypass |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
What it does
Two fixes to the composite
pullcommand so it correctly runs, and re-runs, the full preflight -> files-pull -> db-pull -> db-apply -> flat-docroot -> apply-runtime pipeline from a single invocation:pull --flatten-to=DIR --runtime=...now generates a runtime rooted at the flattened layout (DIR) instead of the raw download tree. The two options now compose:--flatten-tobuilds the flattened docroot and--runtimetargets it.pull --filter=essential-filesonce theskipped-earlierfiles have been fetched no longer fails the mid-flight--filterguard; it proceeds and re-syncs as a delta.Rationale
--flatten-todid not reach apply-runtime.pullforwards--flatten-toto the flat-docroot stage asflatten_to, butrun_apply_runtime()reads a different key,flat_document_root, and otherwise falls back tofs_root + remote document_root(the raw tree). So a pull that both flattens and generates a runtime produced a runtime pointing at the wrong root: the flatten and runtime stages did not compose.Delta re-pull was blocked after a deferred-files tail.
pullsupports delta re-pull: re-running a completed pull resets its own state viaprepare_repull()and re-syncs. But after an--filter=essential-filespull fetches its deferredskipped-earlierfiles, the state readsfilter=skipped-earlier,status=in_progress. The nextpull --filter=essential-filesloads that inImportClient::run()and the mid-flight guard throws:That guard runs before
Pull::run()reachesprepare_repull(), which is the step that would clear the stale state, so the re-pull can never start. A caller that drives the sub-commands directly can sidestep this withfiles-sync --abort; throughpull, the reset has to happen insideprepare_repull().Implementation
validate_and_default_options()derives the missing key:The filter guard exempts a completed pull that is about to delta re-pull (its
prepare_repull()resets the state):Testing instructions
Two new tests:
testPullDerivesFlatDocumentRootFromFlattenTo: a pull with--flatten-toplus--runtimehands apply-runtime a matchingflat_document_root.testRepullBypassesTheMidFlightFilterGuard: a pull whose state carries the tail'sfilter=skipped-earlier/status=in_progressre-pulls to completion instead of throwing.