Context
Several core functions in internal/quality/ carry high CRAP scores due to complexity combined with incomplete test coverage. Two functions (WriteText and traceForwardDataFlow, both CC 32) need decomposition before targeted testing. One unexported function (generateSuggestion) has zero direct test coverage.
Related: #166 (Phase 2b extracted traceForwardDataFlow from matchContainerUnwrap at CC 32, higher than the design estimate of ~12)
Functions
| Function |
File |
CC |
CRAP |
Current Coverage |
Approach |
WriteText |
internal/quality/report.go |
32 |
39.9 |
80.3% (6 direct tests, but SSA diagnostics + package summary sections untested) |
Decompose into section helpers (target CC ≤ 15), then add targeted tests for extracted helpers |
traceForwardDataFlow |
internal/quality/mapping.go |
32 |
32.4 |
92.8% (3 direct tests, but transformation call path + multi-iteration convergence untested) |
Decompose (extract rhsReferencesAnyTracked, handleTransformationCalls, extractDataFlowLHS), then add targeted tests |
generateSuggestion |
internal/quality/overspec.go |
~6 |
medium |
0% direct (indirect only via ComputeOverSpecification) |
Add table-driven tests for all 5 switch cases + default |
Removed from scope (already adequately tested):
ComputeContractCoverage (coverage.go) — 5 direct unit tests since initial implementation (f8d7db0)
ComputeOverSpecification (overspec.go) — 2 direct unit tests
mapAssertionsToEffectsImpl (mapping.go) — 2 direct tests via export_test.go + 20+ indirect tests
Acceptance Criteria
Context
Several core functions in
internal/quality/carry high CRAP scores due to complexity combined with incomplete test coverage. Two functions (WriteTextandtraceForwardDataFlow, both CC 32) need decomposition before targeted testing. One unexported function (generateSuggestion) has zero direct test coverage.Related: #166 (Phase 2b extracted
traceForwardDataFlowfrommatchContainerUnwrapat CC 32, higher than the design estimate of ~12)Functions
WriteTextinternal/quality/report.gotraceForwardDataFlowinternal/quality/mapping.gorhsReferencesAnyTracked,handleTransformationCalls,extractDataFlowLHS), then add targeted testsgenerateSuggestioninternal/quality/overspec.goComputeOverSpecification)Removed from scope (already adequately tested):
ComputeContractCoverage(coverage.go) — 5 direct unit tests since initial implementation (f8d7db0)ComputeOverSpecification(overspec.go) — 2 direct unit testsmapAssertionsToEffectsImpl(mapping.go) — 2 direct tests viaexport_test.go+ 20+ indirect testsAcceptance Criteria
generateSuggestionhas a table-driven test covering all 5 switch cases and the default branchWriteTextcomplexity reduced to ≤ 15 via helper extraction (e.g., SSA diagnostics section, package summary section, style computation)traceForwardDataFlowcomplexity reduced from 32 to ≤ 12 (extractrhsReferencesAnyTracked,handleTransformationCalls,extractDataFlowLHS)testing.Short()guardsgo test -race -count=1 -short ./internal/quality/...passesgolangci-lint runreports zero issues