Skip to content

chore: add unit tests for quality pipeline core functions #198

Description

@yvonnedevlinrh

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

  • generateSuggestion has a table-driven test covering all 5 switch cases and the default branch
  • WriteText complexity reduced to ≤ 15 via helper extraction (e.g., SSA diagnostics section, package summary section, style computation)
  • traceForwardDataFlow complexity reduced from 32 to ≤ 12 (extract rhsReferencesAnyTracked, handleTransformationCalls, extractDataFlowLHS)
  • Extracted helpers have direct unit tests covering previously untested paths
  • All tests run without testing.Short() guards
  • go test -race -count=1 -short ./internal/quality/... passes
  • golangci-lint run reports zero issues

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

Status
In Progress 📋

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions