Skip to content

refactor: resolve sonar complexity and length violations in package modules - #1156

Open
doublewhy wants to merge 2 commits into
devfrom
1153-sonar-package-refactors
Open

refactor: resolve sonar complexity and length violations in package modules#1156
doublewhy wants to merge 2 commits into
devfrom
1153-sonar-package-refactors

Conversation

@doublewhy

Copy link
Copy Markdown

Plain-language summary

  • Context: Part of turning the red dev Sonar quality gate green (raes-strict fails on any new-code violation); the tools/ slice is PR ci(sonar): clear the tools new-code violations and exempt false positives #1155.
  • Problem: Fifteen recently-touched package modules each carry one Sonar violation: two files exactly one line over the 500-line cap (S104), four functions over 100 lines (S138), and nine functions with cyclomatic complexity 11–13 against the 10 threshold.
  • Fix: Behavior-preserving extractions only — named helpers for oversized/complex functions, and three cohesive sibling modules for the file-length violations.

Issue mapping

Summary

  • raes/composition/_expand.py: per-import provenance assembly moves into _import_provenance_additions.
  • raes/phase_contracts.py: the two constraint-pointer shape predicates hoist out of _validate_constraint.
  • raes_backend_libvirt/capability_envelope.py: the operating-system identity probe splits out of _out_of_envelope_terms.
  • raes_backend_protocols/provisioner_capabilities.py: operating-system row and artifact-kind validation extract to module helpers (mirroring the existing _validate_account_support pattern).
  • raes_backend_stubs/stubs.py: the operations fold extracts from apply into _applied_entries.
  • raes_conformance/conformance/snapshot_semantics.py: entry and disclosure builders extract from _snapshot_from_envelope.
  • raes_contracts/apparatus.py, contracts/capabilities.py, realization_envelope_carrier.py: validator bodies split into focused helper functions.
  • raes_contracts/contracts/bundle.py (501 → 413 lines): _runtime_schema_bundle and its imports move to new contracts/bundle_runtime.py.
  • raes_processor/planner/operations.py: ordered apply/delete op builders extract from _build_provisioning_plan.
  • raes_processor/semantics/realization_runtime_evaluation.py: the observation-corroboration predicate hoists out of _corroboration_diagnostic.
  • raes_runtime/backend_calls.py (501 → 438 lines): the seven ApplyResult shape validators move to new backend_call_contracts.py.
  • raes_runtime/control_plane_api_participant_retrieval.py: the three governed-view routes fold onto one shared resolve/audit flow (_resolved_governed_view), removing triplicated logic while landing under the length threshold.
  • raes_runtime/control_plane_store.py (→ 430 lines): snapshot payload builders move to new control_plane_store_payloads.py — this also keeps the file under the repo's own 500-line policy cap, which tools/check_repo_policy.py enforces.

Compatibility

  • No SDL field, schema, portable contract, CLI surface, or experiment surface changes.
  • The published schema bundle is verified byte-identical (tools/check_generated_schemas.py) despite the bundle.py split.
  • All moved functions are module-private; the test-imported surfaces of backend_calls (_call_backend_apply, _RealizationApplyContext, _call_backend_diagnostics) are untouched.

Verification

  • nox -s tests: 7,005 passed, 1 skipped; branch-aware coverage gate green.
  • tools/check_generated_schemas.py: schema bundle identical.
  • tools/check_repo_policy.py: pass (including the 500-line source-file policy).
  • Ruff 0.15.9 format and lint clean across packages/.

🤖 Generated with Claude Code

…odules

Part of turning the dev Sonar quality gate green (raes-strict fails on any
new-code violation). Fifteen recently-touched package modules each carried
one violation: two files exactly one line over the 500-line cap (S104),
four functions over 100 lines (S138), and nine functions with cyclomatic
complexity 11-13 against the 10 threshold.

All changes are behavior-preserving extractions with no public API,
contract, or schema change:

- raes/composition/_expand.py: move per-import provenance assembly into
  _import_provenance_additions
- raes/phase_contracts.py: hoist the two constraint-pointer shape
  predicates out of _validate_constraint
- raes_backend_libvirt/capability_envelope.py: split the operating-system
  identity probe out of _out_of_envelope_terms
- raes_backend_protocols/provisioner_capabilities.py: extract
  operating-system row and artifact-kind validation helpers
- raes_backend_stubs/stubs.py: extract the operations fold from apply
- raes_conformance/snapshot_semantics.py: extract entry and disclosure
  builders from _snapshot_from_envelope
- raes_contracts/apparatus.py, contracts/capabilities.py,
  realization_envelope_carrier.py: extract validator helper functions
- raes_contracts/contracts/bundle.py: move _runtime_schema_bundle and its
  imports into contracts/bundle_runtime.py (bundle output verified
  identical by tools/check_generated_schemas.py)
- raes_processor/planner/operations.py: extract ordered apply/delete op
  builders
- raes_processor/semantics/realization_runtime_evaluation.py: hoist the
  observation-corroboration predicate
- raes_runtime/backend_calls.py: move the ApplyResult shape validators
  into backend_call_contracts.py
- raes_runtime/control_plane_api_participant_retrieval.py: fold the three
  governed-view routes onto one shared resolve/audit flow
- raes_runtime/control_plane_store.py: move snapshot payload builders into
  control_plane_store_payloads.py (also keeps the file under the repo's
  own 500-line policy cap)

Verification: nox -s tests (7,005 passed, coverage gate green), ruff
format and lint clean, tools/check_generated_schemas.py identical,
tools/check_repo_policy.py pass.

Closes #1153

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The extracted _realization_observations_payload had a token-identical
twin inside control_plane_api_models._snapshot_model, which the PR
analysis surfaced as new-code duplication once the store copy moved.
The API model now calls the shared builder; behavior is unchanged
(both sites operate on the same RuntimeSnapshot disclosure objects).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

1 participant