Skip to content

feat: extract provider interfaces for multi-language support (Phase 1 of #95) - #165

Merged
em-redhat merged 15 commits into
unbound-force:mainfrom
em-redhat:opsx/provider-interfaces
Jun 24, 2026
Merged

em-redhat merged 15 commits into
unbound-force:mainfrom
em-redhat:opsx/provider-interfaces

Conversation

@em-redhat

Copy link
Copy Markdown
Contributor

Summary

Phase 1 of Issue #95 (external analyzer protocol). Extracts four provider interfaces to decouple Go-specific analysis from the universal CRAP scoring engine, enabling future external analyzer support for multi-language analysis (e.g., snake-eyes for Python).

What Changed

New: Provider Interfaces (internal/crap/provider.go)

Four interfaces at the natural seam between Go-specific producers and universal scoring:

Interface Replaces Purpose
ComplexityProvider gocyclo.Analyze() Per-function cyclomatic complexity
LineCoverageProvider go test -coverprofile + ParseCoverProfile Per-function line coverage
SideEffectAnalyzer analysis.LoadAndAnalyze + classify.Classify Side effect detection + classification
ContractCoverageProvider BuildContractCoverageFunc Contract coverage lookup (quality pipeline)

FunctionComplexity type replaces gocyclo.Stat — language-neutral, no go/token import.

New: Go Provider Adapters (internal/provider/goprovider/)

Default Go implementations wrapping existing code behind the interfaces. Callers construct providers at call sites — crap.Analyze never imports goprovider.

New: Mock Providers (internal/provider/mockprovider/)

13 tests validating the interface layer with synthetic data: formula correctness, quadrant classification, fix strategies, error paths, provider precedence, degraded packages flow.

Modified: CRAP Pipeline (internal/crap/analyze.go)

  • computeScores accepts []FunctionComplexity instead of []gocyclo.Stat
  • gocyclo import removed — true import decoupling achieved
  • Provider dispatch with graceful degradation for contract coverage errors
  • ResolvePatterns exported as shared utility

Modified: Callers

  • cmd/gaze/main.go — constructs Go providers at call sites
  • internal/aireport/runner.go + runner_steps.go — report pipeline constructs providers

Backward Compatibility

  • Zero user-facing changes (no new CLI flags, no config changes)
  • Byte-identical output with Go providers (validated by E2E self-check)
  • Deprecated ContractCoverageFunc and SSADegradedPackages fields preserved

Testing

  • All 14 packages pass (go test -race -count=1 -short ./...)
  • E2E self-check passes (byte-identical output, 743s)
  • 13 mock provider tests + 7 test coverage gap fixes from code review

OpenSpec Artifacts

  • openspec/changes/provider-interfaces/ — proposal, design, specs, tasks (all complete)
  • Spec review: passed (5 Divisor agents)
  • Code review: passed (3 Divisor agents, 1 iteration of fixes)

Closes Phase 1 of #95

yvonnedevlinrh
yvonnedevlinrh previously approved these changes Jun 23, 2026

@yvonnedevlinrh yvonnedevlinrh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

APPROVE

All 5 CI checks pass. The refactoring cleanly extracts four provider interfaces from the monolithic CRAP pipeline, decoupling Go-specific analysis from the universal scoring engine. Spec artifacts are thorough, interface boundaries are well-chosen, and test coverage is comprehensive (13 mock tests, 7 goprovider tests, full E2E validation).

Findings

Both findings are MEDIUM severity, non-blocking, and will be addressed in separate PRs:

# Finding Severity Tracked By
1 isMainPkg triplication — now exists in crap/contract.go, aireport/runner_steps.go, and new goprovider/sideeffect.go MEDIUM #139
2 SSA degradation data from ContractCoverageProvider.Build no longer propagated to payload.Summary in runProductionPipeline MEDIUM #168

Neither finding represents a regression in user-facing behavior. Finding 1 is pre-existing technical debt (2 of 3 copies existed before this PR). Finding 2 is a subtle data flow change where the quality step still captures the same information in practice.


Reviewed-by: yvonnedevlinrh
Assisted-by: OpenCode (claude-opus-4-6)

@jflowers
jflowers force-pushed the opsx/provider-interfaces branch from bcfe297 to 9b36fba Compare June 24, 2026 12:08
em-redhat added a commit to em-redhat/gaze that referenced this pull request Jun 24, 2026
…mmary

ContractCoverageProvider.Build() returns degraded package paths
through crap.Summary.SSADegradedPackages, but this data was not
propagated from crapStepResult to payload.Summary in
runProductionPipeline.

Add SSADegradedPackages field to crapStepResult, populate from
rpt.Summary.SSADegradedPackages in runCRAPStep, and propagate to
payload.Summary alongside the quality step's degradation data.

Restores data flow parity with pre-provider-interfaces behavior.

Closes unbound-force#168
Addresses PR unbound-force#165 review feedback from @yvonnedevlinrh.
@em-redhat

Copy link
Copy Markdown
Contributor Author

Addressed finding 2 from @yvonnedevlinrh's review in 9b11671:

SSA degradation data flow restored — crapStepResult now carries SSADegradedPackages from crap.Summary, propagated to payload.Summary.SSADegraded and payload.Summary.SSADegradedPackages in runProductionPipeline. Added TestRunProductionPipeline_CRAPStepSSADegradation to verify.

Closes #168

em-redhat added a commit to em-redhat/gaze that referenced this pull request Jun 24, 2026
…mmary

ContractCoverageProvider.Build() returns degraded package paths
through crap.Summary.SSADegradedPackages, but this data was not
propagated from crapStepResult to payload.Summary in
runProductionPipeline.

Add SSADegradedPackages field to crapStepResult, populate from
rpt.Summary.SSADegradedPackages in runCRAPStep, and propagate to
payload.Summary alongside the quality step's degradation data.

Restores data flow parity with pre-provider-interfaces behavior.

Closes unbound-force#168
Addresses PR unbound-force#165 review feedback from @yvonnedevlinrh.
@em-redhat
em-redhat force-pushed the opsx/provider-interfaces branch from 9b11671 to 54d2452 Compare June 24, 2026 13:11
@em-redhat
em-redhat requested a review from yvonnedevlinrh June 24, 2026 14:14

@yvonnedevlinrh yvonnedevlinrh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

em-redhat added 11 commits June 24, 2026 17:02
Phase 1 of Issue unbound-force#95 (external analyzer protocol). Defines four
provider interfaces to decouple Go-specific analysis from the
universal scoring engine:

- ComplexityProvider (replaces gocyclo.Analyze)
- LineCoverageProvider (replaces go test -coverprofile)
- SideEffectAnalyzer (replaces analysis + classify pipeline)
- ContractCoverageProvider (replaces BuildContractCoverageFunc)

Pure refactoring — zero user-facing changes. Enables Phase 2
(JSON-RPC protocol for multi-language support).

Ref: unbound-force#95
Review council (5 Divisor agents) identified:
- 2 HIGH: lookupCoverage cascade, SideEffectAnalyzer role clarity
- 5 MEDIUM: buildCoverMap placement, task ambiguity, error scenarios
- 10 LOW: benchmarks, line refs, coverage targets

Key changes:
- D3 revised: callers construct providers explicitly (true import
  decoupling), not nil-means-default inside crap.Analyze
- D5 amended: explicit note on why SideEffectAnalyzer excluded
  from crap.Options
- D8-D10 added: buildCoverMap placement, resolvePatterns, atomicity
- Error-path scenarios added for all four interfaces
- Task 2.3: lookupCoverage + crap_test.go updates documented
- Task 3.2 split into 3.2a/3.2b (thin wrapper then verify)
- Task 3.4: single approach specified (construct providers at call sites)
- Task 4.2: precedence test and error degradation test added
- Task 5.5: benchmark verification added
- Coverage targets added to task 7.1
Define four provider interfaces in internal/crap/provider.go:
- ComplexityProvider: language-neutral cyclomatic complexity
- LineCoverageProvider: per-function line coverage data
- SideEffectAnalyzer: side effect detection + classification
- ContractCoverageProvider: contract coverage lookup builder

Add FunctionComplexity struct replacing gocyclo.Stat in the
scoring pipeline (no go/token imports).

Add provider fields to crap.Options (ComplexityProvider,
LineCoverageProvider, ContractCoverageProvider). Mark existing
ContractCoverageFunc and SSADegradedPackages as deprecated.

provider.go imports only standard library and internal/taxonomy —
zero Go-specific analysis imports per design decision D1.
Tasks 2.1-2.5 (2.3+2.4 atomic per D10):

- Create GoComplexityProvider (goprovider/complexity.go) wrapping
  gocyclo.Analyze() with gocyclo.Stat → FunctionComplexity conversion
- Create GoLineCoverageProvider (goprovider/coverage.go) wrapping
  generateCoverProfile + ParseCoverProfile with path validation
- Move testFileRegexp to goprovider (D9), generateCoverProfile and
  recoverPartialProfile to goprovider/coverage.go
- Export resolvePatterns as ResolvePatterns in crap/analyze.go (D9)
- Refactor computeScores to accept []FunctionComplexity (D4)
- Refactor lookupCoverage to accept FunctionComplexity
- Refactor crap.Analyze to use ComplexityProvider and
  LineCoverageProvider from Options (D3) — returns error if nil
- Add ContractCoverageProvider dispatch with graceful degradation
- Remove gocyclo import from crap/analyze.go
- Update callers: cmd/gaze/main.go (runCrap, runSelfCheck) and
  internal/aireport/runner_steps.go (runCRAPStep) construct
  goprovider instances explicitly
- Update all tests: FunctionComplexity replaces gocyclo.Stat,
  test providers for Analyze integration tests, recoverPartialProfile
  tests moved to goprovider

buildCoverMap and coverMaps stay in analyze.go per D8.
- Create GoSideEffectAnalyzer wrapping analysis.LoadAndAnalyze +
  classify.Classify (task 3.1)
- Create GoContractCoverageProvider wrapping BuildContractCoverageFunc
  as thin wrapper for byte-identical behavior (task 3.2a)
- Verify crap tests pass with provider (task 3.2b)
- ContractCoverageProvider dispatch in crap.Analyze already
  implemented in Phase 2 (task 3.3)
- Update cmd/gaze/main.go runCrap to construct
  GoContractCoverageProvider instead of calling
  BuildContractCoverageFunc directly (task 3.4)
- Update internal/aireport/runner.go runProductionPipeline to
  construct GoContractCoverageProvider and pass to runCRAPStep
  via crap.Options.ContractCoverageProvider (task 3.4)
- Update pipelineStepFuncs.crapStep signature to accept
  crap.ContractCoverageProvider instead of raw function (task 3.4)
- Update all pipeline_internal_test.go fake step functions to match
  new signature

All existing tests pass with zero regressions.
- Create internal/provider/mockprovider/mock.go with four mock
  implementations: MockComplexityProvider, MockLineCoverageProvider,
  MockSideEffectAnalyzer, MockContractCoverageProvider (task 4.1)
- Each mock stores configurable data and returns it on method call
- MockContractCoverageProvider tracks BuildCalled for precedence tests

- Create internal/provider/mockprovider/mock_test.go with 6 tests
  exercising mocks through crap.Analyze (task 4.2):
  (1) CRAP scores match Formula() for 3 functions with known values
  (2) Quadrant classification and fix strategies for 5 functions
      spanning all 4 quadrants (Q1-Q4)
  (3) Empty provider results produce empty report, not error
  (4) ContractCoverageReason 'all_effects_ambiguous' flows through
  (5) ContractCoverageProvider error causes graceful degradation
  (6) Provider precedence: ContractCoverageProvider wins over
      deprecated ContractCoverageFunc

- Create internal/provider/goprovider/goprovider_test.go with
  compile-time interface satisfaction checks for all four Go
  provider adapters (task 4.3)

- Add testdata/sample.go fixture for isGeneratedFile compatibility

All 14 packages pass with zero failures.
…verification tasks

- Add internal/provider/goprovider/ and mockprovider/ to architecture diagram
- Add Provider interfaces key pattern entry
- Add provider-interfaces to Recent Changes
- Mark Phase 5 (verification), Phase 6 (documentation), Phase 7
  (constitution alignment) tasks complete in tasks.md
golangci-lint flags 5 accesses to the deprecated ContractCoverageFunc
and SSADegradedPackages fields. These are intentional:

- cmd/gaze/main.go: backward-compat fallback path for test injection (D7)
- cmd/gaze/main_test.go: test directly exercises BuildContractCoverageFunc
- mockprovider/mock_test.go: precedence test verifies provider wins over
  deprecated func

Add //nolint:staticcheck directives with SA1019 references and
rationale comments.
…CoverageProvider

Fixes staticcheck SA1019 lint failures in CI.

- Replace coverageFunc test injection (raw function type) with
  contractProvider field (crap.ContractCoverageProvider interface)
  in crapParams. Eliminates 3 deprecated field accesses in main.go.
- Remove stubCoverageNil function and 8 test call sites that
  referenced it — nil is the zero value for the interface field.
- Update TestSC002 to use goprovider.NewContractCoverageProvider
  instead of BuildContractCoverageFunc + deprecated ContractCoverageFunc
  field assignment.
- Single nolint:staticcheck on mock precedence test that intentionally
  sets the deprecated field to verify provider takes precedence.
…ateCoverProfile

Two new goprovider functions (GoLineCoverageProvider.Coverage and
GoSideEffectAnalyzer.Analyze) had 0% coverage, pushing CRAPload
from 38 to 41 (threshold: 38).

Fixes:
- Add behavioral tests for Coverage (pre-generated profile, invalid
  path, directory-as-profile) and Analyze (welltested fixture,
  invalid package)
- Decompose generateCoverProfile (complexity 4 → 2) by extracting
  createTempProfile, runGoTestCoverage, and recoverOrFail helpers

CRAPload returns to <= 38 with these changes.
…mmary

ContractCoverageProvider.Build() returns degraded package paths
through crap.Summary.SSADegradedPackages, but this data was not
propagated from crapStepResult to payload.Summary in
runProductionPipeline.

Add SSADegradedPackages field to crapStepResult, populate from
rpt.Summary.SSADegradedPackages in runCRAPStep, and propagate to
payload.Summary alongside the quality step's degradation data.

Restores data flow parity with pre-provider-interfaces behavior.

Closes unbound-force#168
Addresses PR unbound-force#165 review feedback from @yvonnedevlinrh.
@em-redhat
em-redhat force-pushed the opsx/provider-interfaces branch from 54d2452 to 11a5f54 Compare June 24, 2026 16:02
@em-redhat
em-redhat merged commit 77a886d into unbound-force:main Jun 24, 2026
5 checks passed
em-redhat added a commit to em-redhat/gaze that referenced this pull request Jun 24, 2026
… 2 of unbound-force#95)

JSON-RPC 2.0 over stdin/stdout protocol for multi-language support.
Builds on provider-interfaces (Phase 1, PR unbound-force#165) which extracted
four provider interfaces from the CRAP scoring pipeline.

Phase 2 adds:
- internal/protocol/ — JSON-RPC client for analyzer subprocess
- internal/adapter/ — external provider adapters bridging protocol
  responses to Phase 1 interfaces
- --analyzer and --language CLI flags
- .gaze.yaml analyzers configuration section
- Protocol specification for external analyzer authors

8 task groups, 30 tasks total.

Ref: unbound-force#95
@em-redhat
em-redhat deleted the opsx/provider-interfaces branch June 24, 2026 16:28
@em-redhat em-redhat moved this from In Review 👀 to Done ✔️ in Unbound Force Planning Jun 24, 2026
em-redhat added a commit to em-redhat/gaze that referenced this pull request Jun 29, 2026
… 2 of unbound-force#95)

JSON-RPC 2.0 over stdin/stdout protocol for multi-language support.
Builds on provider-interfaces (Phase 1, PR unbound-force#165) which extracted
four provider interfaces from the CRAP scoring pipeline.

Phase 2 adds:
- internal/protocol/ — JSON-RPC client for analyzer subprocess
- internal/adapter/ — external provider adapters bridging protocol
  responses to Phase 1 interfaces
- --analyzer and --language CLI flags
- .gaze.yaml analyzers configuration section
- Protocol specification for external analyzer authors

8 task groups, 30 tasks total.

Ref: unbound-force#95
em-redhat added a commit to em-redhat/gaze that referenced this pull request Jun 30, 2026
… 2 of unbound-force#95)

JSON-RPC 2.0 over stdin/stdout protocol for multi-language support.
Builds on provider-interfaces (Phase 1, PR unbound-force#165) which extracted
four provider interfaces from the CRAP scoring pipeline.

Phase 2 adds:
- internal/protocol/ — JSON-RPC client for analyzer subprocess
- internal/adapter/ — external provider adapters bridging protocol
  responses to Phase 1 interfaces
- --analyzer and --language CLI flags
- .gaze.yaml analyzers configuration section
- Protocol specification for external analyzer authors

8 task groups, 30 tasks total.

Ref: unbound-force#95
sonupreetam pushed a commit to sonupreetam/gaze that referenced this pull request Aug 12, 2026
…mmary

ContractCoverageProvider.Build() returns degraded package paths
through crap.Summary.SSADegradedPackages, but this data was not
propagated from crapStepResult to payload.Summary in
runProductionPipeline.

Add SSADegradedPackages field to crapStepResult, populate from
rpt.Summary.SSADegradedPackages in runCRAPStep, and propagate to
payload.Summary alongside the quality step's degradation data.

Restores data flow parity with pre-provider-interfaces behavior.

Closes unbound-force#168
Addresses PR unbound-force#165 review feedback from @yvonnedevlinrh.

Signed-off-by: sonupreetam <[email protected]>
sonupreetam pushed a commit to sonupreetam/gaze that referenced this pull request Aug 12, 2026
… 2 of unbound-force#95)

JSON-RPC 2.0 over stdin/stdout protocol for multi-language support.
Builds on provider-interfaces (Phase 1, PR unbound-force#165) which extracted
four provider interfaces from the CRAP scoring pipeline.

Phase 2 adds:
- internal/protocol/ — JSON-RPC client for analyzer subprocess
- internal/adapter/ — external provider adapters bridging protocol
  responses to Phase 1 interfaces
- --analyzer and --language CLI flags
- .gaze.yaml analyzers configuration section
- Protocol specification for external analyzer authors

8 task groups, 30 tasks total.

Ref: unbound-force#95
Signed-off-by: sonupreetam <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done ✔️

Development

Successfully merging this pull request may close these issues.

2 participants