👻 Export Analyzer accessors and update progress types for MCP server#926
Conversation
Add 4 exported methods to the Analyzer interface (Providers, RuleSets, Cache, CachedRuleSets) so the upcoming MCP server can query analyzer internals without reimplementing. Update progress type references to match current analyzer-lsp HEAD (ProgressReporter->Reporter, ProgressEvent->Event) and bump the analyzer-lsp dependency. Signed-off-by: JonahSussman <sussmanjonah@gmail.com>
📝 WalkthroughWalkthroughThis PR updates the codebase to use a newer analyzer-lsp API where Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
kai_analyzer_rpc/pkg/service/rpc_progress_reporter_test.go (1)
121-125:⚠️ Potential issue | 🟡 MinorFail fast when payload type assertion fails in tests.
At Line 121 and Line 152, field assertions only run when
notification.argsisprogress.Event; if not, the test silently passes. Add explicit failure branches to avoid false positives.✅ Suggested test hardening
- if eventArg, ok := notification.args.(progress.Event); ok { + if eventArg, ok := notification.args.(progress.Event); ok { if eventArg.Stage != stages[i] { t.Errorf("notification %d: expected stage %s, got %s", i, stages[i], eventArg.Stage) } + } else { + t.Fatalf("notification %d: expected args type progress.Event, got %T", i, notification.args) }- if eventArg, ok := notifications[0].args.(progress.Event); ok { + if eventArg, ok := notifications[0].args.(progress.Event); ok { if eventArg.Current != 5 { t.Errorf("expected current 5, got %d", eventArg.Current) } if eventArg.Total != 10 { t.Errorf("expected total 10, got %d", eventArg.Total) } if eventArg.Percent != 50.0 { t.Errorf("expected percent 50.0, got %f", eventArg.Percent) } + } else { + t.Fatalf("expected args type progress.Event, got %T", notifications[0].args) }Also applies to: 152-162
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@kai_analyzer_rpc/pkg/service/rpc_progress_reporter_test.go` around lines 121 - 125, The test silently skips checks when notification.args is not a progress.Event; change both type-assertion blocks (the ones using "if eventArg, ok := notification.args.(progress.Event); ok { ... }") to fail fast by adding an else branch that calls t.Fatalf (or t.Errorf followed by return) with the actual type information, e.g. report that notification.args was not a progress.Event and include its type/value; make the same change for the second occurrence (the block that inspects stages and other fields) so the test cannot pass silently when the payload type assertion fails.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@kai_analyzer_rpc/pkg/service/analyzer.go`:
- Around line 236-246: The accessors Providers(), RuleSets(), and Cache() expose
live mutable internals (a.initedProviders, a.discoveryRulesets,
a.violationRulesets, a.cache); change them to return defensive copies or
immutable snapshots instead: for Providers() return a newly allocated map with
copied entries from a.initedProviders; for RuleSets() return copies of the
slices (copy the slice header and underlying elements into new slices) for
discoveryRulesets and violationRulesets; for Cache() either return an immutable
snapshot/clone of a.cache or expose a read-only interface method (e.g.,
Snapshot() or ReadOnlyIncidentsCache) that prevents callers from mutating the
analyzer's internal cache. Ensure you use the existing symbol names (Providers,
RuleSets, Cache, initedProviders, discoveryRulesets, violationRulesets, cache)
when making the changes.
---
Outside diff comments:
In `@kai_analyzer_rpc/pkg/service/rpc_progress_reporter_test.go`:
- Around line 121-125: The test silently skips checks when notification.args is
not a progress.Event; change both type-assertion blocks (the ones using "if
eventArg, ok := notification.args.(progress.Event); ok { ... }") to fail fast by
adding an else branch that calls t.Fatalf (or t.Errorf followed by return) with
the actual type information, e.g. report that notification.args was not a
progress.Event and include its type/value; make the same change for the second
occurrence (the block that inspects stages and other fields) so the test cannot
pass silently when the payload type assertion fails.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 299cf035-3b25-4881-a190-f5557b3bab01
⛔ Files ignored due to path filters (1)
kai_analyzer_rpc/go.sumis excluded by!**/*.sum
📒 Files selected for processing (11)
kai_analyzer_rpc/go.modkai_analyzer_rpc/main.gokai_analyzer_rpc/main_test.gokai_analyzer_rpc/pkg/rpc/server.gokai_analyzer_rpc/pkg/rpc/server_windows.gokai_analyzer_rpc/pkg/service/analyzer.gokai_analyzer_rpc/pkg/service/analyzer_exports_test.gokai_analyzer_rpc/pkg/service/multi_progress_reporter.gokai_analyzer_rpc/pkg/service/pipe_analyzer.gokai_analyzer_rpc/pkg/service/rpc_progress_reporter.gokai_analyzer_rpc/pkg/service/rpc_progress_reporter_test.go
The analyzer-lsp dependency bump requires go 1.25. Update trunk's go runtime and golangci-lint accordingly. Signed-off-by: JonahSussman <sussmanjonah@gmail.com>
Providers(), RuleSets(), and Cache() now return copies instead of live internal references, preventing callers from mutating analyzer state. Signed-off-by: JonahSussman <sussmanjonah@gmail.com>
Signed-off-by: JonahSussman <sussmanjonah@gmail.com>
Summary
Analyzerinterface:Providers(),RuleSets(),Cache(),CachedRuleSets()— enabling the upcoming MCP server to query analyzer internals without reimplementingProgressReporter→Reporter,ProgressEvent→Event, reporters moved toprogress/reportersub-package)lib.GetProviderClientcalls for new*progress.ProgressparameterTrunk config update
The analyzer-lsp dependency bump requires
go 1.25, which broke trunk's golangci-lint (v1.61.0, built with go 1.23). Updated trunk config:go@1.23.0→go@1.25.0golangci-lint@1.61.0→golangci-lint@1.64.8(v2 has a module path change that trunk can't install yet)trunk upgrade checkTest plan
analyzer_exports_test.go)trunk check --cipasses with no new issuesContext
The Konveyor MCP server (konveyor/enhancements#259) is being built in a separate repo (
konveyor-ecosystem/analyzer-mcp) that imports kai-analyzer in-process. These exports let the MCP server access providers, rulesets, and cached results directly rather than reimplementing.