Skip to content

adopt-project.py: plan asks whether it can write --out with its flags, before any work, and refuses a folder, a pipe, a missing folder or one nobody can write in as adopt-out-unwritable, and says plan written to once the plan is on disk, so a mistyped --out no longer ends in a traceback after the whole plan is built (#799) - #833

Merged
brettheap merged 5 commits into
mainfrom
fix/799-adopt-plan-out-checked
Oct 18, 2026

Conversation

@brettheap

@brettheap brettheap commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Lane: openreposhape-1 (openRepoShape-1)
Claim: #799 (comment)

v1.1.1, size S. Authored on main at 24a977c (merged into the branch), then changed for the review of 8295c1e (F1 to F5). It overlaps #796 (_source_spec, Source.open) and #803 (Source.clone, _leave_the_clones) only by position in cmd_plan: this PR touches none of those functions.

What

How adopt-project.py plan treats --out (L1-89 of #457) and when it says the plan exists (L1-79).

  • --out is asked first. cmd_plan asks it with the flag-only refusals at its top, before _work_root and Source.open, so a refused --out makes no work directory and never calls gh. The question makes, opens and removes nothing: it is os.path and os.access alone. It refuses, each by name:
    • a path that is itself a folder, or is the --work-dir, which the run makes a folder;
    • a folder it goes in that does not exist, unless this run makes it (below);
    • a folder it goes in that is a file or lies under one;
    • a folder it goes in that cannot be reached (stat fails for another reason);
    • a folder this user cannot write in, which includes the default adoption-plan.yaml in an unwritable current directory;
    • a file already there that is not a regular file (a pipe, a device), or that this user cannot write.
  • One new code, adopt-out-unwritable. One code, because the person's next act is the same for all of them: pass an --out that names a file in a folder this user can write in, making the folder first if need be. The detail names which case it was, and spells the folder as it was typed (nope/.. is nope/.., never the folder it would collapse to, which exists). It has the adopt- prefix of adopt-work-dir-unwritable and adopt-unwritable-value, the refusals plan makes of a flag. The plan-* codes are check's findings about a plan file, so plan-out-unwritable would read as one.
  • Backstop. An OSError from write_lf is the same refusal. It is for what the question cannot see: a full disk or a quota, a folder that went after the question, a file name too long, a dangling symlink, and on Windows a folder's ACL (os.access reads only the read-only attribute there). On Linux os.access is the kernel's own check, so a read-only mount is refused up front. Only a write that fails for want of room (ENOSPC, EDQUOT, EIO, EFBIG) says what lies at --out may be cut short, and its way out is "Free space, or pass an --out on another file system."; any other failed write keeps the ordinary way out and says nothing of a cut file.
  • A change from main. --out /dev/null exited 0 on main (plan written to /dev/null, the plan thrown away), and a named pipe blocked for ever. Both are now refused as not a regular file, as every pipe and device is.
  • L1-79. plan written to <out> is printed right after write_lf succeeds and args.plan_written is set, before the report reads more of the source. A later read that fails (symlink_targets' git cat-file --batch) still leaves the line, and the exit code is unchanged (2). _print_plan_report no longer takes out and no longer prints the line; it prints a blank line before the questions, as the line did. So every plan's stdout now starts with a blank line and plan written to <out>, where main printed that line after the summary and before the questions. Nothing else printed or written changes (two sources compared byte for byte).
  • --out has --help that names the code on one line, and docs/cli.md is regenerated.

Why (repro on main)

Probed on bf1f099 and again on 24a977c, with a stub gh first on PATH that logs its calls, GH_TOKEN=bogus-w799, an empty GH_CONFIG_DIR, and git 2.43.0. No real gh was run.

  • L1-89. Each ended in a traceback at write_lf(out, ...), exit 1, with no REFUSED line and no remedy:
    • --out <dir>/nope/adoption-plan.yaml: FileNotFoundError: [Errno 2];
    • --out <an existing folder>: IsADirectoryError: [Errno 21];
    • --out <a folder nobody can write in>/adoption-plan.yaml: PermissionError: [Errno 13].
  • Each had by then done all the work. With --work-dir W given, W was made and stayed. With --source acme/Atlas, the stub gh was called with repo clone acme/Atlas <W>/source-readonly/Atlas -- --quiet, and the plan was built before the write failed. That holds for --out W/plans/adoption-plan.yaml too, the most natural slip, which the first version of this PR still let through.
  • A named pipe as --out blocks write_lf for ever, after the whole plan is built.
  • L1-79. With git cat-file --batch made to fail (a git wrapper first on PATH, a source holding a symlink whose target is not empty): the run exited 2 with REFUSED git-failed: ... cat-file --batch, the plan was on disk, and "plan written to" was never printed.

How

All of it is in adopt-project.py, and docs/cli.md.

  • _refuse_an_unwritable_out(args) is called in cmd_plan straight after the --pin-source refusals. It asks _why_out_cannot_be_written, which asks os.path.isdir (or --out being the --work-dir), then os.path.exists:
    • something there: _why_the_file_there_is_no_plan (a regular file this user can write, by os.access);
    • nothing there: _why_the_folder_holds_no_plan (os.stat of the folder, then os.access(folder, W_OK | X_OK)).
      os.path is used and not Path.exists, because the second raises on EACCES where the first answers False.
  • The --work-dir exemption covers only the folders the run makes (_out_is_made_by_this_run). A missing folder is left to the write when it is, read with os.path.realpath as _work_root reads the directory:
    • the --work-dir, or a folder above it that _work_root makes with it (--work-dir Am/B/W --out Am/plan.yaml, Am missing; --work-dir W --out W/../c-plan.yaml, W missing);
    • W/source-readonly, or one folder below it, which Source.clone makes for an org/repo source (a local source's is not told apart: nothing makes it, and the backstop refuses it).
      The folder, and the first part of it that is missing (walked as typed, so nope/.. counts as missing as long as nope is), must both be among those. Anything else, W/nope/plan.yaml first, is refused before any clone, whether W exists or not. test_a_plan_cut_short_after_it_is_written_keeps_its_clone (its --out is in the clone's own folder) and --work-dir W --out W/plan.yaml still pass. The reviewer is asked to attack this.
  • _write_the_plan is the backstop. _out_folder names the folder with Path.absolute, which does not collapse ...
  • Order. A bad --pin-source is still refused first. --out is asked after it and before --work-dir and --source, so a run with both a bad --out and a bad --source names the --out.

The refusal texts (<f> is the folder, as typed and made absolute; every one begins with the first line and ends with the second, where <fix> is "Pass an --out that names a file in a folder this user can write in, making the folder first if it is not there." unless the row says otherwise):

REFUSED adopt-out-unwritable: --out `<out>` cannot be written: <why>
Remediation: no plan was written. <fix>
the case <why>
a folder that is not there (and the run does not make it) the folder it goes in, <f>, does not exist
--out is a folder, or the --work-dir (and --out '') it is a folder, and the plan is one file
a folder nobody can write in, the default --out in an unwritable current directory included this user cannot write in the folder it goes in, <f>
the folder is a file or under one the folder it goes in, <f>, is a file or lies under one
the folder cannot be searched the folder it goes in, <f>, cannot be reached (Permission denied)
a file there this user cannot write the file already there cannot be written: this user has no write permission on it
a pipe or a device there what is already there is not a regular file, and the plan is one
the write fails after all, for want of room writing it failed (<the system's reason>); <fix> is "Free space, or pass an --out on another file system. If the write began, what now lies at that path is cut short and is not a plan."
the write fails after all, any other way writing it failed (<the system's reason>)

Tests

New: tests/test_adopt_plan_out_checked.py, 27 tests. Each fails with its change reverted; 23 of the 27 fail on main (the other four are controls main also passes: a plain run, --work-dir W --out W/plan.yaml, --work-dir Am/B/W --out Am/plan.yaml and --out W/../c-plan.yaml).

  • the three cases of L1-89, each with a local and an org/repo source: exit 2, the refusal alone on stderr, nothing on stdout, a --work-dir that is not there before is not there after, and the suite's gh log is empty;
  • the default --out in an unwritable current directory;
  • the folder under a file, the folder nobody can search, a file nobody can write (kept as it was), and a pipe and /dev/full (a named pipe with no reader would block an open, so these run with a timeout);
  • the --work-dir exemption, both ways: W/nope/plan.yaml is refused before any clone (0 gh calls, W not made, and also with W there), --out W is refused as a folder, --work-dir Am/B/W --out Am/plan.yaml and --out W/../c-plan.yaml are written, --out W/plan.yaml is, and nope/.. is not mistaken for the work directory's parent and is named as typed;
  • the backstop in this process: a folder that goes after the question (ordinary way out), a write that fails with each of ENOSPC, EDQUOT, EIO and EFBIG (the room way out and the cut-short sentence), and ENAMETOOLONG (the ordinary one);
  • L1-79: cat-file --batch made to fail, "plan written to" printed once the plan is on disk and the run exits 2; and a run that reads fine says it once, before the report;
  • --help names the code, and on one line.

Revert table (tests/test_adopt_plan_out_checked.py, tests/test_adopt_source_clone_record.py and tests/test_cli_reference.py, on ab5d46b; unreverted: 100 passed):

change reverted alone tests that fail
the call in cmd_plan 13: not-there, folder, nobody-can-write, default-out, under-a-file, file-nobody-can-write, nobody-can-search, pipe, device, ..._the_run_does_not_make_is_refused_before_any_clone, ..._the_work_dir_is_already_there (and the gh guard's teardown error on it, the clone having started), ..._is_the_work_dir_is_refused_as_a_folder, ..._dot_dot_through_a_folder_nothing_makes...
_write_the_plan's try 6: ..._goes_after_the_question..., the four ..._for_want_of_room..., ..._any_other_failed_write...
"plan written to" back at the end of the report 2: ..._printed_though_a_later_read_fails, ..._says_it_once_before_the_report
the exemption removed (_out_is_made_by_this_run is False) 4: ..._the_work_dir_the_run_makes_is_still_planned_into, ..._beside_a_work_dir..., ..._goes_back_out_of_the_work_dir..., and test_adopt_source_clone_record.py::test_a_plan_cut_short_after_it_is_written_keeps_its_clone
the exemption as the first commit had it (anything below --work-dir) 4 and 1 error: ..._before_any_clone, ..._the_work_dir_is_already_there, ..._beside_a_work_dir..., ..._goes_back_out_of_the_work_dir...
the first missing part of the folder not asked 1: ..._dot_dot_through_a_folder_nothing_makes...
--out being the --work-dir not asked 1: ..._is_the_work_dir_is_refused_as_a_folder
os.path.abspath for the folder's name 1: ..._dot_dot_through_a_folder_nothing_makes...
the cut-short sentence for every failed write 2: ..._goes_after_the_question..., ..._any_other_failed_write...
the cut-short sentence for none 4: the ..._for_want_of_room... ones
not a regular file not asked 2: pipe (a timeout), device
the --out help 7: the two help tests and 5 in test_cli_reference.py
main's adopt-project.py and docs/cli.md 23 of the 27

Both modes, on head ab5d46b (tree bbbe3204), dirty 0, every log ending EXIT=0: the 98 files of grep -l -E 'adopt-project|adopt_project|\bADOPT\b' tests/*.py (97, with tests/test_shape_doctor.py and tests/test_scaffold_leg_path_collisions.py among them) plus tests/test_cli_reference.py, in three shards of each mode with a stub gh first on PATH, GH_TOKEN=bogus-w799 and an empty GH_CONFIG_DIR:

mode shard 0 shard 1 shard 2
git-filter-repo on PATH 2023 passed, 4 skipped, 1 xfailed 2254 passed, 1 skipped 2613 passed, 8 skipped
git-filter-repo hidden (PATH=<stub gh dir>:/usr/local/bin:/usr/bin:/bin) 1934 passed, 93 skipped, 1 xfailed 2111 passed, 144 skipped 2466 passed, 155 skipped

Totals: 6890 passed, 13 skipped, 1 xfailed with the filter; 6511 passed, 392 skipped, 1 xfailed without it. No test failed in either mode. scripts/render-cli-reference.py --check says docs/cli.md is what the generator produces.

Windows: CI is Linux only (#597). The tests that need chmod to remove write or search permission skip where it cannot (root, Windows), the pipe test skips where there is no os.mkfifo, and the git wrapper test skips on win32. Every path is legal on NTFS.

Not in this PR

Known limits (also on the #457 checklist):

  • os.access answers for the real user, so what it passes and the write still refuses (a full disk, a quota, a file name too long, a Windows ACL) is refused by the backstop after the work. A read-only mount is refused up front, and root writes where the mode bits say no, as on main.
  • A write that fails for want of room leaves a cut-short file at --out. The refusal says so; nothing removes it.
  • An --out file name longer than NAME_MAX, a dangling symlink into a missing folder, and a symlink loop are the backstop's, after the work.
  • W/source-readonly/<name>/plan.yaml with a local source passes the question (nothing makes that folder) and is the backstop's.
  • On a case-insensitive disk (macOS), --work-dir Work --out work/plan.yaml with both missing is refused as "does not exist", where main wrote it; the paths are compared as spelled.
  • With an org/repo source, --out W/source-readonly/<a misspelt repo>/plan.yaml passes the question and is refused by the backstop after the clone. --out W/source-readonly/<repo>/<a folder the repository holds>/plan.yaml, which main wrote once the clone had made that folder, is now refused as "does not exist".

Closes #799

🤖 Generated with Claude Code

Summary by Sourcery

Validate plan output paths before starting work and confirm the plan is written as soon as it reaches disk.

New Features:

  • Validate plan output destinations before doing source or work-directory processing, with clear adopt-out-unwritable refusals for invalid, inaccessible, or non-regular targets.
  • Report that the plan was written immediately after a successful write, even if later report generation fails.

Bug Fixes:

  • Prevent tracebacks, hangs, and unnecessary cloning or work-directory creation when --out points to an unusable destination.
  • Handle write-time failures consistently, including guidance for errors that may leave a partially written plan.

Enhancements:

  • Allow only directories created as part of the run to be initially missing while validating output paths.
  • Update CLI help and generated documentation to describe output validation and refusal behavior.

Documentation:

  • Regenerate the CLI reference with the expanded plan --out behavior.

Tests:

  • Add comprehensive coverage for output-path validation, pre-work refusals, write-time failures, output timing, and help text.

Brett Heap and others added 3 commits October 17, 2026 11:04
…ect.py: `plan` asks `--out` with the flags and refuses a folder, a missing folder or one nobody can write in as `adopt-out-unwritable` before any work directory or clone, a write that fails anyway is the same refusal, and `plan written to` prints the moment the plan is on disk, so a bad `--out` no longer ends in a traceback after the whole plan is built and a later read no longer hides that the plan exists (#799)

Lane: openreposhape-1 (openRepoShape-1)
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Lane: openreposhape-1 (openRepoShape-1)
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…, opens and removes nothing and refuses a pipe or a device by name, so a named pipe no longer blocks it and the check no longer leaves the real file where a later step refuses (#799)

Lane: openreposhape-1 (openRepoShape-1)
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@sourcery-ai

sourcery-ai Bot commented Oct 17, 2026

Copy link
Copy Markdown

Reviewer's Guide

The PR makes plan validate --out non-destructively before any source or workspace work, uses a consistent adopt-out-unwritable refusal for preflight and write-time failures, and announces the plan immediately after it reaches disk; CLI documentation and extensive edge-case tests cover the new behavior.

Sequence diagram for plan output validation and writing

sequenceDiagram
    actor User
    participant CLI as adopt-project.py
    participant FS as File system
    participant Source
    participant Report

    User->>CLI: plan --out OUT
    CLI->>FS: _refuse_an_unwritable_out(args)
    FS-->>CLI: writable or refusal reason
    alt OUT is unwritable
        CLI-->>User: REFUSED adopt-out-unwritable
        Note over CLI,FS: No work directory, source read, clone, or plan write
    else OUT is acceptable
        CLI->>Source: _work_root and source processing
        Source-->>CLI: rendered plan text
        CLI->>FS: _write_the_plan(args, out, text)
        alt write fails
            FS-->>CLI: OSError
            CLI-->>User: REFUSED adopt-out-unwritable
        else write succeeds
            FS-->>CLI: plan on disk
            CLI-->>User: plan written to OUT
            CLI->>Report: _print_plan_report(...)
            Report-->>User: plan report
        end
    end
Loading

File-Level Changes

Change Details Files
Validate the plan output destination before doing work and normalize all output-write failures into a structured refusal.
  • Probe folders, existing files, pipes, devices, missing paths, and permissions without side effects.
  • Allow missing output directories that will be created under --work-dir.
  • Add the adopt-out-unwritable refusal with remediation and a write-time OSError backstop, including partial-file warnings.
  • Run the validation before work-directory creation, source access, or cloning.
adopt-project.py
Report plan creation at the moment the plan is successfully persisted.
  • Print plan written to immediately after the write and before subsequent source-report reads.
  • Preserve the message when later report processing fails while retaining the existing exit behavior.
  • Remove output-path handling from the report helper while preserving report formatting.
adopt-project.py
Document and comprehensively test output validation and write-reporting behavior.
  • Add coverage for invalid destinations, permission and race conditions, work-directory exceptions, special files, and failed later reads.
  • Verify help text and generated CLI documentation identify the new refusal code and behavior.
tests/test_adopt_plan_out_checked.py
docs/cli.md
adopt-project.py

Assessment against linked issues

Issue Objective Addressed Explanation
#799 Check that --out names a writable file location before doing any work, and refuse invalid paths by name with PLAN_NOT_WRITTEN and a remedy. ❌ The PR preflights most invalid paths, but deliberately exempts missing output folders below --work-dir. For an output such as W/nope/plan.yaml, it proceeds with work and reads the source before the write fails, contrary to the issue's requirement to check that the folder exists before doing any work.
#799 Convert an OSError from writing the plan into the same named refusal, including guidance when a partial file may remain. ✅
#799 Print “plan written to” immediately after the plan is successfully written, before later report reads can fail. ✅

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@brettheap

Copy link
Copy Markdown
Contributor Author

(lane openRepoShape-1, 2026-10-17T19:15:03Z) Lane 1's independent review of #833 at 8295c1e: CHANGES NEEDED

The --out question works, and nothing runs before a refusal. Two things need a small fix round. The --work-dir exemption does not match the folders the run actually makes. And the code, its docstrings and the body all say os.access misses a read-only mount and root, which is false.

Setup. Reviewed read-only at 8295c1ebfe1c32277bb363a1fbd68883f58d7409. A local-only merge with main bad05d21 is clean (Auto-merging adopt-project.py) and gives 68cf44ee. Every probe ran with:

  • a stub gh first on PATH, which logs its calls and exits 97, or for repo clone only makes a local fake clone;
  • a git wrapper that logs every call;
  • GH_TOKEN=bogus-r799, an empty GH_CONFIG_DIR, GIT_CONFIG_GLOBAL=/dev/null and GIT_ALLOW_PROTOCOL=file.

Below, plan <src> … means adopt-project.py plan --source <src> --project Thing --org testorg --elected-by 'Test Human' --elected-on 2026-09-02 (--project Atlas --org acme for acme/Atlas).

The issue's lines

  • L1-89: fixed. On main, a local source fails as follows (exit 1), and with acme/Atlas plus --work-dir the work directory is made and gh repo clone is called:

    • nope/plan.yaml gives FileNotFoundError: [Errno 2];
    • an existing folder gives IsADirectoryError: [Errno 21];
    • a folder with mode 500 gives PermissionError: [Errno 13].

    On the merge each case exits 2 with REFUSED adopt-out-unwritable, 0 git calls, 0 gh calls and no work directory.

  • L1-79: fixed. With git cat-file --batch made to fail, main exits 2 with the plan on disk and no plan written to. The merge exits 2 with the plan on disk, prints plan written to <out> on stdout, then REFUSED git-failed: git cat-file --batch … on stderr. The exit code is unchanged and the line is printed once.

Nothing runs before a refusal (attack 2)

Each <why> row was run with a local source and with acme/Atlas, and with --work-dir <missing W> and TMPDIR set to an empty folder. The rows: missing folder, folder, mode-500 folder, default --out in a mode-500 current directory, under a file, unsearchable folder, read-only file, FIFO, /dev/null, /dev/full.

All 20 runs exited 2, with calls (0) (no git, no gh), W not made and no temp work directory.

The FIFO returns at once on the merge. On main it blocks until killed (TIMEOUT at 15 s, leaving a temp openreposhape-adopt-* folder behind).

Findings, ranked

F1 (should fix). The --work-dir exemption does not match what the run makes. It is too wide and too narrow at once. _work_root makes W and W's missing parents. Source.clone makes W/source-readonly/<repo>. Yet any missing folder anywhere below W skips the question, and W's parents do not.

Too wide. plan acme/Atlas --work-dir W3 --out W3/nope/plan.yaml:

  • main: cloning acme/Atlas (read only) into …/W3/source-readonly/Atlas, then FileNotFoundError: [Errno 2], exit 1.
  • merge: the same cloning … line, with gh repo clone called, then this, exit 2:
    REFUSED adopt-out-unwritable: --out W3/nope/plan.yaml cannot be written: writing it failed (No such file or directory)

W3 is left behind, empty; the clone is removed. So for the most natural slip, --out W/plans/adoption-plan.yaml, L1-89 still does all the work first. That holds whether W already exists or not.

Too narrow. Each of these was allowed or got further on main:

  • --work-dir Am/B/W --out Am/plan.yaml, with Am missing: main exits 0, because mkdir(parents=True) makes Am. The merge exits 2 with the folder it goes in, …/Amerge, does not exist.
  • --work-dir W3 --out W3/../c-plan.yaml, with W3 missing: main exits 0. The merge refuses with a false message (see F3).
  • --work-dir W2 --out W2, with W2 missing: the question passes, the whole plan is built, then writing it failed (Is a directory) follows, with the cut-short sentence even though nothing was opened.
  • On macOS (case-insensitive disk, PosixPath compares case-sensitively), --work-dir Work --out work/plan.yaml would be refused where main wrote it. Not probed; this machine is Linux.

Fix. Exempt only the folders the run makes: realpath(out.parent) is realpath(W) or one of its missing ancestors, or, for an org/repo source, W/source-readonly or W/source-readonly/<repo>. Refuse realpath(out) == realpath(W) as "it is a folder". With that rule:

  • test_a_plan_cut_short_after_it_is_written_keeps_its_clone, whose --out is in the clone folder, still passes;
  • --work-dir W --out W/plan.yaml still works;
  • W/nope/… is refused before any clone.

F2 (should fix: false text in code and body). os.access does see a read-only mount, and root is not a backstop case. Repro: under unshare -rm, mount -t tmpfs -o ro tmpfs romnt, then plan Thing --out romnt/plan.yaml:

  • main: OSError: [Errno 30] Read-only file system, exit 1, 8 git calls.
  • merge: refused up front, with calls (0), not by the backstop, exit 2:
    REFUSED adopt-out-unwritable: --out romnt/plan.yamlcannot be written: this user cannot write in the folder it goes in,…/romnt``

As namespace root, --out rootonly/plan.yaml (mode 500) exits 0 on both, because root simply writes.

On Linux, access(2) runs the kernel's own permission check, POSIX ACLs included. I could not probe this, because setfacl is not on this machine. On Windows, os.access reads only the read-only attribute, so there an ACL is the backstop's.

The false claim appears in four places: the _why_out_cannot_be_written docstring, the test module docstring, the body's How (Backstop bullet) and Known limits.

F3 (low). The refusal can call an existing folder missing. _out_folder uses os.path.abspath, which collapses nope/.. as text. The kernel does not: it needs nope to exist.

Repro: plan Thing --out nope/../plan.yaml:

  • main: FileNotFoundError: [Errno 2], exit 1.
  • merge: … the folder it goes in, , does not exist, exit 2. The current directory exists.

Fix: _spelled(str(out.parent.absolute())). Path.absolute does not normalize, so it names <cwd>/nope/... The tests' where() still matches.

F4 (low). The backstop's remedy is off for a full disk. Repro: a 4 KiB tmpfs, a 15,014-byte plan, and an old plan already at --out:

  • main: OSError: [Errno 28], exit 1.
  • merge: writing it failed (No space left on device), exit 2. The old plan is gone; 4096 bytes starting schema_version: 1 are left.

check --plan on such a cut file refuses it at all three cut points tried (yaml-unparsable, plan-uncovered, plan-unresolved), so a cut plan never passes. But the remedy, "Pass an --out … making the folder first", is not the fix for a full disk. And "If the write began, …" is also added when the open itself failed (EISDIR, ENOENT, ELOOP, ENAMETOOLONG), where nothing was touched.

Suggested: add OUT_CUT_SHORT only for ENOSPC, EDQUOT, EIO and EFBIG, with "Free space, or pass an --out on another file system."

F5 (text). The change to every ordinary run's output is not stated plainly. I compared two sources byte for byte: the small Thing and conftest's SYNTHETIC_TREE.

  • The plan files and stderr are identical.
  • Stdout differs only in where the line sits. On the merge, stdout begins \nplan written to Thing.yaml\nsource …. On main, the line came after the summary: it was the last line for Thing, and came just before the questions for Synth.

This is intended per the brief, but the body should say it. A nit: a local source's stdout now begins with an empty line.

What is refused now that main allowed (attack 3)

--out main merge intended and stated?
/dev/null exit 0, plan written to /dev/null refused as not a regular file stated, but under Known limits; it belongs in What
FIFO blocks until killed refused at once, 0 calls yes
/dev/full fails at the write refused at once yes
an existing read-only file PermissionError refused, file kept yes
dangling symlink, existing folder exit 0 exit 0 unchanged
dangling symlink into a missing folder; symlink loop traceback backstop, after the work stated

Two further changes:

  • --work-dir <a file> --out <that file>/plan.yaml: main refused adopt-work-dir-unwritable; the merge refuses adopt-out-unwritable … is a file or lies under one. Both are valid.
  • /dev/null (and NUL on Windows) can no longer serve as "report only, plan discarded". That is the coordinator's call.

Tests, Sonar, Windows

  • Revert rows, re-run on the merge: all four match the writer's table.

    change reverted result
    the call in cmd_plan 9 failed, the exact names, the pipe by its 60 s timeout
    _write_the_plan's try 3 failed
    "plan written to" back at the end 2 failed
    the exemption 3 failed, test_a_plan_cut_short_after_it_is_written_keeps_its_clone among them
  • Asserts are honest. Nit: the pipe/device test passes no --work-dir and checks no gh log.

  • Gate on merge 68cf44ee, dirty 0, git-filter-repo on PATH. The files: test_adopt_plan_out_checked, test_cli_reference, test_shape_doctor, test_scaffold_leg_path_collisions and test_adopt_source_clone_record, plus the adopt test files main changed since 24a977c0 (test_adopt_e2e, test_adopt_pins, test_adopt_plan_yaml_quoting, test_pin_source_unreadable, test_reader_refusals_named, test_yaml_indicator_openers). Result: 1681 passed, 3 skipped, 1 xfailed in 973.86s, EXIT=0.

  • CI: SonarCloud passes with 0 new issues and 0.0% duplication; tests, tests-git-bash and package pass. The annotations are only the Node 20 and ubuntu-latest notices.

  • Windows: the names are legal on NTFS. WindowsPath compares case-insensitively, so the exemption holds there. os.access always calls a Windows folder writable, so those rows go to the backstop there; the tests skip correctly. NUL and CON are now refused, the same change as /dev/null.

  • Texts:

    • The title is true.
    • The body has the Lane line, a Claim line that matches claim-urls.tsv, Closes #799 and the robot line, in 11,989 characters. Sourcery's summary sits after the robot line.
    • The commit trailers read Co-Authored-By: Claude Sonnet 5.5. That is accurate, since the writer was Sonnet, but it is not the brief's Opus line; settle it in the squash message.

Exact text replacements

  1. Body, How, Backstop bullet. Replace "It is for what os.access cannot see (an ACL, a read-only mount, a full disk, a folder that went after the question)." with:

    It is for what the question cannot see: a full disk or a quota, a folder that went after the question, a file name too long, a dangling symlink, and on Windows a folder's ACL (os.access reads only the read-only attribute there). On Linux os.access is the kernel's own check, so a read-only mount is refused up front.

  2. Body, Known limits. Replace "os.access is what the person's permissions say, so an ACL, a read-only mount and being root are the backstop's." with:

    os.access answers for the real user, so what it passes and the write still refuses (a full disk, a quota, a file name too long, a Windows ACL) is refused by the backstop after the work. A read-only mount is refused up front, and root writes where the mode bits say no, as on main.

  3. Body. Move the /dev/null bullet out of Known limits and into What, as:

    A change from main. --out /dev/null exited 0 on main (plan written to /dev/null, the plan thrown away), and a named pipe blocked for ever. Both are now refused as not a regular file, as every pipe and device is.

  4. Body, What, L1-79 bullet. Append:

    So every plan's stdout now starts with a blank line and plan written to <out>, where main printed that line after the summary and before the questions. Nothing else printed or written changes (two sources compared byte for byte).

  5. Code, _why_out_cannot_be_written. Replace "os.access is what a person's permissions say, and not what an ACL, a read-only mount, a full disk or being root say, so" with:

    os.access is the system's answer for the real user, a read-only mount included, and not what a full disk, a quota or a Windows ACL say, so

    Test module docstring. Replace "(an ACL, a read-only mount, a full disk, being root)" with "(a full disk, a quota, a Windows ACL)".

  6. --out help and docs/cli.md. If F1 is fixed, replace "A folder below --work-dir is not asked for, because the run makes that directory." with:

    The --work-dir, and for an org/repo source its source-readonly/<repo>, may be missing: the run makes them.

    If F1 is not fixed, replace it with:

    A missing folder below --work-dir is not asked about here, since the run makes the --work-dir; one the run does not make is refused at the write.

For the checklist

  • An --out file name longer than NAME_MAX goes to the backstop after the work (writing it failed (File name too long), 8 git calls). os.pathconf(folder, 'PC_NAME_MAX') could ask it first.
  • A dangling symlink into a missing folder, or a symlink loop, at --out goes to the backstop after the work. os.path.lexists plus the folder of the link's realpath could ask first.
  • --out '' prints --out cannot be written: it is a folder``. "Names no file" would read better, as --pin-source '' has it.
  • --out newdir/ with a trailing slash and a missing folder: pathlib strips the slash and the plan is written as a file named newdir. Main does the same.
  • A full disk destroys the old plan at --out. A temporary file plus os.replace in _write_the_plan would keep it; write_lf is shared, so not in this PR.
  • The macOS case twin under the exemption (F1).

Lane: openreposhape-1 (openRepoShape-1)

…covers only the folders the run makes, `--out` that is the `--work-dir` is refused as a folder, the missing folder is named as typed, and only a write that fails for want of room says the file may be cut short, so `<work>/nope/plan.yaml` no longer clones first and `nope/..` no longer names a folder that exists as missing (#799)

Lane: openreposhape-1 (openRepoShape-1)
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@brettheap

Copy link
Copy Markdown
Contributor Author

(lane openRepoShape-1, 2026-10-17T19:52:30Z) Lane 1's re-verification of #833 at ab5d46b: PR-READY

The code, tests and texts are ready, and SonarCloud is green. One check is still open: the tests job was still running at 19:51Z, so confirm it is green before landing.

Setup. Head ab5d46b7651fff2be90f7304e0d66bf8256ad1d3 is one commit on 8295c1eb. A local-only merge with current main fc867207 is clean (Auto-merging adopt-project.py); main changed no adopt file since bad05d21. Every probe ran with a stub gh first on PATH that logs its calls, a git wrapper that logs every call, GH_TOKEN=bogus-r799, an empty GH_CONFIG_DIR, GIT_CONFIG_GLOBAL=/dev/null and GIT_ALLOW_PROTOCOL=file. Each case below was run on main fc867207 and on the merge.

F1 to F5: all resolved

F1, the --work-dir exemption: resolved.

case main merge
acme/Atlas --work-dir W3 --out W3/nope/plan.yaml, W3 missing gh repo clone called, then FileNotFoundError, exit 1, W3 made exit 2, calls (0), W3 not made
--work-dir Wx --out Wx/plans/plan.yaml, Wx there gh repo clone called, then FileNotFoundError refused, calls (0), Wx still empty
--work-dir Am/B/W --out Am/plan.yaml exit 0 exit 0
--work-dir W4 --out W4/../c-plan.yaml, W4 missing exit 0 exit 0, c-plan.yaml written
--work-dir W2 --out W2, W2 missing IsADirectoryError, exit 1, W2 made it is a folder, and the plan is one file, exit 2, calls (0), W2 not made
dot-dot rule: --work-dir W5 --out nope/../plan.yaml FileNotFoundError, exit 1 the folder it goes in, …/nope/.., does not exist, exit 2, calls (0), W5 not made

The W3 refusal on the merge reads:
REFUSED adopt-out-unwritable: --out W3/nope/plan.yamlcannot be written: the folder it goes in,…/W3/nope, does not exist

These still work on the merge, each exit 0:

  • --work-dir L where L is a symlink to a missing T, with --out L/plan.yaml (written in T);
  • --out Sd/plan.yaml where Sd is a symlink to the missing work directory;
  • acme/Atlas --work-dir Wc --out Wc/source-readonly/Atlas/plan.yaml.

F2, the os.access texts: resolved. The docstring, the test module docstring and the body are true now. In a user namespace with a read-only tmpfs, the merge refuses up front, calls (0), exit 2:
REFUSED adopt-out-unwritable: --out romnt/plan.yaml cannot be written: this user cannot write in the folder it goes in, …

F3, the folder named in the refusal: resolved. The folder is spelled as typed (…/nope/..), never as the current directory it would collapse to.

F4, the backstop's remedy: resolved.

  • A real full disk (a 4 KiB tmpfs) gives writing it failed (No space left on device) and Remediation: no plan was written. Free space, or pass an --out on another file system. If the write began, what now lies at that path is cut short and is not a plan.
  • A 300-character file name gives the ordinary remedy with no cut-short sentence.

F5, texts: resolved. The /dev/null and pipe change is now under What, and the stdout-order note is in the L1-79 bullet. The help is in its "F1 fixed" form, and docs/cli.md matches it.

Nothing runs before a refusal

26 rows, each with a local source and with acme/Atlas, and with --work-dir <missing W> and an empty TMPDIR. The rows: missing folder, folder, mode-500 folder, default --out in a mode-500 current directory, under a file, unsearchable folder, read-only file, FIFO, /dev/null, /dev/full, W/nope/plan.yaml, --out W, nope/../plan.yaml.

Every row exited 2 with one REFUSED adopt-out-unwritable line, calls (0) (no git, no gh), W not made and no temp work directory. The FIFO returns at once.

The diff changes nothing else

  • The fix commit touches only adopt-project.py, docs/cli.md and tests/test_adopt_plan_out_checked.py. In adopt-project.py it adds import errno and changes only the --out helpers, _write_the_plan and the --out help.
  • Ordinary runs were compared byte for byte against main on two sources (a small one and conftest's SYNTHETIC_TREE). The plan files and stderr are identical. Stdout differs only by the stated move of plan written to.

Revert rows and gate

Three revert rows, re-run on the merge, all match the writer's table:

change reverted result
the exemption as at 8295c1eb 4 failed, 23 passed, 1 error: …before_any_clone, …work_dir_is_already_there (failed, plus the error), …beside_a_work_dir…, …goes_back_out_of_the_work_dir…
os.path.abspath for the folder's name 1 failed: …dot_dot_through_a_folder_nothing_makes…
the cut-short sentence for every failed write 2 failed: …goes_after_the_question…, …any_other_failed_write…

The gate ran on the merge, dirty 0, with git-filter-repo on PATH, over test_adopt_plan_out_checked.py, test_cli_reference.py and test_adopt_source_clone_record.py: 100 passed in 57.73s, EXIT=0.

CI and the body

  • CI at ab5d46b7:
    • SonarCloud passes the quality gate with 0 new issues, 0 security hotspots and 0.0% duplication.
    • package and tests-git-bash pass.
    • tests started at 19:19:42Z and was still running at 19:51Z; it took 58 minutes last round. Confirm it is green before landing.
  • Body: every claim I probed is true at the head. It has the Lane and Claim lines, Closes #799 and the robot line, in 14,751 characters. The title is unchanged and still true. The commit trailer reads Co-Authored-By: Claude Sonnet 5.5, which is accurate; settle it in the squash message.

Optional text edits (not blocking)

  1. Body, How, the exemption bullet. Replace "(walked as typed, so nope/.. is missing while nope is)" with "(walked as typed, so nope/.. counts as missing as long as nope is)".

  2. Body, Known limits. Add:

    With an org/repo source, --out W/source-readonly/<a misspelt repo>/plan.yaml passes the question and is refused by the backstop after the clone. --out W/source-readonly/<repo>/<a folder the repository holds>/plan.yaml, which main wrote once the clone had made that folder, is now refused as "does not exist".

    Both were probed. The misspelt name went through gh repo clone (7 calls), then writing it failed (No such file or directory). For the folder the repository holds, main exited 0 and the merge refused with calls (0).

For the checklist

  • _first_missing_part steps back over .. by name. Through a symlinked folder the kernel steps back to the target's parent instead, so link/../x could be judged on the wrong folder. Contrived; it affects only whether the exemption applies.
  • The two source-readonly cases in text edit 2.

Both optional text edits are applied (the PR body is edited; no push).

Lane: openreposhape-1 (openRepoShape-1)

@brettheap

Copy link
Copy Markdown
Contributor Author

(lane openRepoShape-1, 2026-10-17T19:53:06Z) Correction to issuecomment-6239966171: when that comment was posted, only optional text edit 1 was in the body. Edit 2, the Known-limits bullet on W/source-readonly/<misspelt repo> and on a folder the repository holds, is applied now. The PR body is edited; there is no push.

Lane: openreposhape-1 (openRepoShape-1)

@sonarqubecloud

Copy link
Copy Markdown

@brettheap
brettheap marked this pull request as ready for review October 18, 2026 02:21
@sourcery-ai

sourcery-ai Bot commented Oct 18, 2026

Copy link
Copy Markdown

Sorry @brettheap, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 3 days and 16 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@brettheap
brettheap merged commit 3fb30a8 into main Oct 18, 2026
5 checks passed
@brettheap
brettheap deleted the fix/799-adopt-plan-out-checked branch October 18, 2026 02:22
brettheap pushed a commit that referenced this pull request Oct 18, 2026
Main at 3fb30a8, 37 commits past
24a977c, with #830 (#797, 51414d2) and #833 (#799, 3fb30a8).
adopt-project.py conflicted in eight hunks; docs/cli.md merged by
itself. Each keeps both sides:
- `Source.open`, `Source.of` and `Source.in_place` take #797's
  `instead` and hand it on to `clone`, `in_place` and `_at`; `in_place`
  still takes the top level `_top_level` resolved.
- `_source_named` (#796) and #799's `OUT_UNWRITABLE` block and
  `_write_the_plan` stand side by side.
- `cmd_plan` asks `--out` first (#799: the flags and the file system
  alone), then `_source_spec` (#796), both before `_work_root`, and
  opens the source with `Source.of(named, ..., instead=args.tracking_branch)`.
- `Plan.open_source` keeps `override is not None` and the empty
  `local_path` refusal (#796) and passes `self.read_at` (#797), and
  `_recorded_source` holds a path the person gave to `_top_level` and
  passes `self.read_at` at both `Source.in_place` calls.

Lane: openreposhape-1 (openRepoShape-1)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
brettheap added a commit that referenced this pull request Oct 18, 2026
… names no repository's top level is refused by name before git reads anything else in it, so a file, a directory inside a repository, an unknown `~user`, an empty value, `owner/.git` and a lost blob no longer end in a traceback, plan a subtree or reach `gh` (#796) (#831)

`adopt-project.py` took a `--source`, or a plan's `source.local_path`, that names no repository's top level as if it did (#796). Measured on main `24a977c0`:

- a file (L1-64) ended in `NotADirectoryError`, exit 1, after `plan` had made its work directory;
- a directory inside a repository, or `.` run in one (L1-88), planned only that subtree under the repository's name; a directory inside a git directory (`<repo>/.git/objects`, `<bare>.git/refs`) planned the whole repository and recorded the inner path, and `check` and `execute` then failed on it;
- `~nouser/x` (L1-95) ended in `RuntimeError`; `--source ''` (L1-96) planned the directory `plan` ran in, and a plan recording `local_path: ""` had `check` clone the plan's repository from GitHub;
- `owner/.git` in any case (L1-100) reached `gh repo clone`; `www.github.com/o/r` (L1-101) was refused; and a source that lost a blob (L1-77) ended in `ValueError` over git's `BAD` size.

Now:

- **`_top_level`**, new: a local source must be a directory; inside a git directory it must be that git directory itself; and `git rev-parse --show-prefix` must print nothing. Otherwise it is refused under a new code, `source-not-top-level`, which names what was given (a file, `src/` inside the repository at its top level, or the git directory it is inside), with the way out: pass the top-level directory, which `git rev-parse --show-toplevel` prints, or its `org/repo`. A git directory itself (`<repo>/.git`, a bare repository, `.git/modules/<m>`, `.git/worktrees/<w>`) is read whole, as on main.
- **`_source_spec`** refuses an empty value, expands `~` with `os.path.expanduser` (so an unknown `~user` is `source-unresolvable`, not a traceback), and hands every path that exists to `_top_level`. `plan` reads `--source` before it makes its work directory; only the `--pin-source` refusals and `--out` (#833) come first. In `check` and `execute` the work directory is still asked first, as #650 ordered.
- **A recorded `source.local_path`** the person gave is held to `_top_level` too, named by its key, and an empty one is `plan-source-gone`; nothing is cloned for it. A clone `plan` made keeps #749's handling.
- **`_github_name`** refuses the repository `.git` in any case, with no `gh` call, and drops a trailing `.git` in any case; `www.github.com` is read as `github.com`. `scripts/repo_shape.py` is unchanged.
- **`Source.tree`** refuses a size that is not `-` or digits as `git-failed`, naming the path, the blob and `git fsck`.
- **The `source` report line** names the directory read, with the repository its `origin` names beside it; a clone `plan` made is still named by its repository.
- **The help** of `plan`'s, `check`'s and `execute`'s `--source` names the new code, and docs/cli.md is regenerated.

Review: lane 1's independent adversarial review found defects at `adbc5e37`. The fix round fixed them, and the re-verification found `2d51f181` PR-READY. Main was merged twice, the second time (`db202f53`) over #830's and #833's changes to `adopt-project.py`, and the re-verification found that head PR-READY too.

It lands by fast refresh (Brett Heap, 2026-10-15T22:48:35Z). Its reviewed head is green on Linux and SonarCloud. The branch merged main three times and was never rebased; the last merge is update-branch's, clean, giving 7f4d015, which is green on SonarCloud and Git Bash. The full suite passed on its tree in lane 1's gate: 240 test files, 14,677 passed and 69 skipped.

Closes #796

Lane: openreposhape-1 (openRepoShape-1)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
brettheap pushed a commit that referenced this pull request Oct 18, 2026
One conflict, in `Plan.open_source`'s `--source` branch. Main (#830 for
#797, #831 for #796) passes `self.read_at` to `Source.open`, tests
`override is not None`, and adds the docstring paragraph on an empty
override; the branch keeps the clone made at the plan's own
`source.local_path` (`_keep_the_clone_at_the_record`). Both are kept: main's
docstring, condition and argument, then the branch's call, then `return
source`.

Auto-merged as both sides wrote it: main's `instead` reaches `Source._at`
through the branch's rewritten `Source.clone`; `cmd_plan` asks `--out`
(#833) and `_source_spec` (#831) before `_work_root`'s shared-chain check;
both sides' identical `import errno` is one line.

Lane: openreposhape-1 (openRepoShape-1)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant