Repository navigation
fix(cli): refuse a tree child blocked by a file before writing - #1222
Merged
Merged
Conversation
show --diff and apply --dry-run advertised a leaf as written when an intermediate path was already a regular file; the real apply then exited 2 with File exists. Check every produced path, not just dest, so the preview names the blocker and writes nothing. Closes #1221
Collaborator
Author
|
Review (Birfy) Tip SHA: 7fc2db1
|
Birfy
enabled auto-merge (squash)
November 22, 2026 16:25
Birfy
added a commit
that referenced
this pull request
Nov 22, 2026
Closes #1223. Base: 5ac5548 Tip SHA: d2b64b1 ## What changed `#1222` refuses a regular file sitting on the way to a tree leaf. The inverse hole was a directory sitting where the artifact wants a file: `dest` is a directory, `dest/alpha` is a directory, and the artifact writes `alpha`. `show --diff` and `apply --dry-run` advertised `written: ["alpha"]` while the real `apply` exited 2 with `cannot write <dest>: Is a directory` (the tree root, not the blocking leaf). `apply --from` was worse: `shutil.copy2` nested the bytes at `dest/alpha/alpha` and reported success. `_check_apply_paths` now also refuses a produced path that exists as a real directory, so `show --diff`, `apply --dry-run`, the real `apply`, `--from`, and `--install-to` agree on `cannot write <leaf>: '<leaf>' is a directory, not a file` and the preview still writes nothing. Existing `#1221` / `#1215` refusals and a sibling directory next to `plain/written.md` are unchanged. A symlink at the leaf stays with the dest-link refusal. ## Red first At this PR's base (`5ac55481`) in a clean worktree with only the new test file present: ``` PYTHONPATH=. python -m pytest -o addopts="" -p no:cacheprovider -q tests/test_apply_blocked_leaf.py FF.FF FAILED tests/test_apply_blocked_leaf.py::test_tree_leaf_blocked_by_a_directory_is_named_on_all_four_surfaces AssertionError: show advertised a write the real apply refuses: {"written": ["alpha"], "unchanged": [], "extra": ["alpha/keep.txt"], "deleted": [], "backup": [], "noop": false} assert None tests/test_apply_blocked_leaf.py:95 4 failed, 1 passed ``` The failing assertion is `assert show_error` in `test_tree_leaf_blocked_by_a_directory_is_named_on_all_four_surfaces`. The sibling-directory control was already green on live main; it stays as a lock. `--from` exited 0 and advertised `written: ["alpha"]`; `--install-to` already failed the real write but with `cannot write <dest>: Is a directory`. ## Ran at `d2b64b1f` - `PYTHONPATH=. python -m pytest -o addopts="" -p no:cacheprovider -q tests/test_apply_blocked_leaf.py tests/test_apply_blocked_child.py tests/test_apply_blocked_parent.py tests/test_show_dest_refusals.py tests/test_write_dirs_apply_show.py tests/test_apply_symlink_dest.py tests/test_apply_noop.py tests/test_cli_apply_created_target.py tests/test_cli_apply_text_missing_parent.py tests/test_apply_backup_away_from_skills.py tests/test_apply_from.py tests/test_cli_write_error.py tests/test_skill_library_apply_install.py tests/test_demo_dest_link.py` — `94 passed` - `python -m tools.gen_api_docs --check` — `docs/api.md is up to date` - `python -m tools.changelog_fragments check` — `22 changelog fragment(s) OK` ## Not run - Full offline suite locally — the CI test matrix is the line. - `mkdocs build --strict` in its exact form: this host is offline and the `social` plugin fetches `fonts.google.com`. The diff adds one sentence to `docs/plugins.md`; CI `docs` is the line.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1221.
Base: 3bd4883
Tip SHA: 7fc2db1
What changed
#1215refuses a destination whose parent is a file, on all four surfaces. The hole one level down was a tree child:destis a directory,dest/alphais a regular file, and the artifact writesalpha/SKILL.md._refuse_blocked_parentinspected onlydest, soshow --diffadvertisedwritten: ["alpha/SKILL.md"]while the realapplyexited 2 withcannot write <dest>: File exists._check_apply_pathsnow walks every path inwrittenas well asdest, soshow --diff,apply --dry-run, and the realapply(including--install-to, which already used this funnel) agree oncannot write <leaf>: '<path>' is a file, not a directoryand the preview still writes nothing. Existing#1215refusals and a sibling regular file next toplain/written.mdare unchanged.Red first
At this PR's base (
3bd4883e) in a clean worktree with only the new test file present:The failing assertion is
assert show_errorintest_tree_child_blocked_by_a_file_is_named_on_all_four_surfaces. The--install-tocoverage row and the sibling-file control were already green on live main (the dest-level blocked-parent refusal already reaches--install-tothrough this funnel); they stay as locks.Ran at
7fc2db14PYTHONPATH=. python -m pytest -o addopts="" -p no:cacheprovider -q tests/test_apply_blocked_child.py tests/test_apply_blocked_parent.py tests/test_show_dest_refusals.py tests/test_write_dirs_apply_show.py tests/test_apply_symlink_dest.py tests/test_apply_noop.py tests/test_cli_apply_created_target.py tests/test_cli_apply_text_missing_parent.py tests/test_apply_backup_away_from_skills.py tests/test_apply_from.py tests/test_cli_write_error.py tests/test_skill_library_apply_install.py tests/test_demo_dest_link.py—89 passedpython -m tools.gen_api_docs --check—docs/api.md is up to datepython -m tools.changelog_fragments check—21 changelog fragment(s) OKNot run
mkdocs build --strictin its exact form: this host is offline and thesocialplugin fetchesfonts.google.com. The diff adds two sentences todocs/plugins.md; CIdocsis the line.