Repository navigation
templates/assembly-root/scripts/{validate-pins,validate-manifest,bootstrap}.py: split all eight cognitive-complexity-15+ functions into helpers, behaviour unchanged (#132) - #140
Conversation
…four decisions into helpers, cognitive complexity 28 -> 2 (#132) _check_leg mixed four independent questions in one function: whether the pin file's own fields look right, whether the gitlink agrees with the pin's commit, whether the leg's tree digest recomputes, and whether every workflow `@<sha>` reference agrees with the gitlink. SonarCloud's python:S3776 flagged it at cognitive complexity 28, well over the 15 cap now that the hold on python:S3776 is lifted. Split into `_load_leg_pin`, `_check_gitlink_matches_pin`, `_check_pin_digest` and `_check_workflow_refs_for_leg`, one per question, each named for what it decides. `_check_leg` is now a five-line sequence of calls in the original order. Every message, exit code, exception type and the sequence of findings is unchanged — this moves code, it does not fix anything. Lane: openreposhape-2 (openRepoShape-2) Co-Authored-By: Claude Fable 5.1 <[email protected]>
…pin's header check and per-file loop body into helpers, cognitive complexity 17 -> 4 (#132) _check_shape_pin mixed checking the pin file's own commit fields with looping over every pinned file's digest, which SonarCloud's python:S3776 flagged at cognitive complexity 17. Split into `_check_shape_pin_header` (the commit/kind/manifest-agreement checks) and `_check_shape_copy` (one `files:` row, called once per loop iteration instead of holding the row logic inline). `_check_shape_pin` keeps the same `before = len(report.findings)` bracket around the loop so the "digests match" note still depends on nothing having been found, exactly as before. Every message, exit code and finding order is unchanged. Lane: openreposhape-2 (openRepoShape-2) Co-Authored-By: Claude Fable 5.1 <[email protected]>
…l_product_pins' per-entry recheck into helpers, cognitive complexity 32 -> 2 (#132) The whole re-check of one `neutral_product_pins:` entry — loading its pin file, checking the commit and digest fields, resolving where to recompute the referent's tree digest from, and comparing it — lived inline in the loop body, which SonarCloud's python:S3776 flagged at cognitive complexity 32. Split into `_check_neutral_pin_entry_and_load`, `_check_neutral_pin_commit_ and_digest_fields`, `_recompute_neutral_pin_digest` and `_check_one_neutral_product_pin` (one call per loop iteration), each named for the one question it answers. Every `continue` in the original loop becomes a `return None` from the helper that used to hold it, and the caller's `if ... is None: return` reads the same as the loop moving to the next entry. Every message, exit code, exception type and finding/skip order is unchanged. Lane: openreposhape-2 (openRepoShape-2) Co-Authored-By: Claude Fable 5.1 <[email protected]>
…nt setup, per-leg checks and report emission into helpers, cognitive complexity 19 -> 2 (#132) `main` built the `--pin-source` lookup tables, loaded the manifest and its legs, ran every check, and printed the report, all inline — SonarCloud's python:S3776 flagged it at cognitive complexity 19, driven mostly by the list comprehension filtering non-assembly legs and the sequence of Refusal guards around the manifest. Split into `_parse_pin_sources`, `_load_legs_to_check`, `_run_all_checks` (the single call inside `main`'s one `try`) and `_emit_report`. `main` is now argument setup, the `try`/`except Refusal`, and one final call. Every message, exit code and the exact sequence of checks (per-leg, then the shape pin, then the neutral-product pins) is unchanged. This finishes templates/assembly-root/scripts/validate-pins.py's four flagged functions for #132 (`_check_leg`, `_check_shape_pin`, `_check_neutral_product_pins`, `main`); the other two files it names are next. Lane: openreposhape-2 (openRepoShape-2) Co-Authored-By: Claude Fable 5.1 <[email protected]>
…indings' four questions into helpers, cognitive complexity 38 -> 5 (#132) _naming_findings checked one leg's optional `naming:` record against the naming policy in a single flat run: the chain field's shape, everything the classifier's own result implies (a broken referent chain, its warnings, form/role/also_matches agreement), whether a `<Domainx><Product>` name's descendant_referent is one of its real forms, and — when referent_declared is true — whether the pin file for the referent this leg actually holds exists. SonarCloud's python:S3776 flagged it at cognitive complexity 38. Split into `_naming_chain_field_finding`, `_naming_classification_findings`, `_naming_referent_findings` and `_naming_referent_declared_findings`, one per question. `_naming_referent_findings` returns its findings alongside a bool standing in for the original function's early `return out` inside `if not referents:`, so `_naming_findings` still stops there when a name claims no descent. Every message, exit code and finding/warning order is unchanged — this moves code, it does not fix anything. Lane: openreposhape-2 (openRepoShape-2) Co-Authored-By: Claude Fable 5.1 <[email protected]>
…' per-field and per-leg checks into helpers, cognitive complexity 69 -> 4 (#132) _findings ran every check of `project.yaml` inline — the envelope (schema_version/kind/schema), id/name/election/topic, the optional reference/visibility fields, the shape pin, and then a loop over `legs` whose body itself classified each leg's name, checked its `naming:` record and validated its path, all appending to one closure-captured `out` through a local `bad()`. SonarCloud's python:S3776 flagged it at cognitive complexity 69, by far the largest in this cluster. Split into one helper per field this schema requires or admits (`_envelope_findings`, `_id_findings`, `_name_finding`, `_elected_by_finding`, `_elected_on_finding`, `_topic_finding`, `_reference_finding`, `_visibility_finding`, `_shape_findings`, `_neutral_product_pins_type_finding`, `_roles_finding`, `_owners_span_finding`) plus a per-leg helper table for the loop (`_leg_findings`, calling `_leg_role_classification_finding` and `_leg_path_findings`), each named for the one question it answers and called from `_findings` in the exact original order — the id check's `bad()` closure becomes the module-level `_finding()` formatter every one of them uses. `_leg_findings` mutates the `owners` set and `paths` dict the loop already threaded through, so the collision and owners-span checks still see the same accumulated state, and every `continue` in the original loop is a `return` from the helper that used to hold it. Every message, exit code and finding order is unchanged — this moves code, it does not fix anything. Lane: openreposhape-2 (openRepoShape-2) Co-Authored-By: Claude Fable 5.1 <[email protected]>
…per-register and per-row reporting into helpers, cognitive complexity 27 -> 7 (#132) read_authority mixed the degrade-line guard, the loop over every register file found, reading and defaulting its rows, and the loop over each row checking whether it named this project, all in one function. SonarCloud's python:S3776 flagged it at cognitive complexity 27. Split into `_load_register_rows` (one register file's rows, `None` standing in for the original inner loop's `continue` on an unreadable file), `_row_report_line` (one row, formatted or `None` when it matches nothing) and `_report_one_register` (one register file start to finish, called once per file found). `read_authority` is now the degrade-line guard, building `repositories`/`prefixes`, and one call per register file. Every message, exit code and report order is unchanged — this moves code, it does not fix anything. Lane: openreposhape-2 (openRepoShape-2) Co-Authored-By: Claude Fable 5.1 <[email protected]>
…p (a) and step (b) into helpers, cognitive complexity 30 -> 8 (#132) `main` built the root and manifest behind two separate try/except Refusal blocks, then ran step (a)'s tracking-branch placement, step (b)'s validator loop and upstream notice, and the final pass/fail summary, all inline. SonarCloud's python:S3776 flagged it at cognitive complexity 30 — the last of this cluster's eight functions. Split into `_load_root_and_manifest` (both steps behind `main`'s now-single `try`, so either one's `Refusal` is still the same early exit 2), `_checkout_all_tracking_branches` (step a) and `_run_neutral_validators` (step b, returning the failed-labels list `main` used to accumulate locally). `main` is now argument setup, the one `try`, and a five-line sequence of calls in the original order. Every message, exit code and the exact sequence of git commands `checkout_tracking_branch` runs is unchanged — this moves code, it does not fix anything. This finishes the eight functions #132 named across templates/assembly-root/scripts/{validate-pins.py,validate-manifest.py, bootstrap.py}. Lane: openreposhape-2 (openRepoShape-2) Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
@codex review |
There was a problem hiding this comment.
Sorry @brettheap, you've used your own review budget of 250,000 diff characters for the last 7 days.
You can request another review in 3 days and 14 hours by commenting @sourcery-ai review. Upgrade to get a review now.
Reviewer's GuideThe PR is a behavior-preserving refactor of the three assembly-root scripts: the eight functions exceeding cognitive-complexity limits are decomposed into focused helpers, while public signatures, control-flow effects, diagnostics, side-effect order, and CLI behavior remain unchanged. Review should focus on helper boundaries and preservation of early returns, loop state, report ordering, and exception behavior; the reported validation suite and complexity checks pass. Sequence diagram for the refactored pin validation flowsequenceDiagram
participant CLI
participant Main as validate-pins.main
participant Checks as _run_all_checks
participant Leg as _check_leg
participant Shape as _check_shape_pin
participant Neutral as _check_neutral_product_pins
participant Report as _emit_report
CLI->>Main: parse arguments
Main->>Checks: _run_all_checks(root, report, keyed_sources, default_source)
Checks->>Leg: _check_leg(root, leg, report, refs)
Leg->>Leg: _load_leg_pin(...)
Leg->>Leg: _check_gitlink_matches_pin(...)
Leg->>Leg: _check_pin_digest(...)
Leg->>Leg: _check_workflow_refs_for_leg(...)
Checks->>Shape: _check_shape_pin(root, manifest, report)
Shape->>Shape: _check_shape_pin_header(...)
Shape->>Shape: _check_shape_copy(...) per files row
Checks->>Neutral: _check_neutral_product_pins(...)
Neutral->>Neutral: _check_one_neutral_product_pin(...) per entry
Main->>Report: _emit_report(report, quiet)
Report-->>CLI: exit code and diagnostics
Sequence diagram for the refactored bootstrap flowsequenceDiagram
participant CLI
participant Main as bootstrap.main
participant Load as _load_root_and_manifest
participant Branches as _checkout_all_tracking_branches
participant Validators as _run_neutral_validators
participant Authority as read_authority
CLI->>Main: parse arguments
Main->>Load: _load_root_and_manifest(args)
Main->>Branches: _checkout_all_tracking_branches(root, sub_legs, manifest, branch_arg)
Branches->>Branches: checkout_tracking_branch(...) per leg
Main->>Validators: _run_neutral_validators(root, manifest, skip)
Validators->>Validators: _run(...) per validator
Main->>Authority: read_authority(root, legs)
Authority->>Authority: _report_one_register(...) per register
Authority->>Authority: _load_register_rows(register_path)
Authority->>Authority: _row_report_line(...) per matching row
Flow diagram for the refactored manifest findings pipelineflowchart TD
Find[_findings]
Envelope[_envelope_findings]
Fields[Field-specific finding helpers]
Legs[_leg_findings]
Naming[_naming_findings]
Paths[_leg_path_findings]
Owners[_owners_span_finding]
Find --> Envelope
Find --> Fields
Find --> Legs
Legs --> Naming
Legs --> Paths
Find --> Owners
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
🟢 Approval recommended
No unresolved review findings; the refactor preserves existing behavior.
Pull request overview
Refactors eight high-complexity functions in the assembly-root validation and bootstrap scripts while preserving behavior.
Changes:
- Split pin, manifest, and naming validation into focused helpers.
- Extracted bootstrap workflow and authority-reporting helpers.
- Preserved interfaces, messages, ordering, and exit codes.
File summaries
| File | Summary |
|---|---|
templates/assembly-root/scripts/validate-pins.py |
Decomposes pin and digest checks. |
templates/assembly-root/scripts/validate-manifest.py |
Decomposes manifest and naming checks. |
templates/assembly-root/scripts/bootstrap.py |
Decomposes bootstrap steps and authority reporting. |
Review details
- Files reviewed: 3/3 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.
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…eferent_declared_findings' two questions into helpers, cognitive complexity 20 -> 0 (#132) The PR's own SonarCloud analysis (opensoft_openRepoShape#140) still flagged one function after the first eight: local `complexipy` had scored `_naming_referent_declared_findings` at 13, under the 15 cap, but python:S3776's own recompute put it at 20 — the two ternary-in-string expressions building `how_reached` and the missing-pin message weigh more under Sonar's actual rule than complexipy's approximation of it. Split into `_how_referent_reached` (the if/elif/else that used to build `how_reached`, called instead of assigned inline), and one helper per independent `if` the function already had — `referent_declared`'s mismatch against what was reached, and the missing-pin-file check that runs only when it is `true` — since both were already separate, sequential checks that never depended on each other's result. Every message, exit code and finding order is unchanged. Lane: openreposhape-2 (openRepoShape-2) Co-Authored-By: Claude Fable 5.1 <[email protected]>
|



Lane: openreposhape-2 (openRepoShape-2)
Claim: #132 (comment)
Closes #132.
What was wrong
python:S3776(cognitive complexity) flagged eight functions across theassembly-root template's three digest-pinned, dependency-free scripts, all
over the 15 cap now that Brett Heap lifted the hold on that rule
("lets fix the 35 sonar issues", 2026-09-12T02:1xZ):
validate-pins.py_check_leg_load_leg_pin,_check_gitlink_matches_pin,_check_pin_digest,_check_workflow_refs_for_leg— one per fact being comparedvalidate-pins.py_check_shape_pin_check_shape_pin_header(the pin's own fields) +_check_shape_copy(onefiles:row, called per loop iteration)validate-pins.py_check_neutral_product_pins_check_neutral_pin_entry_and_load,_check_neutral_pin_commit_and_digest_fields,_recompute_neutral_pin_digest,_check_one_neutral_product_pin(one call per loop entry)validate-pins.pymain_parse_pin_sources,_load_legs_to_check,_run_all_checks(the one call insidemain'stry),_emit_reportvalidate-manifest.py_naming_findings_naming_chain_field_finding,_naming_classification_findings,_naming_referent_findings,_naming_referent_declared_findings— one per question the function asked about a leg'snaming:recordvalidate-manifest.py_findings_envelope_findings,_id_findings,_name_finding,_elected_by_finding,_elected_on_finding,_topic_finding,_reference_finding,_visibility_finding,_shape_findings,_neutral_product_pins_type_finding,_roles_finding,_owners_span_finding) plus a per-leg helper table (_leg_findingscalling_leg_role_classification_findingand_leg_path_findings) for the loop overlegs; the nestedbad()closure became the module-level_finding()formatterbootstrap.pyread_authority_load_register_rows,_row_report_line,_report_one_register(one call per register file found)bootstrap.pymain_load_root_and_manifest(both refusal-guarded steps behind onetry),_checkout_all_tracking_branches(step a),_run_neutral_validators(step b)The first four were done and pushed before this session picked up the lane
(commits
a4eef2a,13065fc,b0f0a43,653a01b); this PR's own work isthe last four, one commit per function (
ef418d5,e58d21d,fd4837b,f8d834e) plus a ninth, below, that only the PR's own SonarCloud analysisfound:
validate-manifest.py_naming_referent_declared_findingscomplexipyhad scored it 13, under the cap)_how_referent_reached(the if/elif/else that builthow_reached) plus one helper per one of the function's two already-independent, sequentialifstatements —_naming_referent_declared_mismatch_findingand_naming_referent_missing_pin_finding(commit59fa834)What landed
Three digest-pinned files touched, hunks kept minimal:
templates/assembly-root/scripts/validate-pins.pytemplates/assembly-root/scripts/validate-manifest.pytemplates/assembly-root/scripts/bootstrap.pyscripts/repo_shape.py(imported by all three) was read but not edited —it belongs to a different cluster. No signature that anything else imports
or calls was changed; every message, exit code, exception type, side-effect
order and git-command sequence is byte-for-byte the same as before. This
moves code; it does not fix anything, and no bug was noticed while doing it
— nothing to file as a follow-up.
How it was proven
complexipy <file> -mx 15after every split: all sixteen newhelpers and all eight original functions pass (
maininvalidate-pins.py2,_findings4,read_authority7,maininbootstrap.py8, highest new helper 13).tests/test_manifest_validator.py(38 passed),
tests/test_scaffold_e2e.py(44 passed),tests/test_naming_policy.py,tests/test_adopt_e2e.py,tests/test_adopt_spec_only.py,tests/test_reference_default.py,tests/test_scaffold_pin_and_reuse.py(276 passed together),
tests/test_update_shape.py(36 passed).tests/test_[a-m]*.py— 366 passed, 1 skipped (the known flake-free skip);tests/test_[n-z]*.py— 770 passed. Total 1136 passed / 1 skipped, matchingthe count the brief expected on
main.--helptext changed (noargparsecall touched), sorender-cli-reference.pywas not re-run;tests/test_cli_reference.pypassed unchanged as part of the
[a-m]chunk.complexipyonlyapproximates) was queried after CI went green and came back with exactly
one
python:S3776left, in a functioncomplexipyhad scored under thecap;
tests/test_manifest_validator.py(38 passed) andtests/test_scaffold_e2e.py(44 passed) were re-run after splitting itfurther, and the query will be repeated once CI reruns on that push.
A workstation reboot mid-session corrupted the shared git object store with
zero-byte objects (this branch's head among them); the orchestrator
quarantined them and re-fetched from origin.
git fsck --connectivity-onlycame back clean (only harmless dangling objects, no missing/broken links)
and every commit, test run and complexipy measurement above was re-verified
against the recovered tree before this PR was opened.
🤖 Generated with Claude Code