Context
The internal/adapter/ package contains four provider adapters that each implement the same Call + error check + json.Unmarshal pattern for communicating with external analyzers via JSON-RPC 2.0. This 8-line pattern is duplicated across complexity.go, coverage.go, sideeffect.go, and contract.go.
Additionally, safeSSABuild (the recover() guard around prog.Build()) is duplicated between internal/analysis/mutation.go and internal/quality/pairing.go.
Related: codebase audit from #166 triage
Patterns to Extract
| Pattern |
Files |
Description |
| Protocol call + unmarshal |
4 adapter files in internal/adapter/ |
resp, err := client.Call(ctx, method, params); if err != nil { return ..., err }; var result T; if err := json.Unmarshal(resp, &result); ... |
safeSSABuild |
internal/analysis/mutation.go, internal/quality/pairing.go |
recover() guard around prog.Build() with warning log — identical implementation in both files |
Proposed Changes
- Add
callAndUnmarshal[T any](client *protocol.Client, ctx context.Context, method string, params any) (T, error) generic helper to internal/adapter/ (or internal/protocol/)
- Move
safeSSABuild to a shared internal/ssautil/ package (or similar) and update both call sites
Acceptance Criteria
Context
The
internal/adapter/package contains four provider adapters that each implement the sameCall + error check + json.Unmarshalpattern for communicating with external analyzers via JSON-RPC 2.0. This 8-line pattern is duplicated acrosscomplexity.go,coverage.go,sideeffect.go, andcontract.go.Additionally,
safeSSABuild(therecover()guard aroundprog.Build()) is duplicated betweeninternal/analysis/mutation.goandinternal/quality/pairing.go.Related: codebase audit from #166 triage
Patterns to Extract
internal/adapter/resp, err := client.Call(ctx, method, params); if err != nil { return ..., err }; var result T; if err := json.Unmarshal(resp, &result); ...safeSSABuildinternal/analysis/mutation.go,internal/quality/pairing.gorecover()guard aroundprog.Build()with warning log — identical implementation in both filesProposed Changes
callAndUnmarshal[T any](client *protocol.Client, ctx context.Context, method string, params any) (T, error)generic helper tointernal/adapter/(orinternal/protocol/)safeSSABuildto a sharedinternal/ssautil/package (or similar) and update both call sitesAcceptance Criteria
safeSSABuildhas a single source of truthanalysis.BuildSSAandquality.BuildTestSSAuse the shared versiongo test -race -count=1 -short ./...passesgolangci-lint runreports zero issues