Skip to content

fix(cli): refuse a destination blocked by a file before planning - #1215

Draft
HugoXK wants to merge 2 commits into
mainfrom
agent/1208-blocked-parent
Draft

HugoXK wants to merge 2 commits into
mainfrom
agent/1208-blocked-parent

Conversation

@HugoXK

@HugoXK HugoXK commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #1208.

What changed

show --diff and apply --dry-run used to advertise a write whose nearest existing parent is a regular file, and the real apply only failed at the moment it created that parent:

  • text artifact, --to <tmp>/blocker/rule.md (with blocker a file): show/--dry-run returned the plan, the write exited 2 with cannot write <dest>: File exists — the parent's errno printed against a destination that never existed;
  • tree rooted under the same blocker: Not a directory at materialize;
  • apply --from <file> --to <blocked>: same shape.

One refusal now sits at the funnel every surface already uses:

  • _refuse_blocked_parent(dest) walks up to the nearest existing ancestor (os.path.lexists, so a deep <blocker>/a/b/rule.md fails like <blocker>/rule.md) and raises cannot write <dest>: '<ancestor>' is a file, not a directory.
  • It is called at the top of _check_apply_paths (evolution.py:1582), before the check_write is not None guard: the blocked parent is a filesystem property, not a question of who is writing, so the preview sees it with the operator allowlist unset — that guard is exactly what hid it before.
  • Callers of that funnel: show text (cli.py:3117), apply text (:3593), --from (:3714), --install-to (:3812), tree writer (evolution.py:2107). One call site means show, --dry-run and the real write agree by construction, not by three parallel checks.

This intentionally changes apply's message for this case (File exists → the named ancestor): File exists named a destination that never existed. The #1204 "message bytes unchanged" rule is about the refusal half and does not apply here. #1125 is intact: a missing parent with no blocker is still created and the file written.

Verification at the tip

Tip SHA: 9911610a32bd10259c8a6eb8f8bca327d4666687

Ran:

  • pytest -q -o addopts='' tests/test_apply_blocked_parent.py → 5 passed
  • pytest -q -o addopts='' tests/test_show_dest_refusals.py tests/test_write_dirs_apply_show.py (the #1204/#1188 rows, unchanged) → 7 passed
  • the new test file alone on base 1aa816e0 → 4 failed, 1 passed (the passer is the missing-parent control)
  • python -m tools.gen_api_docs --check → docs/api.md is up to date
  • python -m tools.changelog_fragments check → 15 changelog fragment(s) OK

Not run:

  • full pytest -q — the CI matrix is the line
  • mkdocs build --strict — this diff changes no docs/ page and no mkdocs.yml

Scope

agentdescent/evolution.py (one helper plus its call in _check_apply_paths), one test file, one changelog fragment. No cli.py change; existing destination and creatable-parent behaviour unchanged. T2.

@HugoXK HugoXK added agent-pr Pull request opened by an agent area:cli The agentdescent command line (cli.py, doctor, plan/evolve/status/apply) bug Something isn't working labels Nov 21, 2026
At 1aa816e the three shapes exit 0 from show --diff and apply --dry-run,
then exit 2 from the real apply with "cannot write <dest>: File exists" --
the parent's errno printed against a destination that never existed. Each
row takes show's error, apply --dry-run's error and apply's error and
requires them to be equal, so a preview that hard-codes a message apply
does not produce fails too.

The deep-parent row (blocker/a/b/rule.md) pins the walk-up to the nearest
existing ancestor; the control row keeps #1125 (a missing parent with no
blocker still writes). Red at 1aa816e: 4 failed, 1 passed in 2.79s.
apply materialises a missing parent only after the plan is returned, so
show and --dry-run never reached the failing step. _check_apply_paths is
the one funnel they all use, so the refusal lives at its top: walk up to
the nearest existing ancestor and, when it is not a directory, raise
"cannot write <dest>: '<ancestor>' is a file, not a directory" before the
allowlist guard.

This intentionally changes apply's message for this case; #1204's
"message bytes unchanged" rule covers the destination refusals only. A
missing parent with no blocker still writes (#1125), and the changelog
fragment records the preview change.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-pr Pull request opened by an agent area:cli The agentdescent command line (cli.py, doctor, plan/evolve/status/apply) bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(cli): show and --dry-run advertise a write whose parent is a file, and the real write fails with File exists

1 participant