Skip to content

refactor: split oversized modules and cut function complexity (MOD-001) - #743

Merged
Brad-Edwards merged 2 commits into
devfrom
740-MOD-001-sonar-modularity
Jul 12, 2026
Merged

refactor: split oversized modules and cut function complexity (MOD-001)#743
Brad-Edwards merged 2 commits into
devfrom
740-MOD-001-sonar-modularity

Conversation

@Brad-Edwards

Copy link
Copy Markdown
Collaborator

Why

The devmain promotion (PR #740) fails SonarCloud's aces-strict
quality gate with new_violations = 9 (threshold 0). Every other condition
passes (coverage 92.6%, duplication 0.4%, all ratings A). The 9 issues are
accumulated modularity debt on dev surfaced by the aggregate main..dev diff:

  • 5× S104 — files over SonarCloud's 500-line cap
  • 4× FunctionComplexity — functions over cyclomatic complexity 10

(Note: the repo's own ADR-015 cap is 600 lines, which is why local verify
passed; SonarCloud independently caps at 500.) Per the project review standards,
these are fixed by real decomposition — not by relaxing the Sonar threshold or
adding per-file ignores.

What

Each oversized module is split along a cohesive seam; moved symbols are
re-imported into their original module so every public import path and __all__
stays byte-for-byte stable (zero changes at ~30 call sites). Each over-complex
function is decomposed into small helpers.

Module splits (S104):

Original (was ≥500) New sibling
aces_sdl/parser.py _model_diagnostics.py (pydantic-error rendering)
aces_sdl/_runtime_service_families.py _runtime_service_family_registry.py (registry data)
aces_sdl/_yaml_loader.py _mapping_key_analyzer.py (key-validation walker)
aces_operations/_evidence_run_validation.py _evidence_run_realization.py
aces_operations/libvirt_evidence_run.py _evidence_run_native.py
aces_backend_libvirt/techvault_concerns.py techvault_plan_admission.py
aces_backend_libvirt/techvault_native.py _techvault_native_ops.py

EvidenceCheck / LibvirtEvidenceRunConfig relocated to the existing
_evidence_run_types.py to break an import cycle; both re-exported.

_yaml_loader.py and techvault_native.py were not S104 "new" (already >500 on
main); they were split because the complexity fixes below pushed them over the
600-line ADR-015 repo cap.

Complexity reductions (all now ≤10):

  • _validate_unrealized_substrate (11) — extract _unrealized_daemon_leak
  • _walk_mapping_entry (13) — extract _validate_entry_identifiers
  • TechVaultNativeLibvirtDriver.__post_init__ (12) — split into two validators
  • LibvirtProvisioner._drive (14) — extract _active_addresses / _realize_active / _delete_targets

Verification

  • No behaviour change — pure structural refactor.
  • Full nox -s verify green locally (ruff, requirement governance, repo policy
    incl. the 600-line cap, all pytest + integration, contracts, docs).
  • Once merged into dev, PR Dev #740's SonarCloud gate goes to new_violations = 0.

Requirement: MOD-001 (Codebase Modularity And Layering).

The dev->main promotion (PR #740) failed SonarCloud's aces-strict quality gate
with 9 new violations: 5 files over the 500-line S104 cap and 4 functions over
cyclomatic complexity 10. Split each oversized module along a cohesive seam and
decomposed each over-complex function into helpers. Moved symbols are re-imported
into their original modules so every public import path and __all__ stays stable.
No behaviour change; full nox verify green.

Splits:
- aces_sdl.parser -> _model_diagnostics (pydantic-error diagnostic rendering)
- aces_sdl._runtime_service_families -> _runtime_service_family_registry (registry data)
- aces_sdl._yaml_loader -> _mapping_key_analyzer (mapping-key validation walker)
- aces_operations._evidence_run_validation -> _evidence_run_realization
- aces_operations.libvirt_evidence_run -> _evidence_run_native (EvidenceCheck /
  LibvirtEvidenceRunConfig relocated to _evidence_run_types to break the cycle)
- aces_backend_libvirt.techvault_concerns -> techvault_plan_admission
- aces_backend_libvirt.techvault_native -> _techvault_native_ops

Complexity reductions (all now <=10):
- _evidence_run_realization._validate_unrealized_substrate (11)
- _mapping_key_analyzer._walk_mapping_entry (13)
- techvault_native.TechVaultNativeLibvirtDriver.__post_init__ (12)
- provisioner.LibvirtProvisioner._drive (14)
The extracted _active_addresses helper does not use instance state; SonarCloud
flagged python:S2325. Make it a staticmethod (called via the instance in _drive).
@sonarqubecloud

Copy link
Copy Markdown

@Brad-Edwards
Brad-Edwards merged commit 96bd6af into dev Jul 12, 2026
13 checks passed
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