Repository navigation
fix(cli): show --diff previews the write apply refuses (#1188) - #1200
Conversation
`show --diff` guarded only the destination. A directory artifact backs up under `$AGENTDESCENT_HOME/backups/...`, not beside the target, so a destination inside `AGENTDESCENT_SURFACE_WRITE_DIRS` whose home is outside it was reported as `written` while the same `apply` exited 2 on the backup slot -- a preview for a call that cannot run. `show` now runs apply's own check set: the destination, every path in the plan's write set and the backup slot. A single-file artifact checks through `_check_apply_paths`, as `apply` does; a tree through `_write_to(check_write=...)`, the call `apply` makes, with `dry_run` the only difference. An unset allowlist still means allow-anywhere. Partial: #1082 Partial: #963
|
Advisory QA read — #1200 at Read live at that head ( Ran (fresh clone, fetched
Probes at the tip, independent of the new test's assertions:
Not run: docker sandboxes (no daemon — the same 10 errors at both ends), wheel smoke (no packaging path), real-model path (offline; the diff is path checking), Findings: none blocking. Recorded, not a defect: the preview assumes a default No UI surface: CLI No merge action from QA: this report is advisory, the merge gate is the repo's review decision on the head sha, and the merge itself is executed by the repo's merge process. |
|
Review (Birfy) Tip SHA: b9b6202
|
…#1206) Closes #1204. Base: 2dff12b Tip SHA: f8d5a79 ## What changed `#1200` taught `show --diff` to preview the operator write-dir boundary. The other half of `apply`'s destination refusals was still missing, so `show` advertised writes that `apply` exits 2 on: - a text artifact whose `spec.target` is a **directory**; - a text artifact whose `spec.target` is a **symlink**; - a tree artifact whose root is a **symlink**. `apply`'s text-destination checks (`os.path.isdir(dest)` and `_refuse_dest_link(...)`) now live in one helper, `_refuse_text_dest`, that both `apply_payload` and the text branch of `show_payload` call, so the preview cannot drift. The tree branch of `show` calls `_refuse_dest_link(dest, dest)` before `_write_to`, the same refusal `apply` makes (and that `_write_to` would not see, because it `abspath`s the root). `apply`'s behaviour and its message bytes stay unchanged. `show` stays read-only: it reports the refusal in `apply_plan.error`, does not raise, and does not touch the destination. `docs/plugins.md` records the same destination refusals next to the write-dir paragraph from #1188. Red first, at this PR's base (`2dff12b6`) in a clean worktree with only the new test file present: ``` PYTHONPATH=. python -m pytest -o addopts="" -p no:cacheprovider -q tests/test_show_dest_refusals.py 3 failed, 1 passed in 0.84s ``` `show --diff --json` returned `apply_plan` with `written` and no `error` for a directory dest, a text symlink dest, and a tree symlink root. The regular-file control already passed. ## Ran at `f8d5a79f` - `PYTHONPATH=. python -m pytest -o addopts="" -p no:cacheprovider -q 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` — `56 passed`; - `python -m tools.gen_api_docs --check` — `docs/api.md is up to date`; - `python -m tools.changelog_fragments check` — `14 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.
Fixes #1188. Partial: #1082. Partial: #963.
Base: 8d75685
Tip SHA: b9b6202
What changed
show --diffpreviewed a write that the sameapplyrefuses. Its only guardwas
_refuse_plan_outside_write_dirs, which checked the destination;applyadditionally checks every file the plan names and the backup slot
(
_check_apply_paths). A directory artifact backs up under$AGENTDESCENT_HOME/backups/..., so withAGENTDESCENT_SURFACE_WRITE_DIRSset to the destination's tree the preview listed the files as
writtenwhileapplyexited 2 on the backup path.shownow runs apply's own check set:slot = _backup_slot(dest) if backup and not plan["noop"] and os.path.exists(dest) else None, then_check_apply_paths(dest, plan["written"], slot, _operator_write_guard())— the expression and callapplymakes atcli.py:3561;result._write_to(dest, backup=..., dry_run=True, check_write=_operator_write_guard())— apply's call atcli.py:3604withonly
dry_rundifferent, and_write_toruns_check_apply_pathsbeforeits
dry_runreturn (evolution.py:2102-2105)._refuse_plan_outside_write_dirs(payload, target, written=(), backup=None)carries the extra paths instead of guarding the destination alone; the
tree branch's call to it was dropped because
_write_tonow performs thatsame set. An unset
AGENTDESCENT_SURFACE_WRITE_DIRSstill meansallow-anywhere.
One asymmetry is deliberate: the preview assumes the default apply, so it
checks the backup slot.
apply --no-backuptakes no such slot and refusesnothing extra; the preview is therefore stricter than that one flag
combination, not wrong about it.
Red first, at this PR's base (
8d75685a) in a clean worktree with only the newtest file present:
showreturnedapply_plan {"written": ["alpha/SKILL.md", "alpha/references/rules.md", "beta/SKILL.md"], ..., "noop": false}with noerror, while the same call through
applyexited 2 witherror: backup '<tmp>/ad-home/backups/seed-lib-e25afdcf43d6/bak-0' is outside the operator's write allowlist (AGENTDESCENT_SURFACE_WRITE_DIRS); allowed roots: '<tmp>/seed-lib', dest unchanged and home never created.Ran at
b9b62024PYTHONPATH=. python -m pytest -o addopts="" tests/test_write_dirs_apply_show.py -q—
3 passed;tests/test_*.py(516 files), eachPYTHONPATH=. python -m pytest -o addopts="" -q <chunk>—7935 passed, 22 failed, 10 errors, 51 skipped;8d75685aworktree run of thesame ten files (
22 failed, 442 passed, 15 skipped, 10 errors, 137.81s):commbetween the two sorted id lists is empty. All 32 are environment rows—
OSError: [Errno 30] Read-only file system: '/home/xuke/.agentdescent-tests'— plus the Docker sandbox rows intest_sandbox_container.py;python -m tools.gen_api_docs --check—docs/api.md is up to date;python -m tools.changelog_fragments check—9 changelog fragment(s) OK.Not run
mkdocs build --strictin its exact form: this host is offline and thesocialplugin fetchesfonts.google.com, so the build dies atERROR - Error building page 'index.md': ... ConnectTimeout. Verifiedinstead with
mkdocs build --strict -f mkdocs.local.yml, whose onlydifference is
social: {cards: false}— pass,Documentation built in 12.91 seconds. The CI build online is not claimed here.