Skip to content

tests/test_bom_tool_io.py: the byte-order-mark rows hold each tool's own read and write and that only U+FEFF is cut, so a utf-8-sig read that drops the mark and a cut that also takes spaces no longer survive (#1176) - #1188

Merged
brettheap merged 3 commits into
mainfrom
l3-1176-bom-rows-hold-the-tools
Oct 23, 2026

Conversation

@brettheap

@brettheap brettheap commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

What changed

A follow-up outside v1.2.0 (Brett Heap, 2026-10-21T10:32:04Z). It lands only after the v1.2.0 tag, on a later merge word.

One new file, tests/test_bom_tool_io.py (126 rows), and no tool code. #1050's byte-order-mark rows (tests/test_bom_rewrites.py) hold what each line rewriter returns. They do not hold the tools' own read and write, nor that the cut in front of line 1 takes U+FEFF and nothing else, so rv1050's five mutants each passed every file that reads a pin (#1176).

  • The tools' own read and write. update-shape.py's _repin (the shape pin and the manifest, through the Rollback ledger) and bump-leg.py's _leg_pin_text, rewrite_pin and write_lf (in the order its main calls them) run over a file that starts with 0, 1 or 2 marks. The file written starts with exactly the marks it was read with, and every byte after them is the rewrite. The marks are bytes (codecs.BOM_UTF8), never typed.
  • Each tool end to end. update-shape.py apply (a local --upstream only, never the default GitHub one) on a root whose pin and manifest are committed with the marks, and bump-leg.py on a leg pin with the marks: both write the marks back, and the project's own gate is green after.
  • Only U+FEFF is cut, and only in front of line 1. Another zero-width or format (Cf) character as the second character (ZWSP, ZWNJ, ZWJ, word joiner, soft hyphen, LRM) stays: in front of the key the file is refused unchanged in each tool's words, and in front of a key of its own it is written back where it was. A space or a tab in front of the key (with no mark, behind a mark and in front of one) and a file indented two spaces on every line are refused as before update-shape.py and scripts/bump-leg.py: the three line rewriters find a first-line key after a byte-order mark, as every reader does, and write the mark back as it was (#933) #1050. A mark that is the second character of a comment is text and is written back.
  • No fault found. Every row passes at main, so no tool changes. The issue's own measurement holds: the tools keep the mark today, and only a test was missing.

Measured at main (961640c6)

  • Before: tests/test_bom_rewrites.py + tests/test_bom_reads.py = 37 passed. rv1050's five mutants (utf-8-sig at _repin's two reads and at _leg_pin_text's read; an lstrip that also cuts spaces and line feeds in _marks_off and in rewrite_pin) each pass the six files of the issue (272 passed under each).
  • After: tests/test_bom_tool_io.py = 126 passed in about 13 s. Each of the five fails 5 to 20 of its rows (table below), and every row passes without them.

Mutants

Each is one exact-once edit, run against the 3 or 6 existing files (the BOM files, plus the files that read a pin for M1 to M5 and M19 to M22) and against the new file. The tool file is restored from a saved copy after each and checked with cmp (22 of 22 cmp exit 0; git diff of the tools against HEAD is empty). Runner: W1176's own mutants.py, in the lane's scratch.

# Mutant Existing files New rows
M1 _repin reads the shape pin as utf-8-sig survives (272 passed) KILLED (20 failed)
M2 _repin reads the manifest as utf-8-sig survives (272 passed) KILLED (20 failed)
M3 _leg_pin_text reads the leg pin as utf-8-sig survives (272 passed) KILLED (20 failed)
M4 _marks_off: lstrip also cuts spaces and line feeds survives (272 passed) KILLED (10 failed)
M5 rewrite_pin: lstrip also cuts spaces and line feeds survives (272 passed) KILLED (5 failed)
M6 _marks_off: cut widened to every Cf character survives (152 passed) KILLED (24 failed)
M7 rewrite_pin: cut widened to every Cf character survives (152 passed) KILLED (12 failed)
M8 _marks_off: cut left out killed (4 failed) KILLED (6 failed)
M9 rewrite_pin: cut left out killed (2 failed) KILLED (4 failed)
M10 _marks_off: cut also applied to the second character survives (152 passed) KILLED (6 failed)
M11 rewrite_pin: cut also applied to the second character survives (152 passed) KILLED (3 failed)
M12 _marks_off: cut takes one mark only killed (2 failed) KILLED (3 failed)
M13 rewrite_pin: cut takes one mark only killed (1 failed) KILLED (2 failed)
M14 _marks_off: cut takes every mark anywhere killed (2 failed) KILLED (6 failed)
M15 rewrite_pin: cut takes every mark anywhere killed (1 failed) KILLED (3 failed)
M16 _repin writes the shape pin as utf-8-sig survives (152 passed) KILLED (22 failed)
M17 _repin writes the manifest as utf-8-sig survives (152 passed) KILLED (22 failed)
M18 write_lf (bump-leg.py's write) as utf-8-sig killed (1 failed) KILLED (22 failed)
M19 _marks_off: a space or a tab in front of the marks is cut first (lstrip(" \t"), then the marks) survives (272 passed) KILLED (10 failed)
M20 rewrite_pin: the same cut, in front of the marks, first survives (272 passed) KILLED (5 failed)
M21 _marks_off: a space or a tab is cut only where a mark follows it survives (272 passed) KILLED (4 failed, the rows with the lead in front of a mark)
M22 rewrite_pin: the same, only where a mark follows survives (272 passed) KILLED (2 failed, the same rows)

Tests

Under a stub gh (exit 97), GH_TOKEN=bogus, an empty GH_CONFIG_DIR, GIT_SSH_COMMAND=false, a scratch GIT_CONFIG_GLOBAL and [email protected], one pytest at a time. The two lines below are the first two heads', with 120 rows; the third head's gates, with 126, are in Fix round 2:

  • tests/test_bom_tool_io.py tests/test_bom_rewrites.py tests/test_bom_reads.py tests/test_pin_rewrite_layout.py tests/test_repo_hygiene.py tests/test_path_guard_hygiene.py tests/test_no_auto_maintenance.py tests/test_agents_md_codes.py tests/test_cli_reference.py: 550 passed, 2 skipped in 87.26s.
  • tests/test_update_shape.py tests/test_bump_leg.py tests/test_update_shape_apply_lines_and_headers.py tests/test_update_shape_header_comments.py tests/test_bump_leg_dry_run_truth.py (the helpers the new file imports, and the files the issue names): 264 passed, 1 skipped in 200.18s.
  • tests/test_shape_doctor.py is not run: no shape-doctor.py or helper changes.

Merges

Re-listed live on 2026-10-23 at about 07:52Z and again at 08:21Z (the same eleven PRs at the same heads), and run at d65340e5b: git merge-tree --write-tree of this head is clean (exit 0) with origin/main (961640c6, frozen until the v1.2.0 tag) and with each of the eleven open PRs that touch update-shape.py, scripts/bump-leg.py, scripts/shape_materialize.py or scripts/repo_shape.py:

#1178 no longer touches these files. No open PR touches this file or tests/test_update_shape.py, tests/test_bump_leg.py, tests/test_bom_rewrites.py, tests/test_pin_rewrite_layout.py or tests/conftest.py, which it imports. The rows were not run on a merged tree: a clean merge is a clean merge of text only.

Fix round

CI's full suite on the first head (aa0275be, tests.yml run 39861510476) gave 47 setup errors, all in tests/test_bump_leg.py. tests-git-bash, package and SonarCloud passed.

Fix round 2

RV1188's review of 024084b9 (issuecomment-6360127603): READY, one SHOULD and three NITs. One new commit, tests/test_bom_tool_io.py only; the three tool files are byte-identical to HEAD (cmp against saved copies, exit 0).

  • SHOULD-1, SonarCloud python:S3415 ("Unify assertion argument order in this file"). The one == assert with a tuple on its left, assert (pin.read_bytes(), manifest.read_bytes()) == before, is now now = pin.read_bytes(), manifest.read_bytes() and assert now == before, the shape tests/test_naming_policy.py: bind the compared tuple to a name before asserting it, so Sonar's assertion-order rule stops misreading the literal-looking display as the expected side (#130) #131 (d682127d6) fixed. The name is now, not after, which is a function in this file. A scan of every assert in the file by syntax tree found no other == with the expected value on the left: the in asserts keep the text looked for on the left, as in reads. The local analyzer does not reproduce the rule, so the result is read on SonarCloud once CI has run on this head.
  • NIT-1. A space or a tab in FRONT of a mark is now a row for each of the three files (LEAD_PLACES: no mark, behind a mark, in front of one). Each tool refuses it unchanged by its own code (update-pin-unrecognised, update-manifest-no-shape, bump-leg-pin-unrecognised), as the reader does. Six rows more: 126 in all. The module docstring, the row's docstring and the third bullet above say what the rows hold.
  • NIT-2. The Merges list above is re-listed live, with scripts/repo_shape.py added to the files watched.
  • NIT-3. The two end-to-end refusal rows use FINDERS["shape-pin-commit"].refused and FINDERS["leg-pin-commit"].refused in place of the retyped words.
  • Combined runs, tests/test_bom_tool_io.py, tests/test_bump_leg.py and tests/test_update_shape.py in ONE pytest, stub gh, [email protected]: 270 passed, 1 skipped in 129.58s in CI's order and 270 passed, 1 skipped in 137.65s reversed. With the three other files the issue names (tests/test_bump_leg_dry_run_truth.py, tests/test_update_shape_apply_lines_and_headers.py, tests/test_update_shape_header_comments.py), six files in ONE pytest: 390 passed, 1 skipped in 218.42s and 390 passed, 1 skipped in 195.71s reversed.
  • Gates, one pytest at a time: the new file with tests/test_bom_rewrites.py, tests/test_bom_reads.py and tests/test_pin_rewrite_layout.py: 278 passed in 21.85s. The hygiene files, each alone: tests/test_repo_hygiene.py 101 passed, tests/test_path_guard_hygiene.py 49 passed, tests/test_no_auto_maintenance.py 58 passed and 2 skipped, tests/test_agents_md_codes.py 47 passed, tests/test_cli_reference.py 23 passed.
  • Mutants, all 18 of mutants.py re-run at this head, each to its end, and four more for the new rows (M19 to M22): 22 of 22 new rows: KILLED, 22 of 22 cmp exit 0, runner exit 0. M4 and M5 fail two and one rows more than before. M21 and M22 cut a space or a tab only where a mark follows it, so only the new rows in front of a mark kill them; the six existing files all pass under both.

Left out of scope

docs/release-notes/v1.2.0.md (it records v1.2.0's state, known limits included, and is not edited). No milestone.

Closes #1176

Lane: openreposhape-3 (openRepoShape-3)

🤖 Generated with Claude Code

…own read and write and that only U+FEFF is cut, so a `utf-8-sig` read that drops the mark and a cut that also takes spaces no longer survive (#1176)

#1050's rows (tests/test_bom_rewrites.py) hold what the three line
rewriters return. They do not hold the tools' own read and write, nor
that the cut in front of line 1 takes U+FEFF and nothing else, so
rv1050's five mutants (`utf-8-sig` at `_repin`'s two reads and at
`_leg_pin_text`'s read, and an `lstrip` that also cuts spaces and line
feeds in `_marks_off` and in `rewrite_pin`) each passed the whole file
set that reads a pin.

The new file runs update-shape.py's `_repin` and bump-leg.py's
`_leg_pin_text`, `rewrite_pin` and `write_lf` over a file that starts
with 0, 1 or 2 marks, and each tool end to end (`update-shape.py apply`
against a local `--upstream`, and `bump-leg.py`). It asserts that the
marks are written back exactly and that every byte after them is the
rewrite, that another zero-width or format character as the second
character stays (refused in front of the key, written back in front of
a key of its own), that a space, a tab or a whole file indented two
spaces is refused as it was before #1050, and that a mark that is the
second character of a comment is text. No tool code changes: no row
showed a fault.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@sourcery-ai

sourcery-ai Bot commented Oct 22, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds 120 regression tests covering the complete BOM lifecycle in update-shape.py and bump-leg.py, including byte-preserving reads and writes, narrowly scoped U+FEFF stripping, refusal behavior, and end-to-end command validation; no tool implementation changes are included.

File-Level Changes

Change Details Files
Added comprehensive byte-order-mark I/O coverage for both pin-manipulation tools.
  • Tests preservation of zero, one, and two UTF-8 BOM byte sequences through each tool’s actual read and write path.
  • Covers update-shape.py repinning of the shape pin and manifest, plus bump-leg.py pin rewriting and writing.
  • Verifies end-to-end CLI behavior preserves BOMs and leaves project validation green.
tests/test_bom_tool_io.py
Added regression coverage defining the exact scope and position of BOM removal.
  • Confirms only leading U+FEFF bytes on the first line are removed before key matching.
  • Ensures spaces, tabs, indentation, other Unicode format characters, and later BOMs are preserved or rejected without modifying files.
  • Checks refusals retain original bytes and expected tool-specific error codes.
tests/test_bom_tool_io.py
Strengthened mutation-detection coverage for BOM reads, writes, and stripping behavior without changing production code.
  • Exercises mutants involving utf-8-sig, widened or misplaced stripping, incomplete mark removal, and unconditional BOM insertion.
  • Uses byte-level assertions to distinguish marks from typed U+FEFF text and verify rewritten content exactly.
tests/test_bom_tool_io.py

Assessment against linked issues

Issue Objective Addressed Explanation
#1176 Test each tool’s real read-and-write path to ensure shape pins, manifests, and leg pins retain exactly the one or two UTF-8 BOMs they were read with. ✅
#1176 Add regression coverage that only U+FEFF is removed at the start of line 1, while spaces, tabs, other format characters, and marks elsewhere remain intact or cause the same refusal as before. ✅

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

… the spec leg on a branch of their own, so the full suite no longer pushes `bump-leg-advance` twice and tests/test_bump_leg.py's 47 setup errors are gone (#1176)

CI's full suite on #1188 (tests.yml run 39861510476) gave 47 setup
errors in tests/test_bump_leg.py. This file imported test_bump_leg.py's
module-scoped fixture `advanced`, and a module-scoped fixture runs once
for every module that names it. Both runs push HEAD to the branch
`bump-leg-advance` of the session's one shared remote, so the second
push was refused as non-fast-forward: this file sorts first, and
test_bump_leg.py's own `advanced` was the one refused. The gates run one
file at a time and could not see it.

The file now has its own module-scoped `advanced`, which pushes to
`bom-tool-io-advance`, as the other modules that advance the spec leg do
(test_bump_leg_unreadable.py, test_bump_leg_unopenable.py and others).
Nothing else the file imports writes shared state: `upstream_and_project`
builds in its own tmp paths and `tools` only loads two modules. All 120
rows are kept and the tools are untouched.

tests/test_bom_tool_io.py, tests/test_bump_leg.py and
tests/test_update_shape.py in ONE pytest: 218 passed, 47 errors at
aa0275b, 264 passed, 1 skipped with this change.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@brettheap

Copy link
Copy Markdown
Contributor Author

(lane openRepoShape-3, 2026-10-23T07:48:07Z) Independent review (RV1188, opus, ruling 8) of #1188 at 024084b98ed8a77ae7ec6fe5513b3032f86dd461: READY. One SHOULD and three NITs; none blocks landing after the v1.2.0 tag.

SHOULD-1, tests/test_bom_tool_io.py:446.

NIT-1, tests/test_bom_tool_io.py:38 and :254-256, and the body's third bullet: "before a mark or after one".

  • The rows hold "no mark" and "after one mark"; no row puts the space or tab in front of a mark.
  • Measured: that case is refused unchanged today by all three tools (update-pin-unrecognised, update-manifest-no-shape, bump-leg-pin-unrecognised), and the reader refuses it too.
  • Add a before-the-mark row, or reword.

NIT-2, the body's Merges.

NIT-3, :445 and :462 retype "has 0 commit line(s)". FINDERS["shape-pin-commit"].refused and FINDERS["leg-pin-commit"].refused hold the same words. Optional.

Observation, nothing for this PR:

  • update-shape.py's _is_block_header (:1695-1698) uses str.strip(), so a no-break space (U+00A0) or an ideographic space (U+3000) in front of shape: is taken as the header. A direct call to _repin wrote such a manifest, while parse_yaml reads that line as another key.
  • This is already on main, is not the byte-order-mark cut, and no row here pins it. It was not run through apply end to end.
  • A follow-up issue is the lane's call.

Checked:

  • Tools: byte-identical at main and the head; only the test file changes.
  • Own probe: the three files with 0 to 3 marks are written back with exactly those marks. A mark followed by a space, tab, zero-width space, word joiner, right-to-left mark or U+FFFE is refused unchanged. A mark inside a comment is written back.
  • The fixture fix: at aa0275be a narrow selection gives 2 passed and 3 errors (rejected HEAD -> bump-leg-advance); at the head it gives 5 passed. bom-tool-io-advance is unique among the 14 ADVANCE_BRANCH names.
  • Five modules together (bom_rewrites, bom_tool_io, bump_leg, pin_rewrite_layout, update_shape): 391 passed, 1 skipped, in CI order and reversed.
  • The new file with the three hygiene files: 328 passed, 2 skipped.
  • On a merge of this PR with all eleven open PRs touching the tools or repo_shape.py: the BOM files give 157 passed.
  • Own mutants, each restored with cmp 0, all KILLED, and all surviving the three existing files:
    • a utf-8-sig read in _repin (20 failed);
    • an lstrip that cuts spaces (8);
    • the cut widened to every Cf (24);
    • a second-character mark cut (6);
    • the shape pin written with a mark (22);
    • a new one, a utf-8-sig write at _apply_rewrite (2, the end-to-end bump-leg rows).
  • CI: tests, tests-git-bash, package and SonarCloud all SUCCESS. The Sonar gate is OK, with 0.0% duplication.
  • Body and commits: as required.
  • Not re-made: M2, M3, M5, M7-M9, M11-M15, M17 and M18. The writer's log shows all 18 killed.

Lane: openreposhape-3 (openRepoShape-3)

…used in each tool's words as one behind a mark is, the compared pair of files is named before it is asserted, and the retyped refusal words are the finders' own (#1176)

RV1188's review of #1188, from the head 024084b:

SHOULD-1 (SonarCloud python:S3415, "Unify assertion argument order in this
file"): the one assert with a bracketed tuple on the left was
`assert (pin.read_bytes(), manifest.read_bytes()) == before`, the shape
#131 (d682127) fixed. The pair is now bound to `now` and compared as
`assert now == before`. Not `after`, which is a function in this file.
Every other `==` assert has the value read on the left; the `in` asserts
keep the text looked for on the left, as `in` reads.

NIT-1: the module docstring, the row's docstring and the PR body said a
space or a tab in front of the key was held "before a mark or after one",
and the rows held no mark and one mark in front of it. A space or a tab in
FRONT of a mark is now a row for each of the three files: refused
unchanged by each tool's own code (update-pin-unrecognised,
update-manifest-no-shape, bump-leg-pin-unrecognised), as the reader refuses
it. Six rows more (126 in all), and the places are named in LEAD_PLACES.

NIT-3: the two end-to-end refusal rows retyped "has 0 `commit` line(s)";
they now use FINDERS["shape-pin-commit"].refused and
FINDERS["leg-pin-commit"].refused, as the in-process rows do.

The tools are untouched.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@sonarqubecloud

Copy link
Copy Markdown

@brettheap

Copy link
Copy Markdown
Contributor Author

(lane openRepoShape-3, 2026-10-23T08:30:48Z) Delta review (RV1188, opus) of #1188's second fix round: head d65340e5, on 024084b9.

Verdict: READY. All four findings from the review of 024084b9 are fixed, and nothing new is wrong. Land only once CI's tests on d65340e5 is green; it was still running at 08:29:55Z (started 08:20:58Z).

Lane: openreposhape-3 (openRepoShape-3)

@sourcery-ai

sourcery-ai Bot commented Oct 23, 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 10 hours and 26 minutes by commenting @sourcery-ai review. Upgrade to get a review now.

@brettheap
brettheap merged commit 423e667 into main Oct 23, 2026
5 checks passed
@brettheap
brettheap deleted the l3-1176-bom-rows-hold-the-tools branch October 23, 2026 13:21
brettheap pushed a commit that referenced this pull request Nov 10, 2026
…t's bootstrap.py under a Latin-1 locale it builds, over `tb\udcffx`, at each place step (a) asks whether HEAD is on the tracking branch (#1283)

30 rows. Each runs `bootstrap.py --skip-validators` in a child under the
locale it names, so a suite under UTF-8, as CI's is, measures Latin-1. The
locale is built by this module's own module-scoped `latin1` fixture with
`localedef -c`, not imported from `test_adopt_one_byte_locale.py` (#1188);
where none can be built the Latin-1 rows skip with `localedef`'s words.

- the first run and every later run, over `tb\udcffx` under Latin-1, UTF-8
  and ASCII, over `feature/x` and U+00FF itself under Latin-1, and over
  `caf\udcc3\udca9` under all three;
- a failing post-checkout hook where nothing moved, a branch behind the pin
  (HEAD on it, and detached at the new pin), a branch past the pin moved
  back, a branch with a commit of its own, and HEAD on the branch with no
  commit yet, each under Latin-1 and UTF-8.

Lane: openreposhape-1 (openRepoShape-1)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
brettheap added a commit that referenced this pull request Nov 10, 2026
…blems against its source, in the order a person mends them (another repository, a refused name, a moved source, an unanswered entry), so `check`'s first finding is `execute`'s refusal for each pair (#1113) (#1210)

**Stacked on #1125.** This PR's base is `fix/1020-bad-id-first-problem` (#1125's branch, head `9549006f`). It lands after #1125 and stays a draft until then. #1125 makes `check`'s first finding `execute`'s first refusal for a bad `id:` or `org:`. This PR extends that rule to the four pairs #1113 measured, which have neither.

**Fix round.** The first gate failed six rows of `tests/test_adopt_relative_submodule_url.py` that pinned `check`'s old order on a plan hand-edited into another organisation, the relative url before `plan-not-the-source`, a plan `execute` already refused `plan-not-the-source` first on #1125's head; they now expect `plan-not-the-source` first, and a new row asserts that both commands name it first.

## The rule and the order

One generator, `_against_its_source`, asks a plan's four problems against its source in one order, and both commands read it. `execute` refuses its first problem. `check` lists each one, in that order and in its own words, before the split branch and the entries.

The order is the one a person mends them in:
1. a plan for another repository (`plan-not-the-source`);
2. a name the naming policy refuses (`naming-unclassified`, or `naming-role-mismatch`);
3. a source that has moved on since `plan` (`plan-stale`);
4. an unanswered entry (`plan-unresolved`).

Why this order:
- **An unanswered entry last.** Each of the first three is mended by running `plan` again, as its remediation says, and a fresh plan takes back every answer given before. An answer given first would be lost.
- **Another repository first.** Nothing in such a plan is this source's own: it is mended by `plan` under the source's own name, or from the source it is about. And `execute` must ask the naming policy nothing about the plan's names, and no remote anything, before it refuses it (#499). `_against_its_source` is a generator, so `execute` asks nothing after the first problem, and that still holds.
- **A refused name before a moved source.** The name is mended by `plan` given another `--project`, or after the source is renamed on GitHub. That run reads the source as it is now, so it mends the moved source too. `plan` run again as it was, for the moved source, would leave the name to mend.
- **The least change to each command.** The order keeps `execute`'s order for the plan's names (#499, #716) and `check`'s order of a moved source before its entries. Only the pairs that disagreed change.

## Before and after

Measured on #1125's head `9549006f` and on this head, with a stub `gh` (exit 97), `GH_TOKEN=bogus`, an empty `GH_CONFIG_DIR`, `GIT_SSH_COMMAND=false`, a proxy that goes nowhere, an empty global git config and `--local-remote-dir`. No run made a leg. `check` exits 1 and `execute` exits 2 in every row.

| The plan holds | `check` before | `execute` before | both, here |
|---|---|---|---|
| a moved source and an unanswered entry (#1113) | `plan-stale` | `plan-unresolved` | `plan-stale` |
| another repository and an unanswered entry (#1113) | `plan-unresolved` | `plan-not-the-source` | `plan-not-the-source` |
| another repository and a moved source (#1113) | `plan-stale` | `plan-not-the-source` | `plan-not-the-source` |
| a refused name and an unanswered entry (#1113) | `plan-unresolved` | `naming-unclassified` | `naming-unclassified` |
| a refused name and a moved source (not in #1113's table) | `plan-stale` | `naming-unclassified` | `naming-unclassified` |
| all four | `plan-stale` | `plan-not-the-source` | `plan-not-the-source` |
| another repository and a refused name | `plan-not-the-source` | `plan-not-the-source` | `plan-not-the-source` (unchanged) |

The fifth row is not in #1113's table, but the two commands disagreed there too, and the same rule decides it.

The same probe, comparing each command's output before and after, with paths and hashes masked:
- A plan with one of the four problems: both commands print the same stderr and stdout before and after.
- Both commands' stdout is the same before and after in every row.
- `check`'s stderr in each pair row holds the same lines as before, reordered: the same findings and the same remediation lines.
- `execute`'s stderr changes in one row only, a moved source beside an unanswered entry: `REFUSED plan-stale`, in its own words, where it said `REFUSED plan-unresolved`.

No refusal's code or wording changes, and no code is added. Re-run on this head after the fix round, the probe gives the same: the 24 plans (these 11, and the 13 of the next section) each get one first problem from both commands, no run makes a leg, and the comparison with #1125's head is the one above, line for line.

## #1113's suspected case: a `--work-dir` that cannot be written

Measured on #1125's head and on this head, the two commands agree in every row, and nothing here changes it:
- **A bad `id:` or `org:` beside a `--work-dir` this user cannot write in** (`chmod 500`): `plan-bad-id` or `unsafe-value` to both. #1125's review round 1 (RV1125's SHOULD-1) made both commands ask the two before `_work_root`, which settled this case.
- **Each of the 11 plans above beside the same `--work-dir`:** `adopt-work-dir-unwritable` first to both.

## What changed, in `adopt-project.py`

- **`_against_its_source` and `_Unmended` (new).** `_against_its_source` is the rule. It asks:
  - `_refuse_a_plan_for_another_repository`;
  - `_check_names`, given the source only where the plan names no other repository, as `check` gave it (#716);
  - `_refuse_an_unrunnable_plan`.

  It yields each problem as an `_Unmended`: the `Refusal` `execute` refuses it with, and `check`'s FINDING lines and remediation for it, in `check`'s words as they were. `check` lists an unanswered entry with the entries, each by its path (`_leg_findings`), after the rule's problems.
- **`cmd_execute`.** It refuses the first problem, `next(_against_its_source(...))`. Before, it called `_refuse_a_plan_for_another_repository`, `_check_names` and `_refuse_an_unrunnable_plan` in turn.
- **`cmd_check`.** It lists the rule's findings right after the Triad advisory, where it listed a moved source. Another repository and the names are no longer listed after the entries. Three things are still asked where they were, and only where no name was refused:
  - the names' classification lines on stdout;
  - the findings about what the disk or GitHub will not hold (#863);
  - the leg question (#798).

  The remediation lines it prints after its findings follow the findings' order, so the rule's come first.
- **`_refuse_an_unrunnable_plan`.** It asks a moved source before an unanswered entry. Its docstring says why.
- **`_refuse_a_plan_for_another_repository`.** Unchanged. The rule calls it.

## Tests

`tests/test_adopt_plan_against_its_source.py` (new, ASCII only), 11 rows. Each runs `check` and then `execute --yes` on one hand-edited plan, both with the same `--local-remote-dir`, and asserts that no leg is made.
- **7 pair rows** (the six pairs and all four). Each asserts:
  - `check` exits 1 and `execute` exits 2;
  - both name first the same code, the rule's first;
  - `check` lists every problem the plan holds, in the rule's order.
- **4 controls**, one per code: the plan holds that problem alone, and both commands name it.
- **Against #1125's head `9549006f`:**
  - the 6 pair rows that disagreed fail, each because the two commands named different codes, for example `('plan-stale', 'plan-unresolved') != ('plan-stale', 'plan-stale')`;
  - the `another-and-name` guard row and the 4 controls pass.
- **Here:** 11 passed.

`tests/test_adopt_relative_submodule_url.py`, 6 rows changed and 1 new (the fix round):
- **The 6 rows** are `test_check_keeps_a_relative_url_its_github_leg_resolves_alike` for `[https]`, `[scp]`, `[scp-other-case]`, `[ssh-port]` and `[ssh-github-443]`, and `test_a_credential_in_the_source_remote_is_never_printed`.
  - Each hand-edits the plan's `org:` to `otherorg`, so the plan names `otherorg/Thing` and the source is `testorg/Thing`: a plan for another repository.
  - Each expected `check` to list the relative url first and `plan-not-the-source` after it, `check`'s old order. They now expect `plan-not-the-source` first. Their other assertions are unchanged; the credential is still printed nowhere.
- **The new row,** `test_check_names_another_repository_first_as_execute_refuses_it`, runs one such plan. It asserts that `check`, with and without `--local-remote-dir`, lists `plan-not-the-source` and then the url, that `execute` refuses `plan-not-the-source`, and that no leg is made.
- **Measured on #1125's head** for the six source remotes: `execute` already refused each such plan `plan-not-the-source`, and its output is the same on both heads. Only `check`'s order changed. No spelling of the source's `origin` reads as another repository: with `org:` left as the source's, `check` passes on both heads, as the rows assert.

Both files together, 46 rows:
- **Against #1125's head:** 13 failed, 33 passed. The 13 are the 6 pair rows above and the 7 relative-url rows, each on the order: `plan-not-the-source` where the url was expected first, or the url first in the new row.
- **Here:** 46 passed.

## Mutants

Each was applied to `adopt-project.py`, run against both files (46 rows), and restored, with its sha256 checked (`4c8c1c9e`, the same after each one). Unmutated, the 46 pass. M1-M6 are the first round's; M7 and M8 are the fix round's.

| Mutant | Killed by |
|---|---|
| M1, `execute`: `_refuse_an_unrunnable_plan` asks an unanswered entry before a moved source (pair 1) | 2: `moved-and-unanswered`, `all-four` |
| M2, `check`: lists another repository after the entries (pair 2) | 11: `another-and-unanswered`, `another-and-moved`, `another-and-name`, `all-four`, and the 7 relative-url rows |
| M3, `check`: lists a moved source before another repository (pair 3) | 3: `another-and-moved`, `name-and-moved`, `all-four` |
| M4, `check`: lists a refused name after the entries (pair 4) | 3: `name-and-unanswered`, `name-and-moved`, `all-four` |
| M5, `check`: lists a moved source before a refused name (pair 5) | 2: `name-and-moved`, `all-four` |
| M6, the rule: asks a refused name before another repository (both commands) | 2: `another-and-name`, `all-four` |
| M7, `execute`: asks `_refuse_what_check_finds` before the rule | 8: the pair rows but `another-and-name`, the `plan-stale` control, and the new relative-url row |
| M8, `check`: lists all the rule's problems after the entries | 14: the pair rows but `another-and-name`, the `plan-stale` control, and the 7 relative-url rows |

## Gate

Run on the scratch merge `743ebe176`: `origin/main` `961640c68` plus this head `90eca4144` (tree `d71d6f00a`, never pushed). It ran in the landing gate's own environment (a stub `gh`, `GH_TOKEN=bogus`, an empty global git config, `EMAIL` set, the `LANES_*` and `GIT_SSH_COMMAND` variables unset), one shard at a time, each started with at least 19G free. The ids were collected from that tree, 4405 + 448 = 4853, and each is in exactly one shard. The file list is the 46 test files W1113's gate named and four more, added in the fix round (50 in all): `test_adopt_c_locale_bytes.py` and `test_adopt_submodule_url_answers.py` (they import helpers and the module-scoped `adopter` fixture from the changed test file, so they sit in its shard, r03), `test_reader_refusals_named.py` (it hand-edits a plan's `org:` and checks `check`'s exact findings) and `test_github_name_limits.py`. Every shard exited 0.

| Shard | Result |
|---|---|
| r01 | 600 passed |
| r02 | 613 passed |
| r03 | 464 passed, 1 skipped (`test_adopt_plan.py::test_plan_on_medxehr_matches_the_rulings`) |
| r04 | 547 passed |
| r05 | 599 passed, 19 skipped (all in `test_family_init_values.py`) |
| r06 | 542 passed |
| r07 | 489 passed |
| r08 | 531 passed |
| d01 to d07 | 56 passed each (`test_shape_doctor.py`) |
| d08 | 53 passed, 3 skipped (`test_shape_doctor.py`) |

- **r01 to r08:** 4385 passed, 20 skipped (4405 ids).
- **d01 to d08:** 445 passed, 3 skipped (448 ids).
- **Total:** 4830 passed, 23 skipped, none failed, none errored.

Main has moved since this gate: `origin/main` is `ac5f28d2a` (#1188, #1130 and #1098 landed). They change `scaffold-project.py`, `scripts/family.py` and four test files. None of them is a file this PR changes, a module `adopt-project.py` imports, or one of the 50 gated test files, so the gate was not run again on that tip. The merge-trees below were.

## Merge-trees

`git merge-tree --write-tree`, run again on 2026-10-23 at 15:31Z against the current `origin/main`, every one clean:
- **`origin/main` `ac5f28d2a`:** clean, tree `1a65ab9bd`.
- **#1125 `9549006fe`:** clean. This branch is on it.
- **#1177 `5208e874e`** (`fix/1152-plan-and-remote-paths-spelled`, which edits a line of `_refuse_a_plan_for_another_repository`): clean, with this head and three-way on the scratch merge.
- **Every open PR that touches `adopt-project.py` or either test file, 25 of them, #1125 and #1177 among them:** clean, both with this head and three-way on the scratch merge of `ac5f28d2a` and this head, `98afb128a` (`git merge-tree --write-tree <that merge> <its head>`). Since the first run, #1207 is new, and #1119, #1189 and #1190 have moved; all four are clean. No open PR touches either test file. The list is in a code block, so that it does not mention each PR:

```
PR     head       with this head              on the scratch merge
#1105  b28f40d  clean (tree 32fce74c6)   clean (tree 490f555f9)
#1106  504a1dd  clean (tree 3abfa1b6a)   clean (tree db57682e9)
#1118  2307036  clean (tree 79a3888bf)   clean (tree 629f167ca)
#1119  195d993  clean (tree a2926127e)   clean (tree 6aec4c863)
#1120  c55e55e  clean (tree 6171a52f8)   clean (tree 0cb310664)
#1121  1c51737  clean (tree 3acb80467)   clean (tree 2771fbfd0)
#1122  c01c4d7  clean (tree af9a4c414)   clean (tree ef00f52f7)
#1123  5c3908f  clean (tree eb7cb34b3)   clean (tree 4c311748b)
#1125  9549006  clean (tree 239df6d)   clean (tree 1a65ab9bd)
#1141  7a2711d  clean (tree e1c8f7169)   clean (tree 3afeda790)
#1143  7af5fab  clean (tree 35cd165de)   clean (tree aae00cfc7)
#1153  ff33ba1  clean (tree 57da668e8)   clean (tree f91ce3d8d)
#1154  8a78283  clean (tree 28699ba0c)   clean (tree 3e6b1ae98)
#1169  1e958ca  clean (tree e3ef802be)   clean (tree f4566b2c4)
#1170  24ee133  clean (tree 94b9291c8)   clean (tree 848bb0ed0)
#1171  8162b87  clean (tree 65ca8196d)   clean (tree f15571ef3)
#1177  5208e87  clean (tree 08e3d6a62)   clean (tree 111f3c238)
#1178  c4beba1  clean (tree 646f02266)   clean (tree eae3b5996)
#1180  b316f41  clean (tree 25b3d4b6f)   clean (tree 85a559171)
#1186  07486a4  clean (tree d0fe77836)   clean (tree 849f0ef41)
#1189  a131fc2  clean (tree 5b1ab0620)   clean (tree 9851d22b7)
#1190  91a937e  clean (tree aa83fae05)   clean (tree 18101f50b)
#1194  900f77a  clean (tree 9d74efa35)   clean (tree 46317beae)
#1198  d38e4e3  clean (tree 87ca21b8c)   clean (tree 7fc45a875)
#1207  1c7ca5c  clean (tree 1dbab659d)   clean (tree 1e44c98f0)
```

## Left for a follow-up (outside #1113)

- **An unanswered entry beside an uncovered path still gives two first problems,** filed as #1197. `check` lists `plan-uncovered` first and `execute` refuses `plan-unresolved` first. Measured the same on #1125's head and on this head. `execute` refuses an unanswered entry before `_refuse_what_check_finds`, while `check` lists it in `_leg_findings`, after the paths and the coverage. Other entry findings ahead of it in `_entry_findings` are likely the same (`plan-unsafe-path` among them), and so is the taken split branch, but those were not measured.

Closes #1113

Lane: openreposhape-4 (openRepoShape-4)
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