Skip to content

🐛 fix(bones): deploy creates a missing destination parent and fails when a copy fails - #143

Merged
gfazioli merged 4 commits into
masterfrom
fix/deploy-missing-parent
Nov 23, 2026
Merged

gfazioli merged 4 commits into
masterfrom
fix/deploy-missing-parent

Conversation

@gfazioli

@gfazioli gfazioli commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

What was wrong

xcopy() made the destination with a non-recursive, unchecked mkdir(), and nothing propagated the result of a copy: the recursion dropped each call's return, the directory branch returned true regardless, and deploy() ignored the top-level result. With a destination whose parent did not exist (bones deploy /tmp/missing-parent/my-plugin) every mkdir/copy failed, and the deploy still printed Deploy completed! and exited 0. xcopy() also returned false for a file skipped on purpose, so false meant both "skipped" and "failed".

What changed

  • Missing parents of the destination are created like mkdir -p. assertSafeDeployDestination() still runs first (before the build and before anything is created), so a refused destination creates no folders.
  • xcopy() returns false only when a write fails (mkdir, copy, symlink); a dotfile or skip-list entry returns true. It stops at the first failure and records the path.
  • deploy() ends with Deploy failed: could not write '<path>'. The destination is incomplete. and exit status 1 (the -tmp folder of --create-zip is removed first). The PHP warnings are suppressed in favour of that one message.
  • Parents are created one by one from the top with a plain mkdir(), not mkdir()'s recursive flag: PHP collapses link/.. lexically while the guard resolves the link first, so a destination could be approved for one place and created in another.
  • assertAutoloadedFilesShipped() is left as it is: the empty deploy it could not see is now unreachable, because a failed copy exits before it runs.

After review (Codex round 1)

  • deleteDirectory() no longer uses glob() (a [ab] in the destination name matched sibling folders xa/xb and emptied them; pre-existing) and never follows a symlinked folder inside an old destination.
  • The progress check mark is printed only after the copy succeeded; the --create-zip cleanup runs only if the staging folder exists.
  • New tests: symlink-then-.. destination lands where the OS resolves it, a refused one behind a symlink creates nothing, glob characters in the destination, a symlinked folder inside the old destination survives the replace, a nested copy failure exits 1 naming the file. The symlink, glob and symlinked-folder ones fail on the previous commit's code; the nested-failure one already passed there and guards the first commit.

Fixes #139

Tests

tests/Console/DeployDestinationTest.php (process tests): missing parents are created, a file skipped on purpose is not a failure, a parent that is a regular file fails, a read-only parent fails, a refused destination (inside the plugin, contains the plugin) creates nothing. Red on the unfixed code: 3 of the first 5 fail (missing parents, regular-file parent, read-only parent); the other two pass there by design (they guard against regressions of the fix).

composer test: 368 tests before, 378 tests / 1062 assertions after, all green (the 3 deprecations are pre-existing).

Live, in WPKirk-Developing

.claude/scripts/deploy-missing-parent-live-smoke.sh (workspace tooling, not in this repo) deploys the bench to a path whose parent is missing, to a path under a regular file, and under a read-only folder, and checks debug.log.

v3.3.0 (red):

✗ missing parents: 0 files at the destination, the reference has 2080
✗ parent is a file: exit 0, expected 1
✗ parent is a file: printed 'Deploy completed!'
✗ read-only parent: exit 0, expected 1
✗ read-only parent: printed 'Deploy completed!'
✗ debug.log grew by 1419747 bytes

This branch (green):

✓ missing parents: exit 0
✓ missing parents: 2080 files, as many as the reference
✓ parent is a file: exit 1
✓ parent is a file: no 'Deploy completed!'
✓ read-only parent: exit 1
✓ read-only parent: no 'Deploy completed!'
✓ debug.log did not grow

Review rounds

  • Codex round 1 (gpt-6.2-sol, high): mkdir()'s recursive flag collapsed link/.. lexically while the guard followed the link; deleteDirectory() read the path as a glob() pattern (a destination named x[ab] emptied xa/ and xb/) and followed a symlinked folder into its target; no nested-failure test; the copy step's check mark printed before the failure. Fixed in bd83f6d: parents are made one mkdir() at a time from the top down, deleteDirectory() walks scandir() and unlinks links. Copilot asked for the nested failure with --create-zip too: b0b1134.
  • Codex round 2: a . or .. after a MISSING folder resolves through a link the guard never followed once that folder exists; the parent walk had no stop at the root. Fixed in bf65cf0: the walk refuses a ./.. in the missing tail before any mkdir() (deploy ../deploy-version from the plugin still works, tested) and stops when dirname() stops changing.
  • Codex round 3 found only probe-built combinations, both pre-existing in the guard and left for a follow-up: a destination symlink whose NAME contains a backslash (resolvePath() splits on it), and a plugin path typed with different capitalization on a case-insensitive volume.

composer test at bf65cf0, rebased on master with #144: 386 tests / 1083 assertions, green. Live smoke green on bf65cf0.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

A critical path-resolution flaw allows a crafted destination to bypass the safety guard and write into the source plugin, while tests do not cover nested-copy failure propagation or partial ZIP-directory cleanup.

1 open issue
What changed in this PR

This PR addresses #139 by making the WPBones deploy command create missing destination parents and report copy failures instead of falsely reporting success.

Changes:

  • Creates destination directories recursively and propagates write failures while treating intentional skips as successful.
  • Exits with a failure message and removes ZIP staging files when copying fails.
  • Adds process tests for missing parents, skipped files, unwritable destinations, and safety refusals.
File Description
tests/​Console/​DeployDestinationTest.php Adds destination creation, failure, and safety regression tests.
src/​Console/​bin/​bones Adds recursive directory creation, copy-failure tracking, and deploy failure handling.

Review effort: Balanced

Comment thread tests/Console/DeployDestinationTest.php Resolved
gfazioli added a commit that referenced this pull request Nov 23, 2026
…leteDirectory without glob

Missing parents are created one by one from the top, since mkdir()'s recursive flag collapses link/.. lexically while the destination guard resolves the link first. deleteDirectory() no longer builds a glob() pattern from the path (a [ab] in the name matched sibling folders) and never follows a symlinked folder. The progress check mark waits for the copy's result.
…hen a copy fails

xcopy() made the destination with a non-recursive mkdir and dropped every result, so a destination whose parent did not exist printed 'Deploy completed!' with exit 0 and nothing copied. It now creates the parents like mkdir -p (after assertSafeDeployDestination(), which still runs first) and returns false only when a write fails, not for a file skipped on purpose; deploy() exits 1 on it.
…leteDirectory without glob

Missing parents are created one by one from the top, since mkdir()'s recursive flag collapses link/.. lexically while the destination guard resolves the link first. deleteDirectory() no longer builds a glob() pattern from the path (a [ab] in the name matched sibling folders) and never follows a symlinked folder. The progress check mark waits for the copy's result.
@gfazioli
gfazioli force-pushed the fix/deploy-missing-parent branch from be106d1 to bd83f6d Compare November 23, 2026 10:43
@gfazioli
gfazioli merged commit bf65cf0 into master Nov 23, 2026
4 checks passed
@gfazioli
gfazioli deleted the fix/deploy-missing-parent branch November 23, 2026 10:51
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.

🐛 bones deploy reports '✅ Deploy completed!' when the destination's parent folder doesn't exist

2 participants