refactor: decompose mapping.go's three highest-complexity functions#195
Merged
yvonnedevlinrh merged 1 commit intoJul 17, 2026
Merged
Conversation
Extract 9 helpers from the three highest-complexity functions in internal/quality/mapping.go: - matchContainerUnwrap (50 → 8): collectTrackedVars, traceForwardDataFlow, matchTrackedInExpr - isTransformationCall (26 → 5): isByteLikeParam, isPointerDestParam, resolveCallSignature, findParamIndex - matchAssertionToEffect (25 → 5): matchDirect, matchIndirectRoot Combined complexity reduced from 101 to 18. +25 new unit tests using synthetic AST via parseAndTypeCheck. Filled 3 test gaps in isTransformationCall (io.Reader, empty interface, mixed parameter ordering). TestSC003_MappingAccuracy ratchet (85.0%) passes unchanged — no behavioral changes. Refactored parseAndTypeCheck to delegate to parseAndTypeCheckWithFset to eliminate DRY violation. Added comment documenting intentionally ignored type-check errors in test helper. Phase 2b of issue unbound-force#166. Assisted-by: OpenCode (claude-opus-4-6) Signed-off-by: Yvonne Devlin <ydevlin@redhat.com>
trevor-vaughan
approved these changes
Jul 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Phase 2b of CRAPload fragility reduction (#166). Decomposes the three highest-complexity functions in
internal/quality/mapping.go— the assertion mapping engine — into 9 independently testable helpers.Changes
Decomposition
matchContainerUnwrapcollectTrackedVars,traceForwardDataFlow,matchTrackedInExprisTransformationCallisByteLikeParam,isPointerDestParam,resolveCallSignature,findParamIndexmatchAssertionToEffectmatchDirect,matchIndirectRootTest gap coverage
parseAndTypeCheckisTransformationCallgaps:io.Readerparameter, empty interface destination, mixed parameter orderingmatchAssertionToEffectnow has direct unit tests (previously zero)matchContainerUnwraphelpers now have unit tests (previously integration only)Test infrastructure cleanup
parseAndTypeCheckto delegate toparseAndTypeCheckWithFset(DRY)Files changed (3 source + 5 spec + 2 learnings)
Verification
Note on
traceForwardDataFlowcomplexitytraceForwardDataFlowlanded at complexity 32 — higher than the design's ~12 estimate. This is the forward data-flow tracing loop moved intact frommatchContainerUnwrap. The parent function dropped from 50 to 8 because the concerns are now isolated, but the extracted core loop retains inherent complexity from nestedast.Inspectclosures, multi-iteration convergence, and transformation call detection. Further decomposition oftraceForwardDataFlowis a candidate for Phase 2c.Review council
Spec artifacts
Full OpenSpec change at
openspec/changes/crapload-decompose-pr2b/:proposal.md— motivation + constitution alignmentdesign.md— 5 design decisions with alternatives rejectedspecs/decompose-mapping.md— 7 ADDED, 3 MODIFIED requirements with 24 scenariostasks.md— 11 tasks in 5 groups, all checked off