Skip to content

update-shape.py apply --branch and family.py bump take a repeatable --trailer, and the printed apply already carries the lane, so the commit they write ends with its Lane: line instead of being amended afterwards (#111) - #112

Merged
brettheap merged 4 commits into
mainfrom
feat/shape-tool-commit-trailers
Sep 11, 2026

Conversation

@brettheap

@brettheap brettheap commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Lane: openreposhape-2 (openRepoShape-2)
Claim: #111 (comment)

Closes #111.

What was wrong

update-shape.py apply --branch <name> and scripts/family.py bump each compose and write their own commit — Re-sync the shape copies to <repo> @ <sha12>, Bump <Member> to <sha12> in the <Family> family — and neither had any way to put a line on one. The lane-collision protocol (Rule 5) wants Lane: <name> on every artifact a lane produces, the commit included, and this repository's convention adds Co-Authored-By: beside it. Four InkRouter re-pins landed on 2026-09-11 (IRRS@01cb387, IRSS@70f89b5, InkRouter@4653703, InkRouter@77a8189) carrying neither, because both tools were run exactly as their own NEXT lines printed them and nothing in either script wrote a trailer. The lane-line check reads the pull request body, not the commit, so nothing refused the landing; the gap was only in the git history, which is exactly where the protocol says the lane line must also live.

What landed

update-shape.py apply — --trailer "<Key>: <value>", repeatable. Each value is appended to the commit the tool writes, in the order given. Validated at the argparse boundary (type=trailer_line), so a line that is not a <token>: <value> trailer is refused with the usage beside it, exit 2, before the root is opened or a byte is copied. It needs --branch: refused under the existing update-branch-required id, which now names whichever of --push, --pr and --trailer was actually passed (--push and --trailer have nothing to act on without --branch) rather than listing flags nobody typed. A trailer is a line on a commit, and without --branch there is no commit to put one on.

scripts/family.py bump — the same repeatable --trailer, appended to the one commit it writes (the gitlink and members[].pin still move together, still with explicit pathspecs). add and remove share _commit_one and are unchanged, because the issue names bump.

The git-version fallback. git commit --trailer (repeatable) is used where the host git is 2.32 or newer, probed once per run from git --version and parsed conservatively (^git version (\d+)\.(\d+), anchored; 2.45.1.windows.1 and 2.39.3 (Apple Git-146) both read, anything unparseable reads as "no"). Otherwise the lines are appended to the message text after one blank line. The commit that comes out is the same one either way — asserted, not assumed: test_both_paths_write_the_same_commit_message writes both into one real repository and compares. Passed no trailer, the message and the git commit argv are the ones these tools always built.

The printed NEXT lines carry the lane, and only the lane.

  • update-shape.py check — its NEXT … apply … --branch … line gains --trailer "Lane: $LANES_LANE".
  • shape-doctor.py — the shape currency row's two apply spellings (the copied-file branch and the behind-pin-only branch) gain the same argument, quoted through the file's existing platform-aware quote_arg(value, platform) via a lane_trailer_command(platform) that passes platform on rather than merely branching on it, the rule copy_command and scaffold_command already follow. No other row grows one (test_no_other_row_grows_a_trailer).
  • family.py bump prints no next-command of its own, and shape-doctor.py prints no family.py bump line, so there was nothing to add there.

Nothing is added when LANES_LANE is unset, empty or whitespace, so today's output is byte-identical for everybody who is not in a lane. No Co-Authored-By: is ever derived — it names a person or a model no environment variable knows, and it stays the caller's to pass. A lane name carrying a character that would not survive the paste (", ', a backtick, $, \, a newline) is offered on no printed line; --trailer typed by hand still takes anything the grammar accepts.

Where the shared code lives. TRAILER_RE, trailer_line, git_takes_trailer_option, commit_trailers, LANE_ENV, lane_trailer and lane_trailer_argument are in scripts/shape_materialize.py — imported by both writing tools already, and in no copy list. scripts/repo_shape.py was the wrong home for exactly the reason shape-doctor.py gives about its own quoter: it is a shape copy that contracts/shape-pin.yaml digests, so one function added there would put an upstream-changed scripts/repo_shape.py row in front of every project in the estate for a helper no project's copy would ever call. shape-doctor.py reaches it through a third guarded import beside its repo_shape and path_classify ones.

Documentation. docs/cli.md regenerated by scripts/render-cli-reference.py (both new flags). AGENTS.md gained one numbered point under "Updating a project's shape" and one clause in the family section — because a flag documented in docs/cli.md is not permission to pass it, and these are the flags the protocol now requires an assistant to pass; the line cap moves 423 → 433 with the reason recorded in the test's own docstring, the way every previous move was.

How it was proven

Live, on a real root, read-only (~/projects/InkRouter/IRRS, untouched: still 01cb387, clean tree).

update-shape.py check, pointed deliberately at an older commit so a NEXT line prints:

NEXT  python3 update-shape.py apply --root /home/brett/projects/InkRouter/IRRS --upstream /home/brett/projects/openRepoShape--111-trailers --at 32450eb5c5d18fbb0747dc5ad420cf67742cfa99 --yes --branch shape/update-32450eb5c5d1 --trailer "Lane: openreposhape-2 (openRepoShape-2)"

and the same run with LANES_LANE unset ends --branch shape/update-32450eb5c5d1, with no --trailer anywhere.

shape-doctor.py --root ~/projects/InkRouter/IRRS (this branch's HEAD is ahead of the pin, so the row is a finding rather than the COMPLIANT the issue's own command would have printed):

  FINDING  shape currency   no copied file differs, but the pin names an older commit, so `apply` would move the pin alone; 10 unchanged / 0 upstream-changed / 0 locally-modified / 0 both / 0 upstream-added (pinned cd57c4bbd84e, this standard afe584b7bacb)
           NEXT             python3 /home/brett/projects/openRepoShape--111-trailers/update-shape.py check --root /home/brett/projects/InkRouter/IRRS --upstream /home/brett/projects/openRepoShape--111-trailers   # then apply --at afe584b7bacbaeaf2748df66ec42e82bce497c12 --yes --branch shape/update-afe584b7bacb --trailer 'Lane: openreposhape-2 (openRepoShape-2)'

The suite. python3 -m pytest -q → 1 failed, 1052 passed, 1 skipped in 438.90s. 68 tests are new (986 collected on origin/main, 1054 here). The one failure is tests/test_naming_policy.py::test_cli_reports_an_unread_link_as_a_warning_and_still_classifies, and it is not this branch's: it fails identically on unmodified cd57c4b from a worktree in the same parent directory (git worktree add --detach ~/projects/openRepoShape--111-base origin/main → 1 failed for that test alone) and passes from a worktree under /tmp. The cause is repo_shape.resolve_link_source rule 3, "a checkout sitting BESIDE this project": ~/projects/openXdox is a real checkout on this machine, so the referent link verifies and the declared-unverified warning the test wants is never printed. Nothing in this branch touches the naming validator, its policy or that resolution.

python3 scripts/render-cli-reference.py then python3 -m pytest -q tests/test_cli_reference.py → 13 passed, so the committed docs/cli.md is the generated one.

New tests, by name.

tests/test_commit_trailers.py (new file, 46 tests — the shared rules):

  • test_the_grammar_accepts_a_trailer_somebody_would_actually_write (6 cases)
  • test_the_grammar_refuses_a_line_that_is_not_a_trailer (10 cases, including Lane: two\nlines, which would forge a trailer line nobody passed)
  • test_the_version_probe_reads_the_commit_option_off_the_version_line (11 cases)
  • test_the_probe_asked_for_a_version_touches_no_cache
  • test_the_option_arrived_in_2_32
  • test_no_trailers_is_the_message_unchanged_and_no_arguments
  • test_the_commit_option_is_used_where_git_has_it
  • test_the_text_fallback_appends_the_lines_after_one_blank_line
  • test_the_fallback_supplies_the_newline_a_message_is_missing
  • test_both_paths_write_the_same_commit_message
  • test_the_lane_comes_from_the_environment_and_is_a_trailer
  • test_an_unset_or_blank_lane_is_no_lane (3 cases)
  • test_a_lane_name_that_could_not_be_pasted_is_not_offered (6 cases)
  • test_the_printed_argument_is_spelled_by_the_callers_own_quoter
  • test_the_lane_line_is_the_only_thing_derived_from_the_environment

tests/test_update_shape.py:

  • test_two_trailers_end_the_commit_message_in_the_order_given
  • test_one_trailer_is_the_whole_block
  • test_no_trailer_leaves_the_commit_carrying_none
  • test_a_trailer_without_branch_is_refused_like_push_and_pr
  • test_the_refusal_names_every_flag_that_was_passed
  • test_a_malformed_trailer_is_refused_before_a_byte_is_read (4 cases)
  • test_the_next_line_check_prints_carries_the_lane_when_one_is_set
  • test_the_next_line_says_nothing_about_a_lane_when_none_is_set

tests/test_family.py:

  • test_bump_with_two_trailers_ends_the_commit_message_in_the_order_given
  • test_bump_refuses_a_malformed_trailer (3 cases)

tests/test_shape_doctor.py:

  • test_the_apply_a_behind_row_prints_carries_the_lane_when_one_is_set
  • test_the_behind_pin_only_row_carries_it_too
  • test_a_row_says_nothing_about_a_lane_when_none_is_set
  • test_no_other_row_grows_a_trailer
  • test_the_lane_trailer_is_quoted_for_the_platform_asked_for (posix and nt)
  • test_the_lane_trailer_is_nothing_at_all_with_no_lane
  • test_an_awkward_lane_name_is_quoted_and_not_merely_hoped_about

The two end-to-end message tests are written as two runs of the same apply/bump, one with the flag and one without, so the trailer block is the only difference between the messages: the ordering claim and the "a run passing none writes what it always wrote" claim in one assertion, with no pasted copy of today's wording to go stale. Both also assert git log --format='%(trailers:only=true)' — the trailer block as git reads it, which is what a forge reads Co-Authored-By: off.

This commit itself carries both trailer lines.

Test plan

  • python3 -m pytest -q — 1 failed, 1052 passed, 1 skipped; the one failure reproduced on unmodified origin/main from the same parent directory
  • python3 scripts/render-cli-reference.py && python3 -m pytest -q tests/test_cli_reference.py — 13 passed
  • python3 -m pytest -q tests/test_commit_trailers.py — 46 passed
  • python3 -m pytest -q tests/test_update_shape.py — 36 passed
  • python3 -m pytest -q tests/test_shape_doctor.py — 144 passed
  • python3 -m pytest -q tests/test_repo_hygiene.py — 48 passed (the AGENTS.md cap moved with its reason)
  • update-shape.py check on a live root, with LANES_LANE set and unset — trailer present, then byte-identical to before
  • shape-doctor.py --root ~/projects/InkRouter/IRRS with LANES_LANE set — the shape currency row's apply carries the quoted lane trailer; the root is untouched (01cb387, clean)
  • git log -1 --format='%(trailers:only=true)' on this branch's own commit — both lines, in order

🤖 Generated with Claude Code

Summary by Sourcery

Add repeatable commit trailers to shape and family update workflows and propagate safe lane metadata into generated apply commands.

New Features:

  • Add repeatable --trailer options to shape application and family bump commits, preserving trailer order.
  • Include the active lane trailer in generated apply commands when it can be safely pasted.

Bug Fixes:

  • Ensure lane metadata is written directly to generated commits instead of requiring post-commit amendments.
  • Support equivalent trailer commits across Git versions with and without native git commit --trailer support.

Enhancements:

  • Centralize trailer validation, lane handling, Git capability detection, and commit construction in shared materialization helpers.
  • Reject malformed trailers and trailer usage without a branch at argument parsing or command validation boundaries.

Documentation:

  • Update CLI reference, agent guidance, and generated shape/family instructions for commit trailers and lane-aware commands.

Tests:

  • Add comprehensive coverage for trailer validation, Git-version fallback behavior, commit messages, lane command generation, quoting, and unchanged no-trailer behavior.

Chores:

  • Keep non-lane command output unchanged and leave co-author trailers to callers to provide explicitly.

…le `--trailer`, and the printed `apply` already carries the lane, so the commit they write ends with its `Lane:` line instead of being amended afterwards (#111)

Both tools compose their own commit message — "Re-sync the shape copies to
<repo> @ <sha12>", "Bump <Member> to <sha12> in the <Family> family" — so the
`Lane: <name>` line the lane-collision protocol wants on every artifact a lane
produces, and the `Co-Authored-By:` this estate adds beside it, reached those
commits through nothing at all. Four InkRouter re-pins landed on 2026-09-11
carrying neither, each one run exactly as a printed `NEXT` line said.

`--trailer "<Key>: <value>"` is repeatable, kept in the order given, and
validated at the argparse boundary, so a line that is not a trailer is refused
with the usage beside it and before a repository is opened. On `apply` it needs
`--branch`, refused under the same `update-branch-required` id as `--push` and
`--pr` and now naming whichever of the three was passed: a trailer is a line on
a commit, and without `--branch` there is no commit to put one on.

The write is `git commit --trailer` where the host git is 2.32 or newer, probed
once from `git --version` and parsed conservatively, and an append to the
message text where it is not — the same commit either way, which
`tests/test_commit_trailers.py` writes both of and compares. Passed no trailer,
the message and the `git commit` argv are the ones these tools always built.

`update-shape.py check`'s `NEXT` line and the doctor's `shape currency` row now
end with `--trailer "Lane: <$LANES_LANE>"` when the environment names a lane,
quoted through the doctor's own platform-aware `quote_arg` on its rows, so the
line survives being pasted; with no lane set nothing is added and both are
byte-identical to what they printed before. Only the lane is derived — a
co-author names a person or a model no environment variable knows.

What a trailer is, which git takes the option, and which variable names the
lane live in `scripts/shape_materialize.py`, imported by both tools already and
in no copy list; `scripts/repo_shape.py` would have put an `upstream-changed`
row in front of every project in the estate for a helper none of their copies
would call, which is the argument `shape-doctor.py` makes about its quoter.

Lane: openreposhape-2 (openRepoShape-2)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Copilot AI lite review requested due to automatic review settings September 11, 2026 18:18
@brettheap

Copy link
Copy Markdown
Contributor Author

@codex review

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 4 days and 10 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@sourcery-ai

sourcery-ai Bot commented Sep 11, 2026

Copy link
Copy Markdown

Reviewer's Guide

The PR centralizes repeatable commit-trailer handling for shape apply and family bump, including Git-version-compatible commit writing, then propagates only safe lane trailers into generated apply commands while preserving existing no-lane behavior and documenting and testing the complete workflow.

Sequence diagram for lane-aware shape apply commit

sequenceDiagram
    participant User
    participant Check as update-shape.py check
    participant Apply as update-shape.py apply
    participant Materialize as shape_materialize.py
    participant Git

    User->>Check: cmd_check()
    Check->>Materialize: lane_trailer_argument()
    Materialize-->>Check: --trailer Lane: <lane>
    Check-->>User: NEXT apply command
    User->>Apply: apply --branch --trailer
    Apply->>Materialize: commit_trailers(message, trailers)
    Materialize->>Git: git --version
    alt Git >= 2.32
        Materialize-->>Apply: message + git --trailer arguments
    else Older or unparseable Git
        Materialize-->>Apply: message with trailer block
    end
    Apply->>Git: git commit -F - [--trailer] -- paths
Loading

Sequence diagram for lane-aware family bump commit

sequenceDiagram
    participant User
    participant Bump as family.py bump
    participant Materialize as shape_materialize.py
    participant Git

    User->>Bump: bump --trailer Lane: <lane>
    Bump->>Materialize: trailer_line()
    Materialize-->>Bump: validated trailer
    Bump->>Materialize: commit_trailers(message, trailers)
    Materialize-->>Bump: message and commit arguments
    Bump->>Git: git commit -F - [--trailer] -- paths
    Git-->>Bump: one commit containing gitlink and members[].pin
Loading

File-Level Changes

Change Details Files
Add repeatable commit-trailer support to shape and family update commands, with validation and compatibility across Git versions.
  • Validate <Key>: <value> trailer arguments at the argparse boundary and require --branch for shape apply trailers.
  • Centralize trailer grammar, Git capability detection, commit-message fallback, and lane derivation in shared materialization helpers.
  • Pass trailers through the single commits written by shape apply and family bump while preserving explicit pathspec behavior and no-trailer compatibility.
  • Use git commit --trailer on Git 2.32+ and append an equivalent trailer block to the message on older or unparseable Git versions.
scripts/shape_materialize.py
update-shape.py
scripts/family.py
Propagate the current lane into generated apply commands without changing output for non-lane environments.
  • Add a quoted Lane: trailer to update-shape.py check NEXT commands when LANES_LANE is valid and nonblank.
  • Add the same trailer to both shape-doctor shape-currency apply command variants using the requested platform-aware quoting.
  • Suppress unsafe or unpasteable lane values and never derive Co-Authored-By: from the environment.
update-shape.py
shape-doctor.py
Update operational documentation and generated CLI reference for the new trailer workflows.
  • Document trailer usage and lane requirements for shape updates and family bumps.
  • Regenerate CLI help showing both repeatable --trailer options.
  • Raise the AGENTS.md line cap with a test-documented rationale.
AGENTS.md
docs/cli.md
tests/test_repo_hygiene.py
Add comprehensive unit, integration, and output-regression coverage for trailer behavior.
  • Test trailer grammar, Git version parsing, fallback equivalence, lane filtering, quoting, ordering, and no-trailer compatibility.
  • Test shape apply and family bump commit contents, validation timing, branch requirements, and explicit committed paths.
  • Test generated NEXT commands across lane/no-lane and shape-doctor row/platform variants.
tests/test_commit_trailers.py
tests/test_update_shape.py
tests/test_family.py
tests/test_shape_doctor.py

Assessment against linked issues

Issue Objective Addressed Explanation
#111 Add a repeatable --trailer "<Key>: <value>" option to update-shape.py apply --branch and scripts/family.py bump, preserving argument order and refusing trailers where no commit is being created. ✅
#111 Ensure supplied trailers are written to the generated commit on both modern and older Git versions, while keeping the no-trailer behavior byte-identical. ✅
#111 Include the lane trailer in printed NEXT commands when LANES_LANE is set, update the CLI and contributor documentation, and add coverage for both tools, lane propagation, fallback behavior, ordering, and default compatibility. ✅

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved trailer-validation and lane-newline issues, plus a failing documentation hygiene cap, block approval.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds repeatable commit trailers to shape and family update workflows, including lane metadata in generated commands.

Changes:

  • Adds ordered --trailer support with Git-version fallback handling.
  • Propagates lane trailers through update and diagnostic commands.
  • Updates documentation and expands validation, quoting, and hygiene tests.
File summaries
File Summary / findings
update-shape.py Adds trailer-aware shape update commits.
tests/test_update_shape.py Tests trailer handling and lane propagation.
tests/test_shape_doctor.py Tests lane-aware remediation commands.
tests/test_repo_hygiene.py Updates the documentation size guard. Critical (1 vote): the cap is below AGENTS.md’s actual length.
tests/test_family.py Tests family bump trailers.
tests/test_commit_trailers.py Tests shared trailer and Git fallback behavior.
shape-doctor.py Adds lane trailers to printed apply commands.
scripts/shape_materialize.py Provides shared trailer and lane utilities. Moderate (3 votes): trailing-newline trailers are accepted. Moderate (1 vote): newline-containing lane values are stripped before validation.
scripts/family.py Adds trailers to family bump commits.
docs/cli.md Documents the new CLI options.
AGENTS.md Updates workflow guidance.
Review details

Suppressed comments (1)

scripts/shape_materialize.py:584

  • This .strip() runs before the safety check, so LANES_LANE="xfactory-1\n" is silently changed to Lane: xfactory-1 and offered on the printed command. The lane contract says a name containing a newline must not be offered; validate the raw value and only use stripping to recognize an all-whitespace value.
    name = str((os.environ if env is None else env).get(LANE_ENV) or "").strip()
    if not name or not LANE_NAME_RE.fullmatch(name):
  • Files reviewed: 11/11 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tests/test_repo_hygiene.py Resolved
Comment thread scripts/shape_materialize.py Resolved
…newline in either is refused instead of reaching the commit message and argv (#111)

TWO HOLES OF ONE SHAPE, both found by Copilot on PR #112, and both about
"one line" being asserted by something that does not assert it.

`trailer_line` matched with `re.match` against a pattern ending in `$`, and
`$` stops just before a FINAL newline — so `--trailer "Lane: x\n"` was
accepted whole and the newline went into the message `git commit -F -` reads
and into the `--trailer` argument beside it. `.fullmatch` is what requires the
value whole, which is the lesson `shape-doctor.py`'s `quote_arg` took on PR
#102 against `"Atlas\n"`; this is the same defect one file along. And the
middle of the pattern was `[^\n]`, which is not "one line" either: `\r`, `\v`,
`\f` and a bare `\t` all went through, each a line break or a column jump to
some reader of the commit. Both classes now admit no control character at all,
and the refusal says so.

`lane_trailer` asked the alphabet about a `.strip()`ed name, so
`LANES_LANE="xfactory-1\n"` — the shape `$(cat …)` and a CRLF file produce —
was offered on the printed next command as `Lane: xfactory-1`: a name the
contract says is not offered, trimmed into one that is, with nothing said. The
raw bytes are what `LANE_NAME_RE` is now asked about, and a value with
whitespace around it is NOT a lane name, decided that way because `TRAILER_RE`
refuses a value starting or ending in whitespace — a printed line offering a
trailer this tool's own `--trailer` would then refuse is worse than one
offering none. Stripping decides exactly one thing now: that an all-whitespace
variable means no lane, which is `LANES_LANE=` spelled with a space in it.

Fourteen cases, including the trailing newline that got through, each control
character the interior class admitted, every whitespace-around-the-name shape,
and the invariant the two rules exist to keep: a lane the printer offers is a
trailer `--trailer` would accept.

The review's third finding — `AGENTS.md` at 434 lines against a cap of 433 —
does not reproduce: `wc -l AGENTS.md` is 433, the file carries 433 newlines
and 433 `splitlines()` entries and ends with one, and
`test_agents_md_is_short_enough_to_be_read` passes. The cap is untouched.

Lane: openreposhape-2 (openRepoShape-2)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Copilot AI review requested due to automatic review settings September 11, 2026 18:42
@brettheap

Copy link
Copy Markdown
Contributor Author

Lane: openreposhape-2 (openRepoShape-2)

Addressed the findings from Copilot's review of afe584b, in 5e2de2d:

1. scripts/shape_materialize.py — trailer_line() matched with .match() against a $-terminated pattern. Confirmed, fixed, and it was two holes rather than one.

Reproduced before touching anything: trailer_line("Lane: x\n") returned the value with the newline still on it, so the newline reached both the message git commit -F - reads and the --trailer argument beside it. $ stops just before a final newline, exactly as the review says — the same lesson shape-doctor.py's quote_arg took on PR #102 against "Atlas\n", one file along.

The second half of the finding ("make sure the pattern itself has no \n-tolerant class") was also real, and .fullmatch alone would not have closed it: the interior class was [^\n]*, which is not "one line". Lane: a\rb and Lane: a\x0bb were accepted before the fix. So both halves landed:

TRAILER_RE = re.compile(r"^[A-Za-z0-9][A-Za-z0-9-]*: [^\s\x00-\x1f\x7f]"
                        r"(?:[^\x00-\x1f\x7f]*[^\s\x00-\x1f\x7f])?$")
...
    if not TRAILER_RE.fullmatch(value):

and the refusal now says "one line, carries no control character and does not end in whitespace". Regression cases added to test_the_grammar_refuses_a_line_that_is_not_a_trailer: "Lane: x\n" (the trailing newline that got through), "Lane: x\r\n", and the embedded ones the interior class admitted — "Lane: a\rb", "Lane: a\x0bb", "Lane: a\x0cb", "Lane: a\tb", "Lane: x\x7f", "Lane: a\x00b". The existing embedded-newline case "Lane: two\nlines" stays.

2. scripts/shape_materialize.py — lane_trailer stripped before the safety check. Confirmed and fixed.

Reproduced: lane_trailer({"LANES_LANE": "xfactory-1\n"}) returned Lane: xfactory-1, and lane_trailer_argument printed --trailer "Lane: xfactory-1" — a name the contract says is not offered, trimmed into one that is, silently. "xfactory-1 ", " xfactory-1" and "xfactory-1\t" did the same. LANE_NAME_RE.fullmatch is now asked about the RAW value, and stripping decides exactly one thing: whether an all-whitespace variable means "no lane" (it does — that is LANES_LANE= spelled with a space in it).

    raw = str((os.environ if env is None else env).get(LANE_ENV) or "")
    if not raw.strip() or not LANE_NAME_RE.fullmatch(raw):
        return None
    line = f"Lane: {raw}"
    return line if TRAILER_RE.fullmatch(line) else None

Decided and documented, per the finding's "or decide and document": a raw value with surrounding whitespace is not a lane name, and no trailer is offered for it. The reason is in the docstring — TRAILER_RE refuses a value that starts or ends in whitespace, so a printed line offering a trailer this tool's own --trailer would then refuse is worse than a line offering none. New test_a_lane_name_with_whitespace_around_it_is_not_a_lane_name covers "xfactory-1\n" (the shape $(cat …) produces), "xfactory-1\r\n", "xfactory-1 ", " xfactory-1", "xfactory-1\t"; test_an_unset_or_blank_lane_is_no_lane already covered "", " " and "\t\n", and now reaches them through the raw path. And test_a_lane_that_is_offered_is_a_trailer_the_tool_would_accept asserts the invariant the two rules exist to keep.

3. tests/test_repo_hygiene.py:477 — "AGENTS.md is 434 lines and the cap 433, so the test fails unconditionally". Does not reproduce; the cap is untouched.

Verified rather than trusted, in the worktree at afe584b:

$ wc -l AGENTS.md
433 AGENTS.md
$ python3 -c "...read_bytes()..."
bytes: 24999 newlines: 433 splitlines: 433 ends with newline: True
$ python3 -m pytest -q "tests/test_repo_hygiene.py::test_agents_md_is_short_enough_to_be_read"
1 passed in 0.05s

tests/test_repo_hygiene.py::test_agents_md_is_short_enough_to_be_read passes, the whole file passes (48 tests), and CI's tests leg on afe584b was SUCCESS. The file has 433 newline-terminated lines and str.splitlines() — what the assertion counts — returns 433 of them, so the cap of 433 holds exactly. Nothing changed here.

The suite, on 5e2de2d. python3 -m pytest -q → 1 failed, 1066 passed, 1 skipped in 449.63s (1052 → 1066 passed; 14 new regression cases). python3 scripts/render-cli-reference.py produced no diff — neither --help string changed this round — and python3 -m pytest -q tests/test_cli_reference.py passes. The one failure is the same pre-existing tests/test_naming_policy.py::test_cli_reports_an_unread_link_as_a_warning_and_still_classifies, which fails identically on unmodified cd57c4b from a worktree in the same parent directory and passes from one under /tmp: repo_shape.resolve_link_source rule 3 finds the real ~/projects/openXdox beside the checkout, the referent link verifies, and the declared-unverified warning is never printed. Nothing in this branch touches the naming validator or that resolution.

🤖 Generated with Claude Code

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Reject additional control characters, make the baseline lane test deterministic, and update the shipped family instructions.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details

Suppressed comments (2)

AGENTS.md:357

  • templates/family-root/AGENTS-shape.md is the pinned, agent-facing mechanics document copied into every holder (see scripts/shape_materialize.py:232-238), but its family.py bump example still omits the new trailer/lane procedure. A lane agent following the generated holder instructions can therefore continue to run a bare bump and land a commit without Lane:; update the shipped family instructions along with this root guidance.
   block — the tool rewrites it wholesale. `bump` takes the same repeatable
   `--trailer "<Key>: <value>"` as `update-shape.py apply`, for the lines its
   commit must end with.

tests/test_update_shape.py:905

  • The baseline check(root, ...) inherits the test runner's LANES_LANE, so when the suite itself runs in a lane, plain may already contain the trailer and this assertion compares it with a second copy from the explicitly set lane run. Run the baseline with LANES_LANE explicitly empty, as behind_row does, to make the comparison deterministic.
    result = check(root, upstream_and_project)
    assert result.returncode == 1, result.stdout + result.stderr
    plain = next_line_of(result.stdout)
  • Files reviewed: 11/11 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread scripts/shape_materialize.py Resolved
…, not because an ASCII class does, and the holder's own instructions show `bump`'s trailers (#111)

THREE FINDINGS FROM COPILOT'S THIRD ROUND ON PR #112, one of them a hole in
the grammar the previous round opened and two of them about what a reader —
a person or a test — is told.

`[^\x00-\x1f\x7f]` READS AS "NO CONTROL CHARACTER" AND IS NOT ONE. It names
C0 and DEL and stops there, so the C1 block `\x80`-`\x9f`, U+0085 NEXT LINE,
U+2028 LINE SEPARATOR and U+2029 PARAGRAPH SEPARATOR all went through a
pattern whose whole job was "one line" — and Python's own `str.splitlines()`
treats every one of them as a line boundary, so a value the tool called one
line arrived as two in anything that read the commit message back that way.
The `Cf` characters got through the same gap without even being breaks: two
trailers differing by a zero-width joiner look identical to a reader and are
not, which is the confusion a trailer exists to avoid.

A CHARACTER CLASS LARGE ENOUGH TO NAME THEM ALL WOULD BE A SECOND, WORSE COPY
OF THE UNICODE TABLES, so `one_printable_line` asks the two questions in
their own words instead: `value.splitlines() != [value]` is this
interpreter's own definition of a line boundary, and moves by itself the day
a future Python adds one; `unicodedata.category` then refuses `Cc`, `Cf`,
`Zl`, `Zp` and `Cs`. `Cs` is there because a byte the locale could not decode
reaches `sys.argv` as a lone surrogate, which is not text at all — git is
handed that undecodable byte straight back, or, on the pre-2.32 path that
appends trailers to the MESSAGE, `subprocess` raises `UnicodeEncodeError` on
a value `--trailer` had already accepted.

`is_trailer` IS THE WHOLE RULE AND BOTH CALLERS USE IT, so the invariant the
last round established — what `--trailer` refuses, no printed next command
offers — holds by construction rather than by two checks that agree today.
`LANE_NAME_RE` needs no second guard bolted on: it is a positive alphabet of
printable ASCII, so nothing `one_printable_line` refuses can be in a lane
name, and there is now a test saying that out loud for the day somebody
widens it.

`templates/family-root/AGENTS-shape.md` IS THE PINNED, AGENT-FACING MECHANICS
DOC copied into every holder, and its `family.py bump` example still showed a
bare bump. A procedure an agent reads in the holder it is standing in is the
one it follows, so the example carries `--trailer` and a paragraph says what
it is for: `bump` composes its own message, so a `Lane:` line reaches that
commit this way and no other, and `add` and `remove` do not take it. This
repository's `AGENTS.md` said it already; the copy every holder carries did
not.

THE BASELINE HALF OF A WITH/WITHOUT COMPARISON INHERITED THE RUNNER'S LANE.
`tests/conftest.py::run_script` now blanks `LANES_LANE` for every tool under
test unless the CALLER names it — which is how a test asks for a lane — so a
suite run inside a lane asserts the same lines as one run outside it. The
baseline of the test that compares the two pins it explicitly as well: the
assertion there is "the lane run is the plain one PLUS the trailer", and a
baseline that had quietly been a second lane run would have compared two
identical lines and passed.

Sixty-five new cases in `tests/test_commit_trailers.py`, 60 to 125: every
line boundary, every invisible and every lone surrogate in the middle of a
value and at the end of one, each of the two checks proved to be the one that
catches its own half, the lane alphabet proved to exclude all of them, and
`is_trailer` proved to be the single predicate both callers use. `docs/cli.md`
regenerates byte-identical — no `--help` text moved. 1131 passed, 1 skipped;
the one red is the machine-dependent
`test_cli_reports_an_unread_link_as_a_warning_and_still_classifies` in
`tests/test_naming_policy.py`, which is pre-existing and not this branch's.

Lane: openreposhape-2 (openRepoShape-2)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Copilot AI review requested due to automatic review settings September 11, 2026 20:24
@brettheap

Copy link
Copy Markdown
Contributor Author

Lane: openreposhape-2 (openRepoShape-2)

Copilot's third round (review 5182358592) is taken in full, in c19a595. Two of its three comments carry no thread, so all three are answered here by number.

1. scripts/shape_materialize.py:471 — the grammar still admitted C1 controls, U+2028/U+2029 (and U+0085). Answered on the thread as well. [^\x00-\x1f\x7f] names C0 and DEL and stops there, so every one of those went through a pattern whose whole job was "one line" — and str.splitlines() breaks on all of them, so a value the tool called one line arrived as two in anything that read the message back that way. A class large enough to name them all would be a second, worse copy of the Unicode tables, so one_printable_line asks the two questions in their own words: value.splitlines() != [value], which is this interpreter's definition of a boundary, and unicodedata.category against ("Cc", "Cf", "Cs", "Zl", "Zp"). Cf catches what is invisible without being a break (two trailers differing by a zero-width joiner look identical to a reader and are not); Cs catches what is not text at all — a byte the locale could not decode reaches sys.argv as a lone surrogate, and git is then handed that undecodable byte straight back, or subprocess raises UnicodeEncodeError on the pre-2.32 path that appends trailers to the MESSAGE. is_trailer is the single predicate trailer_line and lane_trailer both call, so "what --trailer refuses, no printed next command offers" holds by construction. tests/test_commit_trailers.py goes 60 → 125 cases: LINE_BOUNDARIES, INVISIBLES and NOT_TEXT each in the middle of a value and at the end of one, each check proved to be the one that catches its own half, and the lane alphabet proved to exclude all of them.

2. AGENTS.md:357 — the shipped family instructions still showed a bare bump. templates/family-root/AGENTS-shape.md is the pinned, agent-facing mechanics doc copied into every holder, and a procedure an agent reads in the holder it is standing in is the one it follows. Its example now carries --trailer "Lane: <name>" --trailer "Co-Authored-By: <who>", and a paragraph beside it says what it is for: bump composes its own message, so those lines reach that commit this way and no other, rather than by amending afterwards; add and remove do not take it. It is a digest-pinned copy (it has a contracts/shape-pin.yaml row in every holder), so this shows as upstream-changed in each family holder until an estate re-pin — owed, as for the other pinned files this branch moves.

3. tests/test_update_shape.py:905 — the baseline inherited the runner's LANES_LANE. Fixed at the root as well as at the call site: tests/conftest.py::run_script now blanks LANES_LANE for every tool under test unless the CALLER names it, which is how a test asks for a lane — so a suite run inside a lane asserts the same lines as one run outside it. The baseline in that test also pins LANES_LANE="" explicitly, because the assertion there is "the lane run is the plain one PLUS the trailer" and a baseline that had quietly been a second lane run would have compared two identical lines and passed.

docs/cli.md regenerates byte-identical — no --help text moved. Full suite from the worktree: 1131 passed, 1 skipped, the single red being the pre-existing machine-dependent tests/test_naming_policy.py::test_cli_reports_an_unread_link_as_a_warning_and_still_classifies, which a sibling PR fixes.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

Only minor documentation wording and guidance nits remain; no blocking issues were identified.

Review details

Suppressed comments (2)

AGENTS.md:286

  • This new procedure is only in the standard checkout's AGENTS.md; scaffolded assembly roots read the pinned AGENTS-shape.md as their shape mechanics (scripts/shape_materialize.py:170-177), but templates/assembly-root/AGENTS-shape.md still has no guidance to pass --trailer when running a re-pin. Add the corresponding guidance to the assembly template (and its generated/pinned content) so this protocol reaches projects, not just the standard repo.
7. **`--trailer "<Key>: <value>"` puts a line on the commit `apply` writes.**
   Repeatable, kept in the order given, and only with `--branch`: without one
   there is no commit to put a line on, and it is refused. A lane passes its
   `Lane:` line and this estate's `Co-Authored-By:` there rather than amending
   the commit afterwards. Where `LANES_LANE` is set, `check`'s `NEXT` line and

AGENTS.md:287

  • LANES_LANE being set is not sufficient: lane_trailer deliberately emits nothing for values with quotes, $, backticks, backslashes, newlines, or surrounding whitespace (scripts/shape_materialize.py:638-676). As written this promises a Lane: argument for inputs the implementation intentionally suppresses, so qualify the condition as a paste-safe lane name.
   the commit afterwards. Where `LANES_LANE` is set, `check`'s `NEXT` line and
   the doctor's `shape currency` row already carry the `Lane:` argument — paste
  • Files reviewed: 13/13 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

brettheap added a commit that referenced this pull request Sep 11, 2026
…112 is fixed at each flagged line, two findings declined with reasons (#118) (#121)

Fifteen small, unrelated SonarCloud MAINTAINABILITY findings sat on `main`
(cd57c4b) in files PR #112 (`feat/shape-tool-commit-trailers`) does not
touch: duplicated literals (python:S1192), unused parameters (python:S1172),
ternaries nested inside ternaries (python:S3358), f-strings with nothing to
interpolate (python:S3457), a redundant `except` class already covered by
its own parent (python:S5713), a same-name method/field pair (python:S1845),
a character class equivalent to `\w` (python:S6353), a malformed `noqa`
suppression comment (python:S7632), and two `getAttribute` reads `.dataset`
already covers (javascript:S7761). Full per-site evidence is in #118.

Thirteen sites are fixed, each at the exact line Sonar named, with a named
constant or an independent statement replacing the flagged construct and no
behaviour change. Two are declined and explained instead of taken:

- `scripts/repo_shape.py:825`'s `reached`/`REACHED` pair (python:S1845):
  renaming ripples into `scripts/shape_materialize.py:495`, a file this pass
  must not touch (PR #112 rewrites it), and into a second, unrelated line of
  a pinned file this change already touches only at its one flagged line.
  `repo_shape.py` is also copied verbatim into every scaffolded project, so
  the name is a shipped interface, not private to this file.
- `templates/family-root/scripts/siblings.py:157`'s `MAKE_ASSIGNMENT_RE`
  (python:S6353): it is not compiled with `re.ASCII`, and the string it
  guards (a `--make-arg NAME=value` typed on the family holder operator's
  own command line) is not provably ASCII-only, so swapping in `\w` would
  silently admit Unicode word characters the surrounding comment says this
  pattern is deliberately narrow against.

`python3 scripts/render-cli-reference.py --check`: `[ok] docs/cli.md is what
the generator produces` — none of these touch an argparse option or any
`--help` text.

`timeout 1200 python3 -m pytest tests -q -p no:cacheprovider` from this
worktree, run before this commit (so still against the uncommitted diff):
**3 failed, 982 passed, 1 skipped in 446.99s**. One is the known
machine-dependent flake this fan-out's brief calls out,
`tests/test_naming_policy.py::test_cli_reports_an_unread_link_as_a_warning_and_still_classifies`.
The other two, `tests/test_family.py::test_update_shape_reads_a_family_root_and_mirrors_into_family_yaml`
and `tests/test_family.py::test_update_shape_with_no_shape_block_names_the_family_validator`,
are an artifact of testing an UNCOMMITTED change to a digest-pinned file --
`upstream_clone` (test_family.py:732) bakes the CURRENT WORKING TREE, dirty
or not, into a synthetic "upstream" clone, so any uncommitted edit to
`templates/family-root/scripts/validate-family.py` makes that file's status
`both` (locally-modified AND upstream-changed) instead of a clean single
side, which `update-shape.py` correctly refuses as `update-conflict` --
different stdout/stderr than either test expects. Proven, not assumed: a
throwaway worktree at origin/main with a trivial no-op comment appended
(uncommitted) to that same file reproduces both failures verbatim; committing
that same one-line change on the same worktree makes both pass again. This
commit is exactly that second state.

Lane: openreposhape-2 (openRepoShape-2)

Co-authored-by: Claude Fable 5.1 <[email protected]>
Copilot AI review requested due to automatic review settings September 11, 2026 21:15
… `AGENTS-shape.md`, and `LANES_LANE` is promised to carry a `Lane:` argument only for a name that survives a paste (#111)

BOTH OF COPILOT'S FOURTH ROUND ON PR #112 — two suppressed documentation
findings on the same two lines of `AGENTS.md`, and neither is about what the
tools do. They are about who is told, and about a promise wider than the code
behind it.

A PROJECT READS ITS OWN `AGENTS-shape.md`, NOT THIS CHECKOUT'S `AGENTS.md`.
`scripts/shape_materialize.py` copies `templates/assembly-root/AGENTS-shape.md`
verbatim into every scaffolded assembly root and digest-pins it, and that file
is where an agent standing in such a project learns the shape's mechanics —
including how a re-pin is run. Its "never edit a pinned file" section named the
exit (upstream, then `update-shape.py` from a checkout of the standard, landed
as a pull request) and stopped there, so the one thing the previous commits
added to that procedure reached the standard's own readers and no project's.
The section now carries the two-command block and a paragraph in the file's own
voice: `apply` takes a repeatable `--trailer`, appended in the order given, and
only alongside `--branch` because without one there is no commit to put a line
on; `apply` composes that message itself, so a `Lane:` line or a
`Co-Authored-By:` reaches the re-pin commit this way and no other rather than
by amending it afterwards; `check` writes nothing and takes none. This is the
same fix round 3 took in `templates/family-root/AGENTS-shape.md` for
`family.py bump`, applied to the other holder of the same kind of doc.

Both are pinned copies, so this moves the digest of
`templates/assembly-root/AGENTS-shape.md` and every scaffolded project will
report `upstream-changed` for it until its estate re-pins — the ordinary cost
of changing a copy, and the reason the change is one section rather than a
rewrite. `tests/test_scaffold_e2e.py` and `tests/test_family.py` recompute
those digests from the bytes on disk, so nothing is hard-coded to move with
them; each now also asserts `--trailer` is IN the file it checks, because a
procedure that reached only the standard once can do so again.

"WHERE `LANES_LANE` IS SET" PROMISED MORE THAN `lane_trailer` DELIVERS. That
function deliberately offers nothing for a lane name that would not survive
being pasted — a quote, a `$`, a backtick, a backslash, a newline, surrounding
whitespace — because a printed next command is there to be copied, and one that
breaks or expands when it is copied is worse than no line at all. A reader with
such a name, told the `NEXT` line "already carries the `Lane:` argument", would
go looking for a bug. The sentence now says what is true on both sides: where
`LANES_LANE` holds a name that survives being pasted the two printed lines
carry the argument already, and one that would not is offered on neither. Seven
lines to seven, so the 433-line cap in `tests/test_repo_hygiene.py` is
untouched.

THE THIRD ITEM THIS ROUND RAISED WAS ALREADY TAKEN. `unicodedata.category` of a
lone surrogate is `Cs`, and `UNPRINTABLE_CATEGORIES` has listed `Cs` since the
previous commit, with the grammar cases in `tests/test_commit_trailers.py`
(`NOT_TEXT`) to prove it. Verified again here rather than assumed:
`subprocess.run(["true", "Lane: a\ud800b"])` raises `UnicodeEncodeError`
instead of mangling the value, which is exactly the failure `--trailer` must
refuse at the boundary rather than let reach `git commit`.

PROVEN ON A TREE REBASED ONTO `origin/main` AT e9fa826 (#116, #117 and #121
landed under this branch while it was open) — the rebase was conflict-free,
because #121 touched `scripts/repo_shape.py`,
`scripts/render-cli-reference.py`, `setup-project.py` and the leg-template
validators and this branch edits none of them. The commit itself sits on
c19a595 unrebased: the branch ruleset refuses a force-push, which is the
correct answer, and GitHub tests the merge with `main` regardless. 1131
passed, 1 skipped on the rebased tree; the one red is the machine-dependent
`test_cli_reports_an_unread_link_as_a_warning_and_still_classifies` in
`tests/test_naming_policy.py`, pre-existing and not this branch's.
`docs/cli.md` regenerates byte-identical on both trees — through the old
`render-cli-reference.py` and through #121's new one — so no `--help` text
moved.

Lane: openreposhape-2 (openRepoShape-2)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
@brettheap

Copy link
Copy Markdown
Contributor Author

Lane: openreposhape-2 (openRepoShape-2)

Copilot's fourth round (review 5183177442, 2026-09-11T20:31:52Z, "Approval recommended", 0 new comments) listed two suppressed findings, so there were no threads to reply on. Both are taken in 0e5942b.

(i) AGENTS.md:286 — the procedure reached the standard's readers and no project's. TAKEN.
Right, and it is the same hole round 3 found in the family holder. scripts/shape_materialize.py copies templates/assembly-root/AGENTS-shape.md verbatim into every scaffolded assembly root and digest-pins it, and that is the file an agent standing in such a project reads for its shape mechanics. Its "never edit a file that has a row in contracts/shape-pin.yaml" section named the exit — upstream, then update-shape.py from a checkout of the standard, landed as a pull request — and said nothing about the flag the rest of this pull request added to that exit. The section now carries the command block and a paragraph in the file's own voice:

./update-shape.py check --root <path-to-this-project>
# then, once the human has seen the per-file verdicts and said yes:
./update-shape.py apply --root <path-to-this-project> --at <commit> --yes \
    --branch shape/update-<sha> \
    --trailer "Lane: <name>" --trailer "Co-Authored-By: <who>"

with the why beside it: repeatable, in the order given, only alongside --branch because without one there is no commit to put a line on, apply composes that message itself so a Lane: or Co-Authored-By: reaches the re-pin commit this way and no other, and check writes nothing and takes none.

This moves the digest of a pinned copy, so every scaffolded project will read upstream-changed for AGENTS-shape.md until its estate re-pins — the ordinary cost, and the reason the diff is one section rather than a rewrite. tests/test_scaffold_e2e.py and tests/test_family.py recompute those digests from the bytes on disk, so nothing is hard-coded to move with them; each now also asserts --trailer is present in the file it checks, because a procedure that reached only the standard once can do so again. There is no line cap on either template in tests/test_repo_hygiene.py.

(ii) AGENTS.md:287 — "Where LANES_LANE is set" over-promised. TAKEN.
Correct, and the gap is deliberate on the code's side: lane_trailer offers nothing for a name carrying a quote, a $, a backtick, a backslash, a newline or surrounding whitespace, because a printed next command exists to be pasted and one that breaks or expands when pasted is worse than no line at all. A reader with such a name, told the NEXT line "already carries the Lane: argument", would go hunting for a bug. Point 7 now says what is true on both sides — where LANES_LANE holds a name that survives being pasted the two printed lines carry the argument already, and one that would not is offered on neither. Seven lines to seven, so the 433-line cap in tests/test_repo_hygiene.py is untouched.

The surrogate question: already taken, in c19a595, and re-verified rather than assumed.
unicodedata.category("\ud800") is Cs, and Cs has been in UNPRINTABLE_CATEGORIES since the previous commit, with the grammar cases in tests/test_commit_trailers.py (NOT_TEXT = ["\udcff", "\ud800"]) and the reason in the constant's own comment. The why, checked again on this machine: subprocess.run(["true", "Lane: a\ud800b"]) raises UnicodeEncodeError: 'utf-8' codec can't encode character '\ud800' in position 7: surrogates not allowed — it does not silently mangle the value, so a lone surrogate is a failure --trailer must refuse at the boundary rather than let reach git commit. Nothing further was needed this round.

On the rebase. main moved three times under this branch (#116, #117, #121 → e9fa826). The whole suite was run on a tree rebased onto e9fa826, and the rebase was conflict-free: #121 touched scripts/repo_shape.py, scripts/render-cli-reference.py, setup-project.py, docs/handbook.html and the leg-template validators, none of them files this branch edits. The commit is pushed unrebased onto c19a595 — this branch's ruleset refuses a force-push, which is the right answer, and GitHub tests the merge with main regardless. docs/cli.md regenerates byte-identical on both trees, through the old renderer and through #121's new one, so no --help text moved.

Proof. 1131 passed, 1 skipped. The one red is the machine-dependent tests/test_naming_policy.py::test_cli_reports_an_unread_link_as_a_warning_and_still_classifies, pre-existing on this host and not this branch's.

Head: 0e5942b. Pinned file touched by this commit: templates/assembly-root/AGENTS-shape.md (templates/family-root/AGENTS-shape.md was already touched in c19a595).

@sonarqubecloud

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No unresolved review issues were identified, and the supplied assessments indicate readiness.

Review details
  • Files reviewed: 15/15 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

brettheap added a commit that referenced this pull request Sep 11, 2026
…ses SHAPE_PIN_SOURCE_OPENXDOX, so a developer or CI environment that exports it cannot verify the link either (#114)

PR #120 gave test_cli_reports_an_unread_link_as_a_warning_and_still_
classifies its own tmp_path cwd so a sibling ~/projects/openXdox
checkout could no longer satisfy resolve_link_source's rule 3 (the
sibling-checkout lookup) and silently turn the expected offline
warning into a verified chain. Copilot's review of that PR (id
5183204764) named the other rule in the same function that reads the
disk instead of an argument: rule 2, `SHAPE_PIN_SOURCE_<PRODUCT>` in
the environment, checked BEFORE rule 3. run_script (tests/conftest.py)
starts every subprocess from a COPY of the calling process's own
environment, so a developer shell or CI box that exports
SHAPE_PIN_SOURCE_OPENXDOX — pointed at a tree that really does declare
openDox, the same shape ~/projects/openXdox has on this workstation —
verifies the link the same way a sibling checkout would, and
`assert "WARNING codexDox: declared-unverified" in result.stderr`
fails. Reproduced against 0007cef: with that variable exported to the
real ~/projects/openXdox, the test failed with
`AssertionError: assert 'WARNING codexDox: declared-unverified' in ''`.

The test now passes its own `env=` override to run_script, pinning
SHAPE_PIN_SOURCE_OPENXDOX to a path known to carry no manifest, so the
outcome cannot depend on what the calling environment exports. Proven
against the same real checkout: the test now passes whether or not
SHAPE_PIN_SOURCE_OPENXDOX is exported ambiently.

No other test in the file shares the exposure: the two other CLI tests
that resolve a link source (test_cli_classifies_a_chain_given_on_the_
command_line, test_cli_reports_a_broken_link_as_a_finding_naming_it)
both pass an explicit --link-source for the same product, which wins
over the environment in resolve_link_source's own order regardless of
what is ambiently set, and the in-process
test_an_unreadable_link_is_declared_unverified_and_still_classifies
calls NamingPolicy.classify directly with an explicit link_pins dict,
never reaching resolve_link_source or os.environ at all.

A general rule in run_script itself — blank every SHAPE_PIN_SOURCE_*
variable unless the caller names it — would close this class of
exposure for every current and future test at once, but tests/
conftest.py is owned by PR #112 this round, so that belongs in a
follow-up rather than here.

Lane: openreposhape-2 (openRepoShape-2)

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@brettheap
brettheap merged commit 3d3c155 into main Sep 11, 2026
6 checks passed
@brettheap
brettheap deleted the feat/shape-tool-commit-trailers branch September 11, 2026 21:31
brettheap added a commit that referenced this pull request Sep 11, 2026
…ws inside PR #112's four files are fixed at each flagged line, one declined pair kept with reasons (#123) (#125)

What was wrong: shape-doctor.py, scripts/shape_materialize.py,
update-shape.py and scripts/family.py -- the four files PR #112 also
rewrites -- carried 18 open SonarCloud MAINTAINABILITY findings outside
that PR's own diff (python:S1192 duplicated literals x13, python:S5886 x1,
python:S1481 x3, python:S5713 x1), verified
live against the project's issues API and re-verified by content after
PR #112 landed at 3d3c155.

What landed:

* shape-doctor.py: AGENTS_MD, PROJECT_MANIFEST/FAMILY_MANIFEST and four
  LABEL_* constants (LABEL_MANIFEST_KINDS, LABEL_SHAPE_CURRENCY,
  LABEL_LEG_SHAPE_FILES, LABEL_AGENT_FILES), each spelled once and read at
  every site that previously retyped the literal -- a check function's own
  Row(...) returns and its CHECKS registry entry included, so the row name
  a reader sees and the one tests/test_shape_doctor.py looks up by cannot
  drift apart. leg_tracked_files's return hint is now `-> tuple`, matching
  what `return out, unwritable` actually returns and the bare `-> tuple:`
  style run_validator already uses for the same kind of helper.
* scripts/shape_materialize.py: REPO_SHAPE, NAMING_POLICY_YAML and
  BOOTSTRAP join the file's own VALIDATE_NAMING (whose comment already
  states the principle -- spelling a name in both the copy list and the
  chmod list is how the two start disagreeing), fixing 3 of the 5 flagged
  literals. The other two, "AGENTS.md"/"CLAUDE.md" in TEMPLATED and
  FAMILY_TEMPLATED, are a considered DECLINE: the file's own comment says
  the family root "gets its own four lists rather than reusing the assembly
  root's with exceptions, because 'the same list minus three entries' is a
  list that starts agreeing with neither" -- a constant shared by both
  lists would recreate exactly that coupling, for two entries out of each
  list's otherwise-uniform bare literals.
* update-shape.py: cmd_check's and cmd_apply's `prepare(args)` unpacks
  rename their unused `pin`/`kind` locals to `_` (cmd_apply still uses
  `kind` -- only its `pin` is unused), and upstream_copies's `except`
  drops `UnicodeDecodeError`, which is already a `ValueError` (by way of
  `UnicodeError`) and was named redundantly beside it.
* scripts/family.py: GITMODULES joins the file's own MANIFEST constant,
  fixing the three `.gitmodules` literals in `add`'s and `remove`'s commit
  path lists.

How it was proven: every listed literal count re-checked with an AST walk
(not grep, which cannot tell a single- from a double-quoted match apart)
before and after, each dropping to exactly 1 occurrence (its own constant's
definition) except the two declined ones, which are unchanged at 3;
update-shape.py's own AST-based upstream_copies parser (the mechanism that
reads shape_materialize.py as an "upstream" without importing it) re-run
by hand against the edited file and confirmed to resolve every new named
constant to the same tuples as before.

Built from origin/main at e9fa826, then rebased onto 3d3c155 (#111/#112's
squash merge, which also rewrites these four files) once that PR landed;
the rebase applied with no conflicts, and every literal count and the
AST-parser check above were re-run after it, unchanged. Both the
pre-rebase and post-rebase trees were proven with the full suite in the
foreground: tests/test_shape_doctor.py (137), tests/test_update_shape.py +
tests/test_update_shape_add.py + tests/test_family.py (112) and the full
suite before rebasing (984 passed, 1 skipped, 1 known pre-existing
failure); tests/test_shape_doctor.py + tests/test_update_shape.py +
tests/test_commit_trailers.py (305) and the full suite again after (1131
passed, 1 skipped, the same known pre-existing failure --
tests/test_naming_policy.py::test_cli_reports_an_unread_link_as_a_warning_and_still_classifies,
machine-dependent, not touched by this change).
scripts/render-cli-reference.py --check confirms no --help text moved,
both before and after the rebase.

Lane: openreposhape-2 (openRepoShape-2)

Co-authored-by: Claude Fable 5.1 <[email protected]>
brettheap added a commit that referenced this pull request Sep 11, 2026
…ses SHAPE_PIN_SOURCE_OPENXDOX, so a developer or CI environment that exports it cannot verify the link either (#114) (#120)

PR #120 gave test_cli_reports_an_unread_link_as_a_warning_and_still_
classifies its own tmp_path cwd so a sibling ~/projects/openXdox
checkout could no longer satisfy resolve_link_source's rule 3 (the
sibling-checkout lookup) and silently turn the expected offline
warning into a verified chain. Copilot's review of that PR (id
5183204764) named the other rule in the same function that reads the
disk instead of an argument: rule 2, `SHAPE_PIN_SOURCE_<PRODUCT>` in
the environment, checked BEFORE rule 3. run_script (tests/conftest.py)
starts every subprocess from a COPY of the calling process's own
environment, so a developer shell or CI box that exports
SHAPE_PIN_SOURCE_OPENXDOX — pointed at a tree that really does declare
openDox, the same shape ~/projects/openXdox has on this workstation —
verifies the link the same way a sibling checkout would, and
`assert "WARNING codexDox: declared-unverified" in result.stderr`
fails. Reproduced against 0007cef: with that variable exported to the
real ~/projects/openXdox, the test failed with
`AssertionError: assert 'WARNING codexDox: declared-unverified' in ''`.

The test now passes its own `env=` override to run_script, pinning
SHAPE_PIN_SOURCE_OPENXDOX to a path known to carry no manifest, so the
outcome cannot depend on what the calling environment exports. Proven
against the same real checkout: the test now passes whether or not
SHAPE_PIN_SOURCE_OPENXDOX is exported ambiently.

No other test in the file shares the exposure: the two other CLI tests
that resolve a link source (test_cli_classifies_a_chain_given_on_the_
command_line, test_cli_reports_a_broken_link_as_a_finding_naming_it)
both pass an explicit --link-source for the same product, which wins
over the environment in resolve_link_source's own order regardless of
what is ambiently set, and the in-process
test_an_unreadable_link_is_declared_unverified_and_still_classifies
calls NamingPolicy.classify directly with an explicit link_pins dict,
never reaching resolve_link_source or os.environ at all.

A general rule in run_script itself — blank every SHAPE_PIN_SOURCE_*
variable unless the caller names it — would close this class of
exposure for every current and future test at once, but tests/
conftest.py is owned by PR #112 this round, so that belongs in a
follow-up rather than here.

(Squashed by the landing session from the branch's authored commit c30d9f4; the branch also carried two git-generated merge commits, 506c499 and 059a6cf, from catching up with main under a ruleset that refuses force-push.)

Lane: openreposhape-2 (openRepoShape-2)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
brettheap added a commit that referenced this pull request Sep 12, 2026
…_* variable unless the caller names it, so no test can be swayed by what the environment happens to export (#126) (#128)

Closes #126.

## What was wrong

`run_script` (`tests/conftest.py`) blanked one inherited environment
variable, `LANES_LANE` (PR #112), but not the other family that changes
tool output the same way: `SHAPE_PIN_SOURCE_<PRODUCT>`
(`scripts/repo_shape.py`'s `PIN_SOURCE_ENV_PREFIX`), read by
`resolve_link_source`'s rule 2 BEFORE rule 3, the cwd-derived sibling
checkout. PR #120 hit this directly — Copilot found that
`test_cli_reports_an_unread_link_as_a_warning_and_still_classifies` would
verify a link it should report as declared-unverified whenever
`SHAPE_PIN_SOURCE_OPENXDOX` happened to be exported at a real
`openDox`-declaring checkout (exactly what `~/projects/openXdox` is on
this workstation) — and fixed it locally, one test at a time, with both
of its own review-thread comments naming the general fix as a follow-up
left for after PR #112 landed and gave `run_script` the `LANES_LANE`
mechanism to generalise. #126 is that follow-up.

## What landed

`run_script` gets a second blanking rule beside `LANES_LANE`: every
inherited environment variable whose name starts with
`PIN_SOURCE_ENV_PREFIX` (imported from `scripts/repo_shape.py`, not
re-spelled) is blanked to `""` unless THIS call's own `env=` names that
exact variable — `""` because `resolve_link_source`'s `if env_value:`
already reads an empty string as absent, the same convention
`lane_trailer` already uses for an empty `LANES_LANE`. PR #120's own local
`env=` override is now redundant and removed; its docstring points at two
new proof tests. No digest-pinned file (see the repo-wide list in
`AGENTS.md`) is touched by this PR.

## How it was proven

Both new tests in `tests/test_naming_policy.py` are mutation-tested, not
just written to pass once:

- `test_run_script_blanks_an_inherited_pin_source_unless_named` —
  monkeypatches the ambient `SHAPE_PIN_SOURCE_OPENXDOX` to a tree that
  WOULD verify the link and asserts the warning still prints. Disabling
  the blanking loop turns it red
  (`assert 'WARNING codexDox: declared-unverified' in ''` — the link
  verifies instead); restored, it's green.
- `test_run_script_still_passes_a_pin_source_the_caller_names` — a caller
  that DOES name the variable must still reach the child. Drafting it
  first with its verifying tree at the sibling path (`tmp_path /
  "openXdox"`) hid a real gap: a mutant that blanks EVERY
  `SHAPE_PIN_SOURCE_*` unconditionally (ignoring the caller's own `env=`)
  still left it green, because rule 3 found the same tree by accident.
  Moved to `elsewhere` (mirroring `test_a_link_source_names_the_tree_
  explicitly`'s placement for the same reason, one rule earlier), the
  same mutant now turns it red too.

Grepped `tests/` for every other caller that already names a
`SHAPE_PIN_SOURCE_*` variable in its own `env=`: only
`tests/test_neutral_pin_validator.py::test_a_neutral_pin_recomputes_from_
the_env_var`. Confirmed it still passes unchanged, and that the same
unconditional-blanking mutant above turns it red too — it already carried
its own regression coverage.

Full suite, three foreground chunks from this worktree
(`tests/test_naming_policy.py tests/test_update_shape.py
tests/test_shape_doctor.py`; the next eleven files alphabetically; the
last eleven): **1134 passed, 1 skipped**, no other red — PR #120's merged
baseline (1132 passed, 1 skipped) plus this PR's two new tests. No known
flake encountered.


## Summary by Sourcery

Make test environment isolation cover all pin-source overrides so naming and validation tests depend only on their declared inputs.

Bug Fixes:
- Prevent inherited SHAPE_PIN_SOURCE_* environment variables from altering test subprocess results unless explicitly supplied by the test.
- Keep explicitly requested pin-source overrides available to child processes while handling case-insensitive environment names safely.

Enhancements:
- Clear ambient pin-source variables for direct in-process naming-policy tests to keep link resolution hermetic.

Tests:
- Add regression and mutation-focused coverage for inherited and caller-supplied pin-source variables, including Windows-style case folding.

(Squashed by the landing session from the pull request body; the branch carried five authored commits — the rule, Copilot's case-folding round, the direct-call tests, the shared clearer, and the shared predicate — plus one git-generated merge commit from catching up with main under a ruleset that refuses force-push.)

Lane: openreposhape-2 (openRepoShape-2)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
brettheap added a commit that referenced this pull request Sep 12, 2026
…he rollback ledger to a `Rollback` object, so the body Sonar scored at 47 is the sequence of what `apply` does rather than every decision inside all of it (#133)

The function carried, in one body: the `--accept-local` unknown-path refusal,
the `--add` notes, the nothing-to-do exit, the `update-conflict` and
`update-local-drift` refusals, two nested closures that remembered every byte
written, the copy/kept/added print loops, both pin rewrites, the validator run
and its refusal, the branch/push/pull-request landing, and the two loops in the
`except Refusal` arm that put the tree back. A reader who wanted to check one
refusal read all of it, which is what a cognitive complexity of 47 is a
statement about.

What is here is the same code in the same order, moved:

  * `Rollback` is the two closures and the two undo loops as one object. It
    keeps the distinction they had — a file the root already owned is restored
    from its first bytes, a file `--add` created is deleted along with any
    directory made to hold it — and `undo` unwinds the creations in reverse so
    a directory is only considered after the file it was made for is gone.
  * `_refuse_unknown_accept_local`, `_refuse_conflicts`, `_refuse_local_drift`
    and `_refuse_red_validators` are one refusal each, asked in the order they
    were asked in, with every id, message and remediation byte-identical. The
    reasons those orderings are deliberate — a mistyped path reported as a
    mistyped path, `both` alone having an accepted exit — moved with them.
  * `_note_untaken_additions`, `_nothing_to_do`, `_write_copies`, `_repin` and
    `_land` are the report, the exit test, the write pass, the re-pin and the
    three optional acts after a clean rewrite.

`cmd_apply` keeps the sequence, the `try`/`except`/`finally` and the two
`return` values, so what it reads as now is the order in which `apply` does
things. Nothing moved across the boundary `scripts/shape_materialize.py`
shares: `commit_on_branch` and the `--trailer` path (#112) are untouched, and
`_land` only calls them. complexipy 8.0.1 scores the function at 8, and every
helper at 11 or less.

Lane: openreposhape-2 (openRepoShape-2)

Co-Authored-By: Claude Fable 5.1 <[email protected]>
brettheap added a commit that referenced this pull request Sep 12, 2026
…a named helper, cognitive complexity 51 -> 2

Sonar's python:S3776 scored `cmd_init` at 51 against the 15 the rule
allows (#136), the highest of the six functions in this cluster, also
carrying flake8's own `# noqa: C901` for the same shape: one function
validated every flag, computed who is creating the family and where its
remote and its holder land, printed the plan, refused on a non-empty
target or a live remote, created the remote (bare or `gh repo create`),
materialized and committed the holder, pushed it, set its topic, and
printed the NEXT STEPS block — the whole `init` procedure, start to
finish, in one body.

Split into one helper per phase, called in the SAME ORDER the phases
always ran: `_checked_family_identity` (the name and id checks, still
mutating `args.org`/`args.tracking_branch` as it always did),
`_creator_name`, `_holder_remote`, `_shape_snapshot`, `_template_values`,
`_checked_landing` (the `--into`/`--work-dir` refusal plus `_landing`),
`_print_init_plan` (what `--dry-run` shows and what a real run shows
first), `_prepare_landing_dir` (the target-exists refusal),
`_checked_reuse` (the remote-exists refusal, restructured as a guard
clause: `if empty is None: return False` in place of the same body nested
inside `if empty is not None`), `_create_holder_remote`,
`_create_holder_worktree` (materialize, commit, push — returning `None` on
success or the int `cmd_init` should return right now, since a push
failure is handled here with its own message and exit code rather than
left for `main`'s generic one), `_finish_holder_remote` and
`_print_next_steps`. `cmd_init` is now the outline: gather the facts,
print the plan, stop early (`--dry-run`, a push failure), or finish.

Behaviour is byte-identical: every refusal keeps its id and its exact
remediation text, every printed line and its exact wording (`values`'s own
`FAMILY_ID`/`VISIBILITY` entries are read where the removed local variables
used to be, since the dict already carried the same values), and every git
and `gh` command and its order are unchanged. `--trailer` on `bump` (#112)
and the `GITMODULES` handling in `add`/`remove` (#125) are untouched — this
commit is `cmd_init` only. `complexipy --max-complexity-allowed 15` now
passes every function in the file (`cmd_init` 2, its largest helper
`_checked_reuse` 7); `python3 -m pytest tests/test_family.py -q` still
passes all 74 tests, and `tests/test_repo_hygiene.py` still passes all 48.

Lane: openreposhape-2 (openRepoShape-2)

Co-Authored-By: Claude Fable 5.1 <[email protected]>
brettheap added a commit that referenced this pull request Sep 12, 2026
… for cognitive complexity hand each decision to a named helper, so every one of them is readable alone and every refusal, message and exit code is byte-identical (#133) (#139)

* update-shape.py: `classify` hands each pinned row to `_classify_row` and the verdict ladder to `_row_verdict`, so the function Sonar scored at 24 is a loop over rows and each decision it makes is readable alone (#133)

SonarCloud's `python:S3776` scored `classify` at 24 against a limit of 15
(complexipy 8.0.1 agrees: 24). One loop body answered three "these bytes
cannot be compared" questions and then walked a five-branch verdict ladder
over three derived booleans, so the four byte-strings the docstring names —
the recorded digest, the root's bytes, the upstream's bytes at the pinned
commit and at the target — had to be reconstructed from the ladder by anyone
reading it.

It is now three functions and the same code. `classify` is the loop.
`_classify_row` holds the three exits where a byte-string does not exist at
all (no file in the root, no upstream path this pin maps to, nothing at the
target), each of which is a human's decision rather than a difference this
tool acts on. `_row_verdict` is the ladder, reached only when all four read.

Nothing moved across the reads: the root's bytes, then the pinned blob, then
the target blob, in that order, because `Upstream.blob` shells out to git and
a reordering would change what a failing run prints. `file_sha256` is still
called exactly where it was, passed into `_row_verdict` as the argument that
was the local variable. Every state, detail string and digest assignment is
byte-identical, `continue` becoming `return` in a body that now ends the
function instead of the iteration.

classify 24 -> 1; _classify_row 3 (new); _row_verdict 11 (new).

Proven by tests/test_update_shape.py, tests/test_update_shape_add.py and
tests/test_commit_trailers.py: 178 passed.

Lane: openreposhape-2 (openRepoShape-2)

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* update-shape.py: `upstream_copies` asks `_tuple_constants` what the materializer's copy lists are and `_listed_copies` what they mean, so the `ast` scan and the mapping onto `Copy` are two functions rather than one body Sonar scored at 19 (#133)

SonarCloud's `python:S3776` scored `upstream_copies` at 19 against a limit of
15 (complexipy 8.0.1 scored it 21). It did two unrelated jobs in one body: an
`ast` walk that harvests the upstream module's top-level string and tuple
constants, and then the mapping of the three copy lists that walk found onto
`Copy` objects. Reading either required stepping over the other.

The scan is now `_tuple_constants`, which returns only the tuples — the
strings exist so `as_literal` can resolve a list entry that names a constant
rather than repeating a path, and they are not the answer, so returning them
would have left the caller holding a value it never reads. The mapping is now
`_listed_copies`, which keeps both loops in their original order, so a
`..._FROM_SHAPE` entry still overwrites a verbatim entry of the same path
exactly as it did before. `upstream_copies` keeps the two exits that make it
the entry point: no materializer at that commit, and a module that will not
parse.

No shape check moved and none was relaxed: the entry-shape tests each loop
runs are the ones that were there, because these tuples arrive from a file
read out of somebody's git history and a copy list this tool cannot vouch for
is dropped rather than guessed at.

upstream_copies 21 -> 2; _tuple_constants 9 (new); _listed_copies 10 (new).
(complexipy's numbers; Sonar scored the original 19.)

Proven by tests/test_update_shape.py, tests/test_update_shape_add.py and
tests/test_commit_trailers.py: 178 passed. `tests/test_update_shape_add.py`
is the one that drives this path — it renames copy-list entries out of a
throwaway upstream clone and asserts the `upstream-added` verdicts that
come back.

Lane: openreposhape-2 (openRepoShape-2)

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* update-shape.py: `rewrite_manifest` asks `_shape_block_bounds` where the `shape:` block is and then only edits inside it, so finding the block and rewriting it are no longer interleaved in one body Sonar scored at 16 (#133)

SonarCloud's `python:S3776` scored `rewrite_manifest` at 16 against a limit of
15. Two scans located the block — one for the `shape:` key, one for the next
top-level key after it — with the `update-manifest-no-shape` refusal between
them, and only then did the rewrite begin. Finding the block is a different
question from editing it, and the answer is what SCOPES the edit: `commit:`
and `tree_sha256:` are spelled the same way in every pin a manifest carries,
so a rewrite that ran past the end of this block would move a leg's pin while
claiming to move the shape's.

`_shape_block_bounds` now answers it and raises the one refusal that belongs
to it, because a bounds function with no bounds to return has nothing else to
do. The end of the block is unchanged in every case: the next non-blank
unindented line, or the end of the file when `shape:` is the last block a
scaffold wrote. `rewrite_manifest` keeps the rewrite, the `seen` counts and
the `update-manifest-unrecognised` refusal, all byte-identical.

rewrite_manifest 15 -> 7; _shape_block_bounds 8 (new). (complexipy's numbers;
Sonar scored the original 16.)

Proven by tests/test_update_shape.py, tests/test_update_shape_add.py,
tests/test_commit_trailers.py and tests/test_family.py: 252 passed. The
family suite is in that list because a holder mirrors the same pin into
`family.yaml` through this function.

Lane: openreposhape-2 (openRepoShape-2)

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* update-shape.py: `cmd_apply` hands each phase to a named helper and the rollback ledger to a `Rollback` object, so the body Sonar scored at 47 is the sequence of what `apply` does rather than every decision inside all of it (#133)

The function carried, in one body: the `--accept-local` unknown-path refusal,
the `--add` notes, the nothing-to-do exit, the `update-conflict` and
`update-local-drift` refusals, two nested closures that remembered every byte
written, the copy/kept/added print loops, both pin rewrites, the validator run
and its refusal, the branch/push/pull-request landing, and the two loops in the
`except Refusal` arm that put the tree back. A reader who wanted to check one
refusal read all of it, which is what a cognitive complexity of 47 is a
statement about.

What is here is the same code in the same order, moved:

  * `Rollback` is the two closures and the two undo loops as one object. It
    keeps the distinction they had — a file the root already owned is restored
    from its first bytes, a file `--add` created is deleted along with any
    directory made to hold it — and `undo` unwinds the creations in reverse so
    a directory is only considered after the file it was made for is gone.
  * `_refuse_unknown_accept_local`, `_refuse_conflicts`, `_refuse_local_drift`
    and `_refuse_red_validators` are one refusal each, asked in the order they
    were asked in, with every id, message and remediation byte-identical. The
    reasons those orderings are deliberate — a mistyped path reported as a
    mistyped path, `both` alone having an accepted exit — moved with them.
  * `_note_untaken_additions`, `_nothing_to_do`, `_write_copies`, `_repin` and
    `_land` are the report, the exit test, the write pass, the re-pin and the
    three optional acts after a clean rewrite.

`cmd_apply` keeps the sequence, the `try`/`except`/`finally` and the two
`return` values, so what it reads as now is the order in which `apply` does
things. Nothing moved across the boundary `scripts/shape_materialize.py`
shares: `commit_on_branch` and the `--trailer` path (#112) are untouched, and
`_land` only calls them. complexipy 8.0.1 scores the function at 8, and every
helper at 11 or less.

Lane: openreposhape-2 (openRepoShape-2)

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* update-shape.py: the docstrings on `_classify_row` and `_row_verdict` say that the PINNED blob is the one byte-string allowed to be absent, so neither claims a contract the code does not have (#133)

Copilot read the three new docstrings against the code on this branch and found
that two of them overstate what the split guarantees. It is right, and the fix
is the prose: nothing here changes a statement, and the file's AST is identical
to the previous commit's once docstrings are stripped from both.

  * `_classify_row` said its three early exits cover "one of the four
    byte-strings" being missing, and that `_row_verdict` is therefore "never
    reached holding a hole". Three of the four are covered; the PINNED blob is
    not. `upstream.blob(pinned, source)` returns `None` for a source the
    standard did not carry at the pinned commit, and that value is passed
    straight on. The docstring now says which three the exits are, and that
    the pinned blob is the deliberate exception.
  * `_row_verdict` said it is "reached only for a row whose four byte-strings
    all read", which is the same overstatement from the other side, and its
    very next line is `pinned_bytes is None or ...`. It now says what a `None`
    pinned blob MEANS to the ladder: `upstream_changed` true and
    `verbatim_at_pin` false, because a copy cannot be a verbatim copy of a
    blob that was never there.
  * `Rollback`'s docstring compared the moved code to "a third of what Sonar
    scored that function at" without naming the score, which read to a
    reviewer as a sentence with a number missing from it. It names the 47.

Lane: openreposhape-2 (openRepoShape-2)

Co-Authored-By: Claude Fable 5.1 <[email protected]>

---------

Co-authored-by: Claude Fable 5.1 <[email protected]>
brettheap added a commit that referenced this pull request Sep 12, 2026
…leg.py and family.py: six functions' cognitive complexity dropped to Sonar's limit of 15 (#145)

* scripts/validate-repository-naming.py: _describe's four-way claim/admission ladder answers one question per helper, cognitive complexity 35 -> 2

Sonar's python:S3776 scored `_describe` at 35 against the 15 the rule
allows (#136): the `--explain` row loop built each family's MATCH mark,
role note and claim string inline, with a four-way if/elif ladder — a
referent CLAIM, a DECLARED-ONLY note, an ADMITS note (itself a nested
three-way ladder over what is or is not declared), and an UNAMBIGUOUS
note — plus the CHAIN/WARNING/OVERLAP trailer, all in one body.

Split into one helper per decision, in the file's own leading-underscore
convention, each carrying a WHY docstring saying what it decides and that
it was split from its parent for #136: `_no_family_lines` (the NO FAMILY
early return), `_referent_claim_note`, `_declared_only_note`,
`_unambiguous_note` and `_admission_row` (the four claim answers),
`_family_claim_and_role_note` (which of the four answers this family
gets), `_family_row` (one family's full line) and `_referent_lines` (the
CHAIN/WARNING/OVERLAP trailer). `_describe` itself now only decides which
lines to assemble, not how each one reads.

Behaviour is byte-identical: every line, in the same order, from the same
conditions — this is code motion, not a fix. `complexipy --max-complexity-
allowed 15` now passes every function in the file this touches (`_describe`
2, its highest helper `_family_claim_and_role_note` 9); `python3 -m pytest
tests/test_naming_policy.py -q` still passes all 162 tests, including the
`--explain` assertions this function answers.

Lane: openreposhape-2 (openRepoShape-2)

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* scripts/validate-repository-naming.py: _targets_from_project asks _leg_target what one leg is worth, cognitive complexity 18 -> 6

Sonar's python:S3776 scored `_targets_from_project` at 18 against the 15
the rule allows (#136): the loop that walks a `project.yaml`'s legs built
each leg's `Target`, classified it, and appended its own findings in
place, then fell through to the manifest-level `topic:` check after the
loop — three questions folded into one body.

`_leg_target` now answers the first one alone: one leg's `Target` (or
`None`, with the "a leg has no `repository:`" finding, for a leg that
cannot be classified at all) and the findings that leg's own name and
chain earn. `_topic_finding` answers the second: whether the manifest's
`topic:` agrees with its `id:`. `_targets_from_project` is left as the
loop that collects both, plus the one topic finding after it — the same
shape it always had, with the two questions it was answering asked
elsewhere.

Behaviour is byte-identical: the `targets` list and the `findings` list
come back with the same elements in the same order for every case, since
each leg still contributes to both lists in the same per-leg iteration
this always ran. `complexipy --max-complexity-allowed 15` now passes
`_targets_from_project` (6) and `_leg_target` (7); `python3 -m pytest
tests/test_naming_policy.py -q` still passes all 162 tests, including the
`--project` manifest cases this function answers.

Lane: openreposhape-2 (openRepoShape-2)

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* scripts/validate-repository-naming.py: main hands off argument parsing, target gathering and the classify loop to helpers, cognitive complexity 39 -> 12

Sonar's python:S3776 scored `main` at 39 against the 15 the rule allows
(#136): parsing `--link-source`, reading targets from three sources (the
command line, `--project`, stdin), the classify-and-print loop over every
target, and the final WARNING/FINDING/exit-code trailer were all one body.

Split into `_link_sources_from_args` (the `--link-source` parsing loop),
`_targets_from_stdin` (the stdin fallback), `_print_classification` (one
plain-listing line), `_classify_targets` (the loop that classifies every
target and returns `(unclassified, warnings)`) and `_emit_reports` (the
WARNING/FINDING lines and the exit code). `main` is left as the sequence
these already were — parse, load the policy, gather targets from every
source in the same order, classify, report — with each step's own
decisions asked elsewhere. The `--project` `Refusal` handling stays
inline in `main`, unchanged, because it is `main` that must print and
`return 2` on it, exactly as the policy-load `Refusal` beside it already
does.

Behaviour is byte-identical: the same argument definitions, the same
target-gathering order (CLI names, then `--project`, then stdin only if
still empty), the same lines and the same exit codes. The one structural
change is folding two always-mutually-exclusive `if found: ... / if not
found: ...` statements in the classify loop into one `if/else`, which
decides nothing differently. `complexipy --max-complexity-allowed 15` now
passes every function in this file (`main` 12, its busiest helper
`_classify_targets` 10); `python3 -m pytest tests/test_naming_policy.py -q`
still passes all 162 tests, and
`python3 -m pytest tests/test_cli_reference.py -q` (13 passed) confirms no
`--help` text moved.

Lane: openreposhape-2 (openRepoShape-2)

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* scripts/render-cli-reference.py: render composes each tool's own section instead of every tool's in one body, cognitive complexity 16 -> 6

Sonar's python:S3776 scored `render` at 16 against the 15 the rule allows
(#136): one function built the active tool groups (a comprehension nested
inside a comprehension), the table of contents, and then, for every group
and every tool in it, the heading, the installed-as note, the tool's own
note, its captured `--help`, and every subcommand section it lists — four
questions folded into two nested loops.

`_active_tools` answers which of a group's tools this rendering keeps,
once, instead of as a comprehension nested inside the one that walks
`GROUPS`. `_tool_section` answers what one tool's whole section says;
`_subcommand_sections`, the part of that answer that lists a dispatcher's
own subcommands. `_refuse_host_paths` is Rule 1's check, split out so it
reads as its own question on the finished document rather than the last
few lines of assembling it. `render` itself is now the outline: which
groups, which sections, in which order.

Behaviour is byte-identical: `python3 scripts/render-cli-reference.py
--check` still says `[ok] docs/cli.md is what the generator produces`, so
the committed file needed no regeneration. `complexipy
--max-complexity-allowed 15` now passes every function in the file
(`render` 6); `python3 -m pytest tests/test_cli_reference.py -q` still
passes all 13 tests.

Lane: openreposhape-2 (openRepoShape-2)

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* scripts/bump-leg.py: cmd_bump hands its refusal ladder and its rewrite-or-roll-back to named helpers, cognitive complexity 28 -> 5

Sonar's python:S3776 scored `cmd_bump` at 28 against the 15 the rule
allows (#136), also carrying flake8's own `# noqa: C901` for the same
shape: one function validated `--to`, the root's cleanliness, the branch,
the submodule and the recorded gitlink (five refusal checks), reported
what it found, then rewrote the pin and every workflow file inside a
try/except that rolls every byte back on failure — the whole leg-advance
procedure in one body.

Each refusal is now a named question, in the SAME ORDER the checks always
ran: `_checked_target_commit` (`--to` is 40 hex), `_ensure_root_clean`
(tracked changes), `_branch_to_bump_from` (detached, or the tracking
branch), `_initialized_submodule`, `_recorded_leg_commit`, and, once
`fetch_leg` and the digest are already computed, exactly where the
original checked it, `_leg_pin_path`. `_print_workflow_plan` is the
workflow-count report. `_apply_rewrite` is the checkout, the pin and
workflow rewrite, the staging, the validators, and the rollback on a
caught `Refusal` or `CommandFailed` — moved whole, because splitting the
try from its except would be splitting a rollback from the write it
undoes. `cmd_bump` is now the sequence: gather the facts, refuse on the
first one that is wrong, report, and either stop (nothing to do,
`--dry-run`) or hand the rewrite to `_apply_rewrite` and make the commit.

Behaviour is byte-identical: every refusal keeps its id and its exact
remediation text, every git command this runs and its order are unchanged
(checkout detached, write, stage, validate; on failure restore bytes,
restore the leg's placement, reset the index — never reordered), and
`main`'s two `except` clauses still catch whatever this raises, whichever
helper raised it. `complexipy --max-complexity-allowed 15` now passes
every function in the file (`cmd_bump` 5, its largest helper
`_apply_rewrite` 11); `python3 -m pytest tests/test_bump_leg.py -q` still
passes all 16 tests, and `tests/test_repo_hygiene.py` still passes all 48.

Lane: openreposhape-2 (openRepoShape-2)

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* scripts/family.py: cmd_init hands each phase of creating a holder to a named helper, cognitive complexity 51 -> 2

Sonar's python:S3776 scored `cmd_init` at 51 against the 15 the rule
allows (#136), the highest of the six functions in this cluster, also
carrying flake8's own `# noqa: C901` for the same shape: one function
validated every flag, computed who is creating the family and where its
remote and its holder land, printed the plan, refused on a non-empty
target or a live remote, created the remote (bare or `gh repo create`),
materialized and committed the holder, pushed it, set its topic, and
printed the NEXT STEPS block — the whole `init` procedure, start to
finish, in one body.

Split into one helper per phase, called in the SAME ORDER the phases
always ran: `_checked_family_identity` (the name and id checks, still
mutating `args.org`/`args.tracking_branch` as it always did),
`_creator_name`, `_holder_remote`, `_shape_snapshot`, `_template_values`,
`_checked_landing` (the `--into`/`--work-dir` refusal plus `_landing`),
`_print_init_plan` (what `--dry-run` shows and what a real run shows
first), `_prepare_landing_dir` (the target-exists refusal),
`_checked_reuse` (the remote-exists refusal, restructured as a guard
clause: `if empty is None: return False` in place of the same body nested
inside `if empty is not None`), `_create_holder_remote`,
`_create_holder_worktree` (materialize, commit, push — returning `None` on
success or the int `cmd_init` should return right now, since a push
failure is handled here with its own message and exit code rather than
left for `main`'s generic one), `_finish_holder_remote` and
`_print_next_steps`. `cmd_init` is now the outline: gather the facts,
print the plan, stop early (`--dry-run`, a push failure), or finish.

Behaviour is byte-identical: every refusal keeps its id and its exact
remediation text, every printed line and its exact wording (`values`'s own
`FAMILY_ID`/`VISIBILITY` entries are read where the removed local variables
used to be, since the dict already carried the same values), and every git
and `gh` command and its order are unchanged. `--trailer` on `bump` (#112)
and the `GITMODULES` handling in `add`/`remove` (#125) are untouched — this
commit is `cmd_init` only. `complexipy --max-complexity-allowed 15` now
passes every function in the file (`cmd_init` 2, its largest helper
`_checked_reuse` 7); `python3 -m pytest tests/test_family.py -q` still
passes all 74 tests, and `tests/test_repo_hygiene.py` still passes all 48.

Lane: openreposhape-2 (openRepoShape-2)

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* Fix the three docstring wording nits Copilot's review of PR #145 found

scripts/validate-repository-naming.py: `_admission_row`'s docstring had a
stray "in" — "`role_note` in is the plain note" — read as broken English;
fixed to "`role_note` is the plain note".

scripts/bump-leg.py: `_branch_to_bump_from`'s docstring read "The branch
the bump commits on"; reworded to "The branch on which the bump commits"
per the review's suggestion, so the sentence does not lean on a trailing
preposition right before its comma.

scripts/family.py: `_template_values`'s docstring read "The substitution
values `materialize_family_root` fills the holder's template with", which
reads as though `materialize_family_root` were the values; reworded to
"The values `materialize_family_root` substitutes into the holder's
template".

Docstrings only — no code, no behaviour, no test changes.

Lane: openreposhape-2 (openRepoShape-2)

Co-Authored-By: Claude Fable 5.1 <[email protected]>

---------

Co-authored-by: Claude Fable 5.1 <[email protected]>
brettheap added a commit that referenced this pull request Sep 12, 2026
…the gap #111 left in the third pin-moving tool (#150) (#151)

#111 -> PR #112 gave `update-shape.py apply --branch` and `scripts/family.py
bump` a repeatable `--trailer "<Key>: <value>"`, so a lane's commit lands
with its `Lane:` line instead of being amended afterwards. `bump-leg.py` —
the third pin-moving tool, which writes ONE commit moving the leg gitlink,
`contracts/<role>-pin.yaml` and every workflow `@<sha>` — was not in #111's
scope: `commit_once` took no trailers and `build_parser` had no `--trailer`
at all. Today's four leg bumps in the InkRouter estate (IRRS#26, IRSS#26,
2026-09-12) each needed a `git commit --amend --trailer` by hand before the
push, exactly the step #111 existed to delete for the other two tools.

`commit_once` gains a `trailers` parameter, reusing
`shape_materialize.trailer_line` as the argparse `type=` and
`shape_materialize.commit_trailers` for the write — the same helpers #112
already gave the other two tools, no second implementation. Passed none,
`commit_trailers` hands the message and the `git commit` argv back
unchanged, which keeps a plain bump byte-identical to every one before it.
`--dry-run` now prints the trailers a real run would end the commit with,
after the `old -> new` line it already prints, through a new
`_print_trailers` helper called once `cmd_bump` knows there is something to
do (after the `nothing to do` exit, before the `--dry-run` return) — so a
real run shows the same thing right before it writes them.

`AGENTS.md`'s "Advancing a leg" section gains one numbered point saying so,
mirroring the wording #112 added under "Updating a project's shape"; the
line cap in `tests/test_repo_hygiene.py` moves 433 -> 439 with the reason in
the test's own docstring, as every previous move did. `docs/cli.md` is
regenerated for the new `--help` line.

Five new tests in `tests/test_bump_leg.py`: two trailers end the commit
message in the order given, and the run without the flag carries none — one
assertion comparing a trailed bump against a plain one made from the same
starting clone, so there is no pasted copy of today's wording to go stale.
The `git commit` argv `commit_once` builds with no trailers is asserted
byte-identical to the one it always built, against a real commit, by loading
`bump-leg.py` in-process (`importlib.util.spec_from_file_location`, the same
technique `test_update_shape.py`'s `update_shape` fixture already uses for a
hyphenated filename) and spying on `subprocess.run`. `--dry-run` prints the
trailers after the `old -> new` line (and says `none` when there are none).
A malformed trailer is refused at the argparse boundary before `cmd_bump`
ever runs — HEAD does not move and the working tree stays clean — even
though `--to` and the project are both otherwise valid.

`python3 -m pytest tests -q -p no:cacheprovider`: 1143 passed, 1 skipped
(1136 on `origin/main`, +7 for the five new tests, one of them parametrized
three ways). The one skip, unrelated to this change, is
`test_adopt_plan.py::test_plan_on_medxehr_matches_the_rulings`
(`SHAPE_MEDXEHR_CLONE` is unset on this machine). `python3 scripts/render-
cli-reference.py` regenerated `docs/cli.md`, and `tests/test_cli_reference.py`
(13 passed) confirms it matches. `tests/test_repo_hygiene.py` (48 passed)
confirms the new AGENTS.md cap.

Lane: openreposhape-2 (openRepoShape-2)

Co-authored-by: Claude Fable 5.1 <[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

Development

Successfully merging this pull request may close these issues.

update-shape.py apply --branch and family.py bump write commits with no Lane:/Co-Authored-By trailers; add a repeatable --trailer

2 participants