Skip to content

refactor: extract generic protocol call helper for adapter package #201

Description

@yvonnedevlinrh

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

  1. Add callAndUnmarshal[T any](client *protocol.Client, ctx context.Context, method string, params any) (T, error) generic helper to internal/adapter/ (or internal/protocol/)
  2. Move safeSSABuild to a shared internal/ssautil/ package (or similar) and update both call sites

Acceptance Criteria

  • Protocol call pattern has a single generic implementation
  • All 4 adapter files use the shared helper
  • safeSSABuild has a single source of truth
  • Both analysis.BuildSSA and quality.BuildTestSSA use the shared version
  • All existing tests pass without modification
  • go test -race -count=1 -short ./... passes
  • golangci-lint run reports zero issues

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

Status
No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions