Skip to content

fix(analyzer): exclude isolated modules from coupling averages - #854

Open
TheNetherWatcher wants to merge 2 commits into
ludo-technologies:mainfrom
TheNetherWatcher:fix/isolated-module-coupling
Open

TheNetherWatcher wants to merge 2 commits into
ludo-technologies:mainfrom
TheNetherWatcher:fix/isolated-module-coupling

Conversation

@TheNetherWatcher

Copy link
Copy Markdown

Summary

Modules with no in-project imports and no importers (Ca + Ce = 0) have undefined instability. It defaulted to 0, giving Distance 1, and those modules were averaged into MSD and average instability, marked risk_level: high, and listed as refactoring candidates. A fully decoupled package scored worse than an import chain. This treats instability/distance as undefined for isolated modules, as proposed in the issue.

Type of Change

  • Bug fix (non-breaking change)
  • New feature (non-breaking change)
  • Breaking change
  • Documentation update
  • Performance improvement
  • Refactoring

Related Issues

Fixes #850

Changes

  • Add analyzer.IsIsolatedModule (Ca + Ce == 0).
  • calculateSystemMetrics: leave isolated modules out of MainSequenceDeviation and AverageInstability (both 0 when every module is isolated). AverageAbstractness, fan-in/out and dependency ratio are unchanged.
  • calculateSystemComplexity: compute the instability variance over the same coupled modules, so it stays consistent with the new AverageInstability.
  • identifyRefactoringPriorities: skip the distance term for isolated modules. Cycle and complexity terms still apply.
  • system_analysis_service.go: isolated modules are always RiskLevelLow, so they no longer count toward HighRiskModules.
  • docs/algorithms/dependency.md: describe the new handling of Ca + Ce = 0.
  • The extract_metrics_with_high_risk fixture had Ca = Ce = 0, so I gave it AfferentCoupling: 3 to keep testing the distance-based high-risk path.

Out of scope, as the issue notes: modules with Ca > 0, Ce = 0 and no classes (D = 1) are unchanged.

Testing

  • make test passes locally (go test -race ./...)
  • make lint passes locally (0 issues)
  • Added tests for new functionality (internal/analyzer/coupling_metrics_test.go: all-isolated graph, and a mixed graph with one isolated module)
  • Manual testing completed: ran the repro from the issue (empty pkg/__init__.py plus 4 independent modules) with binaries built before and after the change
deps_main_sequence_deviation dependency_score health_score high_risk_modules
before 1.0 80 97 5
after 0 100 100 0

Documentation

  • Updated godoc comments
  • Updated README or other docs (if needed)

Additional Context

AI disclosure: this change was written with AI assistance (Claude). I reviewed the diff and ran the tests, lint and repro above locally.

Modules with no in-project imports and no importers (Ca + Ce = 0) have
undefined instability, which defaulted to 0 and produced Distance 1.
They were averaged into MainSequenceDeviation and AverageInstability,
marked high risk, and ranked as refactoring candidates, so a fully
decoupled package scored worse than an import chain.

Leave isolated modules out of the instability/distance averages and the
instability variance used by SystemComplexity, skip the distance term in
refactoring priority for them, and report them as low risk.

Fixes ludo-technologies#850

This branch has not been deployed

No deployments
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.

[BUG][auto] msd-isolated-modules-max-distance: modules with no imports or importers get Distance 1 and inflate the MSD penalty and risk_level

2 participants