Skip to content

fix(cli): show --diff still previews writes apply refuses -- directory and symlink destinations #1204

Closed

Description

@HugoXK

Problem

#1200 taught show --diff to preview the operator write boundary: when apply would refuse a destination outside AGENTDESCENT_SURFACE_WRITE_DIRS, show now carries that refusal in apply_plan.error. The other half of apply's destination refusals is still missing, so show --diff advertises writes that apply exits 2 on.

At e43e847a, for a run whose spec.target / --to destination is:

  • a directory (text artifact): show --diff --json returns apply_plan {"would_write": "<dir>", "written": ["<dir>"], "noop": false} with no error; apply refuses at cli.py:3560-3568 ("evolved a single text artifact and ... is a directory; pass --to FILE ...").
  • a symlink (text artifact): show returns the same plan shape; apply refuses via _refuse_dest_link at cli.py:3568 ("a destination link is never dereferenced").
  • a symlink (tree artifact, default root): show returns written: ["<root>/SKILL.md", ...]; apply refuses at cli.py:3608 before _write_to is called.

Control, regular file target: both exit 0, no error, file untouched.

Mechanism (read at e43e847a)

  • The text branch of show_payload (cli.py:3197-3205) calls _text_plan and then only _refuse_plan_outside_write_dirs. It never calls os.path.isdir(dest) nor _refuse_dest_link(...), which is exactly what apply_payload does first (cli.py:3560-3568).
  • The tree branch (cli.py:3216-3226) calls result._write_to(..., dry_run=True, check_write=...). _write_to (evolution.py:2065) abspaths its destination and never refuses a link at the root; apply_payload refuses that link at cli.py:3608 before calling _write_to, so the dry-run plan never sees it.

Measured: show_payload called at e43e847a with a stub run store (text artifact, rendered="hello\n") returns {"would_write": ".../outdir", "written": [".../outdir"], "chars": 6, "noop": false} for a directory destination, and the same shape for a symlink destination. End-to-end exit codes against a real run store were measured by the Product seat at the same sha.

Expected

show --diff / show --diff --json puts the refusal apply would raise into apply_plan.error for every destination apply refuses, not only the write-dir half. show stays read-only: it reports the refusal, it does not raise and does not touch the destination.

Suggested fix (one helper, two callers)

Factor the two text-destination checks (os.path.isdir(dest) and _refuse_dest_link(dirname, dest)) into one helper that both apply_payload and the text branch of show_payload call, so the preview and the write cannot drift again. For the tree branch, call _refuse_dest_link(dest, dest) before _write_to and carry its message into apply_plan.error. apply's behaviour and its message bytes stay unchanged.

Acceptance

  • Text artifact, directory destination: show --diff and --json carry an apply_plan.error whose text equals what apply raises for the same destination; show exits 0 and the directory is untouched.
  • Text artifact, symlink destination: same equality, same exit 0.
  • Tree artifact whose root is a symlink: same equality, same exit 0.
  • Control: regular file destination unchanged (apply_plan with written, no error).
  • The equality is asserted against apply's own message (not a hard-coded copy), so a later wording change cannot quietly re-open the gap.
  • Red-first at e43e847a: the new rows fail before the change.
  • changelog.d/ Fixed fragment; focused apply/show tests, tools.gen_api_docs --check, tools.changelog_fragments check green.

Scope

agentdescent/cli.py (show_payload, the shared helper) plus one changelog fragment. apply's behaviour and message bytes untouched; the write-dir half from #1200 untouched. T2 (cli.py).

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:clibug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions