Skip to content

fix(cli): refuse a tree child blocked by a file before writing - #1222

Merged
Birfy merged 1 commit into
mainfrom
fix/1221-blocked-child
Nov 22, 2026
Merged

Birfy merged 1 commit into
mainfrom
fix/1221-blocked-child

Conversation

@Birfy

@Birfy Birfy commented Nov 22, 2026

Copy link
Copy Markdown
Collaborator

Closes #1221.

Base: 3bd4883
Tip SHA: 7fc2db1

What changed

#1215 refuses a destination whose parent is a file, on all four surfaces. The hole one level down was a tree child: dest is a directory, dest/alpha is a regular file, and the artifact writes alpha/SKILL.md. _refuse_blocked_parent inspected only dest, so show --diff advertised written: ["alpha/SKILL.md"] while the real apply exited 2 with cannot write <dest>: File exists.

_check_apply_paths now walks every path in written as well as dest, so show --diff, apply --dry-run, and the real apply (including --install-to, which already used this funnel) agree on cannot write <leaf>: '<path>' is a file, not a directory and the preview still writes nothing. Existing #1215 refusals and a sibling regular file next to plain/written.md are unchanged.

Red first

At this PR's base (3bd4883e) 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_child.py
F..
FAILED tests/test_apply_blocked_child.py::test_tree_child_blocked_by_a_file_is_named_on_all_four_surfaces
AssertionError: show advertised a write the real apply refuses: {"written": ["alpha/SKILL.md"], "unchanged": [], "extra": ["alpha"], "deleted": [], "backup": [], "noop": false}
assert None
tests/test_apply_blocked_child.py:96
1 failed, 2 passed

The failing assertion is assert show_error in test_tree_child_blocked_by_a_file_is_named_on_all_four_surfaces. The --install-to coverage row and the sibling-file control were already green on live main (the dest-level blocked-parent refusal already reaches --install-to through this funnel); they stay as locks.

Ran at 7fc2db14

  • PYTHONPATH=. 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 passed
  • python -m tools.gen_api_docs --check — docs/api.md is up to date
  • python -m tools.changelog_fragments check — 21 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 two sentences to docs/plugins.md; CI docs is the line.

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
@github-actions github-actions Bot added the risk:T3 Risk tier T3 (core loop, release, process; needs Danyang's click), set by the controller label Nov 22, 2026
@Birfy

Birfy commented Nov 22, 2026

Copy link
Copy Markdown
Collaborator Author

Review (Birfy)

Tip SHA: 7fc2db1
Ran:

  • .github/scripts/risk_gate.py --repo ThinkFlowLab/agentdescent --pr 1222 → T3 (178 lines / 4 files; path agentdescent/evolution.py)
  • pytest -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 at this tip → 89 passed
  • python -m tools.gen_api_docs --check → docs/api.md is up to date
  • python -m tools.changelog_fragments check → 21 changelog fragment(s) OK
  • Required CI at this tip → still running; --auto --squash armed
    Not run:
  • Full offline suite locally — the CI test matrix is the line
  • mkdocs build --strict — this host is offline (social fetches fonts.google.com); the diff only adds two sentences to docs/plugins.md, CI docs is the line
    Findings:
  • No actionable defects. After fix(cli): refuse a destination blocked by a file before planning #1215, show --diff still advertised a tree leaf as written when an intermediate path was already a regular file, and the real apply exited 2 with File exists. _check_apply_paths now walks every produced path, not just dest, so the four surfaces agree on the blocking-file sentence and the preview writes nothing. Existing fix(cli): refuse a destination blocked by a file before planning #1215 refusals and a sibling regular file next to an unblocked plain/written.md are unchanged.
    Verdict: PASS

@Birfy
Birfy enabled auto-merge (squash) November 22, 2026 16:25
@Birfy
Birfy merged commit 5ac5548 into main Nov 22, 2026
12 checks passed
@Birfy
Birfy deleted the fix/1221-blocked-child branch November 22, 2026 16:44
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk:T3 Risk tier T3 (core loop, release, process; needs Danyang's click), set by the controller

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(cli): show --diff advertises a written child that apply refuses (File exists)

1 participant