Skip to content

Prepares the tool for integration with kubecompare MCP#12

Merged
mvazquezc merged 3 commits intoopenshift-kni:mainfrom
mvazquezc:prepare-mcp-integration
Apr 20, 2026
Merged

Prepares the tool for integration with kubecompare MCP#12
mvazquezc merged 3 commits intoopenshift-kni:mainfrom
mvazquezc:prepare-mcp-integration

Conversation

@mvazquezc
Copy link
Copy Markdown
Collaborator

No description provided.

…ternal use of the required methods.

Co-authored-by: Claude <noreply@anthropic.com>

Signed-off-by: Mario Vazquez <mavazque@redhat.com>
@openshift-ci
Copy link
Copy Markdown

openshift-ci Bot commented Apr 20, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mvazquezc

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 20, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 20, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 10f506b7-1697-4db1-b73a-3cbb38ca1b15

📥 Commits

Reviewing files that changed from the base of the PR and between d3aac28 and 8978153.

📒 Files selected for processing (2)
  • CLAUDE.md
  • CLAUDE.md
✅ Files skipped from review due to trivial changes (2)
  • CLAUDE.md
  • CLAUDE.md

📝 Walkthrough

Walkthrough

Add bytes-based constructors/validators to expose analyzer/rules as a public pkg/ library, migrate imports from internal to pkg, update CLI imports and docs, and add tests validating in-memory YAML rule handling and equivalence with file-based flows.

Changes

Cohort / File(s) Summary
Documentation
AGENTS.md
Describes RDS Analyzer as both a Go CLI and importable library; documents public pkg/ layout, moves Cobra CLI guidance to internal/cli, updates examples to reference pkg/..., and mentions analyzer.NewFromBytes.
CLI
internal/cli/root.go
Switched imports from internal/... to pkg/... for analyzer, rules, and types; runtime calls unchanged.
Analyzer
pkg/analyzer/analyzer.go, pkg/analyzer/analyzer_test.go
Added exported NewFromBytes([]byte, string) (*Analyzer, error) that initializes an Analyzer from in-memory YAML (validates regexes, wraps engine errors). Updated imports to pkg/.... Tests added for valid/invalid YAML, version propagation, equivalence with file-based New, and analyze output across formats/modes.
Rules Engine
pkg/rules/engine.go, pkg/rules/engine_test.go
Added NewEngineFromBytes(data []byte, version string) and ValidateRulesRegexpPatternsFromBytes(data []byte, sourceName string); refactored file-based functions to delegate to bytes-based helpers, improved YAML error messages and sourceName propagation. Tests exercise YAML parsing, invalid version, regex validation warnings/errors, and bytes-vs-file equivalence.
Parser
pkg/parser/diff.go, pkg/parser/diff_test.go
Updated imports in code and tests to github.com/openshift-kni/rds-analyzer/pkg/types (replacing former internal/types).
Report Modules
pkg/report/html.go, pkg/report/html_test.go, pkg/report/reporting.go, pkg/report/reporting_test.go, pkg/report/text.go, pkg/report/text_test.go
Replaced imports to use pkg/ variants of parser, rules, and types; no logic or API signature changes in shown diffs.
Misc / New file
AGENTS.md
Added file documenting agents/library layout and usage; content updates referenced above.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant CLI as CLI / Client
  participant Analyzer as Analyzer (pkg/analyzer)
  participant Rules as Rules Engine (pkg/rules)
  participant Reporter as Reporter (pkg/report)

  CLI->>Analyzer: NewFromBytes(rulesYAML, version)
  Note right of Analyzer: validate YAML and regex patterns
  Analyzer->>Rules: NewEngineFromBytes(rulesYAML, version)
  Rules->>Rules: parse YAML, validate regexes
  Rules-->>Analyzer: Engine or error
  CLI->>Analyzer: Analyze(diff, format, mode)
  Analyzer->>Reporter: Render(report, format, mode)
  Reporter-->>CLI: output (text/html or text)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 62.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive No description was provided by the author. This is insufficient to convey the changeset details. Add a description explaining the refactoring from internal/ to pkg/ structure, the new NewFromBytes constructors, and their purpose for MCP integration.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title directly describes the main structural change: preparing the codebase for MCP integration by reorganizing internal packages into a public pkg/ structure with new exported constructors.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

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)
pkg/rules/engine.go (1)

57-63: ⚠️ Potential issue | 🟡 Minor

Preserve source file context when NewEngineWithVersion delegates to byte-based constructor.

If YAML parsing fails, the current returned error loses the originating rulesFile, which makes field debugging harder in multi-source flows.

💡 Suggested fix
 func NewEngineWithVersion(rulesFile, version string) (*Engine, error) {
 	data, err := os.ReadFile(rulesFile)
 	if err != nil {
 		return nil, fmt.Errorf("failed to read rules file: %w", err)
 	}
-	return NewEngineFromBytes(data, version)
+	engine, err := NewEngineFromBytes(data, version)
+	if err != nil {
+		return nil, fmt.Errorf("failed to initialize rules engine from %q: %w", rulesFile, err)
+	}
+	return engine, nil
 }

As per coding guidelines, **/*.go: "Wrap errors with context using fmt.Errorf("context: %w", err)".

Also applies to: 68-72

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/rules/engine.go` around lines 57 - 63, NewEngineWithVersion currently
returns whatever NewEngineFromBytes returns and loses the original rulesFile
context; change NewEngineWithVersion so after calling NewEngineFromBytes(data,
version) it checks the error and, if non-nil, wraps it with
fmt.Errorf("reading/parsing %s: %w", rulesFile, err) (or similar) to include the
rulesFile name; apply the same pattern to NewEngine (the no-version variant) so
both functions wrap and return errors from NewEngineFromBytes with the source
file context preserved.
🧹 Nitpick comments (3)
AGENTS.md (1)

38-39: Consider using one term consistently: “regex” or “regexp”.

The section currently mixes both forms; standardizing one term improves readability.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@AGENTS.md` around lines 38 - 39, The doc mixes “regex” and “regexp”; pick one
term (e.g., use “regex”) and update all occurrences for consistency—replace
mentions in the paragraph that reference rules.ValidateRulesRegexpPatterns,
analyzer.New, and the --validate-rules-only path so they all use the chosen term
(e.g., “regex patterns in condition rules (global_rules, rules)”) and ensure any
code-symbol names or function references remain unchanged while only harmonizing
the descriptive wording.
pkg/rules/engine.go (1)

3-13: Reorder imports to standard → external → internal.

gopkg.in/yaml.v3 should be grouped before github.com/openshift-kni/rds-analyzer/pkg/types.

💡 Suggested import grouping
 import (
 	"fmt"
 	"os"
 	"path/filepath"
 	"regexp"
 	"strings"
 
-	"github.com/openshift-kni/rds-analyzer/pkg/types"
-
 	"gopkg.in/yaml.v3"
+
+	"github.com/openshift-kni/rds-analyzer/pkg/types"
 )

As per coding guidelines, **/*.go: "Order imports as: standard library first, then external dependencies, then internal packages".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/rules/engine.go` around lines 3 - 13, Reorder the import block so
standard library packages (fmt, os, path/filepath, regexp, strings) come first,
then external dependencies like gopkg.in/yaml.v3, and finally internal packages
such as github.com/openshift-kni/rds-analyzer/pkg/types; update the import
grouping in the import declaration in pkg/rules/engine.go accordingly so
gopkg.in/yaml.v3 appears before the internal types import.
pkg/analyzer/analyzer_test.go (1)

261-410: Consider consolidating the NewFromBytes scenario tests into a table-driven test.

The current coverage is good, but these cases are repetitive and would be easier to extend/maintain in one table-driven block.

As per coding guidelines, **/*_test.go: Use table-driven tests for multiple test cases.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/analyzer/analyzer_test.go` around lines 261 - 410, Multiple
TestNewFromBytes_* tests are repetitive; consolidate them into a single
table-driven test that iterates cases for NewFromBytes (and subsequent Analyze
calls) to reduce duplication. Create a slice of test cases with fields like
name, rulesBytes, version, expectError (or expectOutputContains for Analyze),
format/mode for Analyze, and expected HTML/text content; loop over cases and for
each call NewFromBytes (or New for the file case), assert error behavior, and
when applicable call Analyze and check buffer contents (use existing symbols
NewFromBytes, New, Analyze, and types.ValidationReport). Replace the individual
TestNewFromBytes_* functions with this single table-driven test to cover
valid/invalid YAML, invalid version/regex, HTML output, reporting mode, and
parity with New, using subtests t.Run for each case.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@AGENTS.md`:
- Around line 13-22: The fenced code block in the README-like section is missing
a language identifier which triggers markdownlint MD040; update the opening
fence (the ``` that precedes the directory tree) to include an explicit language
identifier (use "text") so it becomes ```text, keeping the block content
unchanged; this fix targets the fenced code block that contains the pkg/ ├──
analyzer/ ... internal/ └── cli/ tree in AGENTS.md to satisfy the linter.

---

Outside diff comments:
In `@pkg/rules/engine.go`:
- Around line 57-63: NewEngineWithVersion currently returns whatever
NewEngineFromBytes returns and loses the original rulesFile context; change
NewEngineWithVersion so after calling NewEngineFromBytes(data, version) it
checks the error and, if non-nil, wraps it with fmt.Errorf("reading/parsing %s:
%w", rulesFile, err) (or similar) to include the rulesFile name; apply the same
pattern to NewEngine (the no-version variant) so both functions wrap and return
errors from NewEngineFromBytes with the source file context preserved.

---

Nitpick comments:
In `@AGENTS.md`:
- Around line 38-39: The doc mixes “regex” and “regexp”; pick one term (e.g.,
use “regex”) and update all occurrences for consistency—replace mentions in the
paragraph that reference rules.ValidateRulesRegexpPatterns, analyzer.New, and
the --validate-rules-only path so they all use the chosen term (e.g., “regex
patterns in condition rules (global_rules, rules)”) and ensure any code-symbol
names or function references remain unchanged while only harmonizing the
descriptive wording.

In `@pkg/analyzer/analyzer_test.go`:
- Around line 261-410: Multiple TestNewFromBytes_* tests are repetitive;
consolidate them into a single table-driven test that iterates cases for
NewFromBytes (and subsequent Analyze calls) to reduce duplication. Create a
slice of test cases with fields like name, rulesBytes, version, expectError (or
expectOutputContains for Analyze), format/mode for Analyze, and expected
HTML/text content; loop over cases and for each call NewFromBytes (or New for
the file case), assert error behavior, and when applicable call Analyze and
check buffer contents (use existing symbols NewFromBytes, New, Analyze, and
types.ValidationReport). Replace the individual TestNewFromBytes_* functions
with this single table-driven test to cover valid/invalid YAML, invalid
version/regex, HTML output, reporting mode, and parity with New, using subtests
t.Run for each case.

In `@pkg/rules/engine.go`:
- Around line 3-13: Reorder the import block so standard library packages (fmt,
os, path/filepath, regexp, strings) come first, then external dependencies like
gopkg.in/yaml.v3, and finally internal packages such as
github.com/openshift-kni/rds-analyzer/pkg/types; update the import grouping in
the import declaration in pkg/rules/engine.go accordingly so gopkg.in/yaml.v3
appears before the internal types import.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 85375ee4-275c-4038-b42a-e40ea4461dec

📥 Commits

Reviewing files that changed from the base of the PR and between 6e3b131 and 4f7003e.

📒 Files selected for processing (19)
  • AGENTS.md
  • internal/cli/root.go
  • pkg/analyzer/analyzer.go
  • pkg/analyzer/analyzer_test.go
  • pkg/parser/diff.go
  • pkg/parser/diff_test.go
  • pkg/report/html.go
  • pkg/report/html_test.go
  • pkg/report/reporting.go
  • pkg/report/reporting_test.go
  • pkg/report/text.go
  • pkg/report/text_test.go
  • pkg/rules/engine.go
  • pkg/rules/engine_test.go
  • pkg/rules/regex_validation_error.go
  • pkg/rules/types.go
  • pkg/rules/version.go
  • pkg/rules/yaml_regex_validate.go
  • pkg/types/compare.go

Comment thread AGENTS.md Outdated
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
pkg/analyzer/analyzer_test.go (2)

314-332: Use a descriptive test variable name instead of a

The single-letter identifier makes the new subtests harder to scan. Rename to analyzer for clarity.

♻️ Proposed refactor
-			a, err := NewFromBytes(tt.rulesData, tt.version)
+			analyzer, err := NewFromBytes(tt.rulesData, tt.version)
 			if tt.wantErr {
 				if err == nil {
 					t.Fatal("expected error, got nil")
 				}
 				if tt.errContains != "" && !strings.Contains(err.Error(), tt.errContains) {
 					t.Errorf("expected error containing %q, got: %v", tt.errContains, err)
 				}
 				return
 			}
 			if err != nil {
 				t.Fatalf("unexpected error: %v", err)
 			}
-			if a == nil {
+			if analyzer == nil {
 				t.Fatal("expected analyzer, got nil")
 			}
-			if tt.wantVersion != "" && a.GetTargetVersion() != tt.wantVersion {
-				t.Errorf("expected version %s, got %s", tt.wantVersion, a.GetTargetVersion())
+			if tt.wantVersion != "" && analyzer.GetTargetVersion() != tt.wantVersion {
+				t.Errorf("expected version %s, got %s", tt.wantVersion, analyzer.GetTargetVersion())
 			}
-			a, err := NewFromBytes([]byte(testRulesYAML), "")
+			analyzer, err := NewFromBytes([]byte(testRulesYAML), "")
 			if err != nil {
 				t.Fatalf("Failed to create analyzer: %v", err)
 			}
@@
-			if err := a.Analyze(&buf, report, tt.format, tt.mode); err != nil {
+			if err := analyzer.Analyze(&buf, report, tt.format, tt.mode); err != nil {
 				t.Fatalf("Analyze failed: %v", err)
 			}

As per coding guidelines, "**/*.go: Use meaningful variable names; avoid single letters except for loops`."

Also applies to: 408-427

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/analyzer/analyzer_test.go` around lines 314 - 332, Rename the
single-letter test variable "a" to a descriptive name "analyzer" where
NewFromBytes(tt.rulesData, tt.version) is called and subsequently used
(references include err check, nil check, and calling GetTargetVersion()), and
apply the same rename to the other test block mentioned (the occurrences around
lines 408-427) so subtests read clearly and adhere to the naming guideline.

261-261: Align test names to explicit scenario style

Consider renaming TestNewFromBytes and TestNewFromBytes_Analyze to scenario-explicit forms (for example, TestNewFromBytes_TableCases and TestNewFromBytes_AnalyzeModes) for easier test intent discovery.

As per coding guidelines, "**/*_test.go: Name test functions TestFunctionName_Scenario`."

Also applies to: 377-377

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/analyzer/analyzer_test.go` at line 261, Rename the vague test functions
to explicit scenario-style names: change TestNewFromBytes to
TestNewFromBytes_TableCases and change TestNewFromBytes_Analyze to
TestNewFromBytes_AnalyzeModes (or other descriptive suffixes per the guideline),
then update any references to these function names (calls, t.Run subtests, or
test lists) and adjust comments to match; ensure the new names are exported as
Test* and run `go test` to confirm no references remain.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@pkg/analyzer/analyzer_test.go`:
- Around line 314-332: Rename the single-letter test variable "a" to a
descriptive name "analyzer" where NewFromBytes(tt.rulesData, tt.version) is
called and subsequently used (references include err check, nil check, and
calling GetTargetVersion()), and apply the same rename to the other test block
mentioned (the occurrences around lines 408-427) so subtests read clearly and
adhere to the naming guideline.
- Line 261: Rename the vague test functions to explicit scenario-style names:
change TestNewFromBytes to TestNewFromBytes_TableCases and change
TestNewFromBytes_Analyze to TestNewFromBytes_AnalyzeModes (or other descriptive
suffixes per the guideline), then update any references to these function names
(calls, t.Run subtests, or test lists) and adjust comments to match; ensure the
new names are exported as Test* and run `go test` to confirm no references
remain.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 901927d6-a82e-4315-98d2-847f6d4833cb

📥 Commits

Reviewing files that changed from the base of the PR and between 4f7003e and a0e5809.

📒 Files selected for processing (3)
  • AGENTS.md
  • pkg/analyzer/analyzer_test.go
  • pkg/rules/engine.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/rules/engine.go

Co-authored-by: Claude <noreply@anthropic.com>
Signed-off-by: Mario Vazquez <mavazque@redhat.com>
@mvazquezc mvazquezc force-pushed the prepare-mcp-integration branch from a0e5809 to d3aac28 Compare April 20, 2026 12:25
@openshift-kni openshift-kni deleted a comment from coderabbitai Bot Apr 20, 2026
Signed-off-by: Mario Vazquez <mavazque@redhat.com>
@mvazquezc mvazquezc merged commit 0d7ab1b into openshift-kni:main Apr 20, 2026
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant