Skip to content

shape-doctor.py and three scripts/: the SonarCloud maintainability rows inside PR #112's four files are fixed at each flagged line, one declined pair kept with reasons (#123) - #125

Merged
brettheap merged 1 commit into
mainfrom
chore/sonar-maintainability-inside-112-files
Sep 11, 2026
Merged

brettheap merged 1 commit into
mainfrom
chore/sonar-maintainability-inside-112-files

Conversation

@brettheap

@brettheap brettheap commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

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

Closes #123.

What was wrong

shape-doctor.py, scripts/shape_materialize.py, update-shape.py and
scripts/family.py -- the four files PR #112
(feat/shape-tool-commit-trailers, landed at 3d3c155) also rewrites --
carried 18 open SonarCloud MAINTAINABILITY findings outside that PR's own
diff, verified live against opensoft_openRepoShape's issues API and
re-verified by content after #112 landed:

  • shape-doctor.py: 7x python:S1192 (a duplicated string literal) --
    "AGENTS.md" x4, "project.yaml" x5, "family.yaml" x3, "manifest kinds" x3, "shape currency" x5, "leg shape files" x4, "agent files"
    x3 -- and 1x python:S5886: leg_tracked_files is hinted -> list but
    its own return out, unwritable is a 2-tuple.
  • scripts/shape_materialize.py: 5x python:S1192, all inside the copy
    lists COPIED_FROM_SHAPE/FAMILY_COPIED_FROM_SHAPE,
    COPIED_VERBATIM/FAMILY_COPIED_VERBATIM/EXECUTABLE/FAMILY_EXECUTABLE
    and TEMPLATED/FAMILY_TEMPLATED -- "scripts/repo_shape.py" x4,
    "contracts/repository-naming.yaml" x4, "scripts/bootstrap.py" x4,
    "AGENTS.md" x3, "CLAUDE.md" x3.
  • update-shape.py: 3x python:S1481 (an unused local) -- cmd_check's
    prepare(args) unpack leaves both pin and kind unread; cmd_apply's
    same unpack leaves only pin unread (kind is used repeatedly there) --
    and 1x python:S5713: except (SyntaxError, ValueError, UnicodeDecodeError) names UnicodeDecodeError redundantly, since it is
    already a ValueError (by way of UnicodeError).
  • scripts/family.py: 1x python:S1192: ".gitmodules" x3, in add's and
    remove's commit path lists.

Every python:S3776 cognitive-complexity row in these files is explicitly
OUT OF SCOPE, held on Brett Heap's word.

What landed

  • shape-doctor.py: AGENTS_MD, PROJECT_MANIFEST/FAMILY_MANIFEST and
    four LABEL_* row-name 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 in the same
    file.
  • 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. Declined, not
    missed.
  • 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.
  • 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.

No digest-pinned file (the list in AGENTS.md/the lane's shared brief) was
touched -- these four files are not among them.

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 --
was 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, 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 (git's
merge correctly interleaved this PR's Row(...)/list-literal edits with
#112's own edits a few lines away in the same statements -- e.g.
shape-doctor.py's shape-currency FINDING returns now carry both
LABEL_SHAPE_CURRENCY and #112's appended {lane_trailer_command()}).

Both the pre-rebase and post-rebase trees were proven with the full suite
in the foreground:

  • Before rebasing: tests/test_shape_doctor.py (137),
    tests/test_update_shape.py + tests/test_update_shape_add.py +
    tests/test_family.py (112), then the full suite -- 984 passed, 1
    skipped, 1 known pre-existing failure.
  • After rebasing: tests/test_shape_doctor.py + tests/test_update_shape.py
    • tests/test_commit_trailers.py (305), then the full suite -- 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: [ok] docs/cli.md is what the generator produces -- no --help text moved, checked both before and
after the rebase.

🤖 Generated with Claude Code

Summary by Sourcery

Clean up the remaining maintainability issues in the shape tooling without changing its behavior.

Bug Fixes:

  • Resolve SonarCloud maintainability findings across the shape doctor, materialization, update, and family management scripts.

Enhancements:

  • Centralize repeated manifest, label, file, and Git submodule path names while preserving intentionally independent template lists.
  • Align helper type annotations and simplify exception handling and unused-value unpacking.

Chores:

  • Document the deliberate retention of separate AGENTS.md and CLAUDE.md template literals where sharing them would couple distinct lists.

…ws inside PR #112's four files are fixed at each flagged line, one declined pair kept with reasons (#123)

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]>
Copilot AI lite review requested due to automatic review settings September 11, 2026 21:49
@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 2 days and 19 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

Fixes the scoped SonarCloud maintainability findings across four files by centralizing repeated literals, correcting one return annotation, removing unused locals, and simplifying exception handling. Two templating literals remain intentionally duplicated because sharing them would couple independently defined assembly and family lists; cognitive-complexity findings remain out of scope.

Sequence diagram for update-shape command cleanup

sequenceDiagram
    participant Caller
    participant UpdateShape
    participant Upstream
    Caller->>UpdateShape: cmd_check(args)
    UpdateShape->>UpdateShape: prepare(args)
    UpdateShape->>Upstream: tree_sha256(pinned)
    UpdateShape->>Upstream: tree_sha256(target)
    Caller->>UpdateShape: cmd_apply(args)
    UpdateShape->>UpdateShape: prepare(args)
    UpdateShape->>Upstream: upstream_copies(upstream, rev, kind)
    alt invalid source bytes or syntax
        Upstream-->>UpdateShape: return {}
    end
Loading

File-Level Changes

Change Details Files
Centralize repeated filenames and row labels in shape-doctor.py while correcting an inaccurate helper return annotation.
  • Introduce constants for manifest filenames, AGENTS.md, and four row display labels.
  • Replace repeated literals in checks, probes, and the CHECKS registry with those constants.
  • Change leg_tracked_files from list to tuple return typing.
shape-doctor.py
Deduplicate shared materialization paths while preserving deliberate independence between family and assembly template lists.
  • Add constants for repo_shape.py, repository-naming.yaml, and bootstrap.py and reuse them across copy and executable lists.
  • Keep AGENTS.md and CLAUDE.md templating literals separate to avoid coupling intentionally distinct list definitions.
scripts/shape_materialize.py
Remove unused unpacked locals and simplify redundant exception handling in update-shape.py.
  • Replace unused prepare() unpack targets with underscores in cmd_check and cmd_apply.
  • Catch ValueError without redundantly naming its UnicodeDecodeError subclass.
update-shape.py
Centralize the .gitmodules path used by family membership commit operations.
  • Define GITMODULES and use it in add and remove commit path lists, including remove's re-staging list.
scripts/family.py

Assessment against linked issues

Issue Objective Addressed Explanation
#123 Eliminate the duplicated SonarCloud string-literal findings in shape-doctor.py, scripts/shape_materialize.py, and scripts/family.py by defining reusable constants while preserving all literal values and behavior; intentionally leave the AGENTS.md and CLAUDE.md family-template duplicates unchanged for the documented decoupling reason. ✅
#123 Fix update-shape.py's maintainability findings by removing unused unpacked locals and eliminating the redundant UnicodeDecodeError exception type. ✅
#123 Correct shape-doctor.py's leg_tracked_files return annotation so it reflects the two-value tuple actually returned. ✅

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

@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 blocking issues remain.

Pull request overview

This pull request resolves SonarCloud maintainability findings across four shape-management scripts while preserving behavior.

Changes:

  • Centralizes repeated manifests, labels, paths, and Git submodule constants.
  • Corrects tuple typing and simplifies exception handling and unused unpacking.
  • Preserves intentionally independent template lists.
File summaries
File Summary
update-shape.py Simplifies exception handling and unused unpacking.
shape-doctor.py Centralizes manifest and label constants and fixes tuple typing.
scripts/shape_materialize.py Centralizes repeated materialization paths.
scripts/family.py Centralizes the .gitmodules path.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 0
  • Review effort level: Lite

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

@brettheap
brettheap merged commit 0220300 into main Sep 11, 2026
6 checks passed
@brettheap
brettheap deleted the chore/sonar-maintainability-inside-112-files branch September 11, 2026 22:05
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
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants