Repository navigation
feat: extract provider interfaces for multi-language support (Phase 1 of #95) - #165
Conversation
9c139fd to
bcfe297
Compare
yvonnedevlinrh
left a comment
There was a problem hiding this comment.
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)
bcfe297 to
9b36fba
Compare
…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.
|
Addressed finding 2 from @yvonnedevlinrh's review in SSA degradation data flow restored — Closes #168 |
…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.
9b11671 to
54d2452
Compare
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.
…eld usage" This reverts commit 54c6723.
…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.
54d2452 to
11a5f54
Compare
… 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
… 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
… 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
…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]>
… 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]>
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:
ComplexityProvidergocyclo.Analyze()LineCoverageProvidergo test -coverprofile+ParseCoverProfileSideEffectAnalyzeranalysis.LoadAndAnalyze+classify.ClassifyContractCoverageProviderBuildContractCoverageFuncFunctionComplexitytype replacesgocyclo.Stat— language-neutral, nogo/tokenimport.New: Go Provider Adapters (
internal/provider/goprovider/)Default Go implementations wrapping existing code behind the interfaces. Callers construct providers at call sites —
crap.Analyzenever importsgoprovider.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)computeScoresaccepts[]FunctionComplexityinstead of[]gocyclo.Statgocycloimport removed — true import decoupling achievedResolvePatternsexported as shared utilityModified: Callers
cmd/gaze/main.go— constructs Go providers at call sitesinternal/aireport/runner.go+runner_steps.go— report pipeline constructs providersBackward Compatibility
ContractCoverageFuncandSSADegradedPackagesfields preservedTesting
go test -race -count=1 -short ./...)OpenSpec Artifacts
openspec/changes/provider-interfaces/— proposal, design, specs, tasks (all complete)Closes Phase 1 of #95