Skip to content

Conversation

dymurray
Copy link
Contributor

@dymurray dymurray commented Oct 10, 2025

Fixes #565

Summary by CodeRabbit

  • Bug Fixes

    • Corrected label listing in containerless (local) runs so list-sources and list-targets return accurate results without invoking container-dependent steps; container-based behavior unchanged.
  • Performance

    • Faster, more direct label listing in local runs, reducing errors and latency.
  • Tests

    • Expanded test coverage for local listing and output formatting to improve reliability.

Copy link

coderabbitai bot commented Oct 10, 2025

Walkthrough

Adds runLocal-aware branching to label listing in kantra analyze: when listing sources/targets with override-provider-settings unset, the command now calls listLabelsContainerless(ctx) and returns in containerless mode; otherwise it calls the existing ListLabels(cmd.Context()). Also adds extensive tests for containerless label listing and formatting.

Changes

Cohort / File(s) Summary
Analyze CLI: containerless-aware label listing
cmd/analyze.go
Adds a runLocal conditional when handling --list-sources/--list-targets: calls listLabelsContainerless(ctx) and returns in containerless mode; retains ListLabels(cmd.Context()) in container mode.
Tests: containerless label listing & formatting
cmd/analyze-bin_test.go
Adds extensive tests covering containerless label fetching/formatting: valid rules, mixed labels, no-match, empty rule dir, missing dirs errors, multiple command variants (list targets/sources, run-local toggles), output header/line/sort checks, and helpers/setup scaffolding.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant CLI as kantra analyze
  participant Analyze as analyze.go
  participant Container as Container Label Lister
  participant Local as Containerless Label Lister

  User->>CLI: run --list-sources / --list-targets
  CLI->>Analyze: execute handler
  alt runLocal == true (containerless)
    Analyze->>Local: listLabelsContainerless(ctx)
    Local-->>Analyze: labels / error
    Analyze-->>CLI: output / return
  else runLocal == false (container)
    Analyze->>Container: ListLabels(cmd.Context())
    Container-->>Analyze: labels / error
    Analyze-->>CLI: output / return
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • jmle
  • eemcmullan
  • aufi

Poem

Thump-thump in my coding lair,
I hop where flags tell me to care.
Local burrow or container road,
I fetch the labels, lighten the load.
Carrot crumbs lead tests to show—hooray! 🥕

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Title Check ⚠️ Warning The title includes an emoji and additional phrasing that is not strictly necessary, and it does not follow the guideline to avoid noise such as emojis; a concise summary without embellishment would improve clarity. Please remove the emoji and simplify the title to clearly state the change, for example “Use containerless listing for targets and sources when run-local is set.”
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues Check ✅ Passed The changes introduce a runLocal check for both list-targets and list-sources and call the containerless listing function when runLocal is true, addressing the core requirement of issue #565 to respect the --run-local flag.
Out of Scope Changes Check ✅ Passed All modifications are scoped to adding the runLocal branch in analyze.go and corresponding tests in analyze-bin_test.go for containerless listing, with no unrelated code changes outside these objectives.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

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

Copy link
Member

@aufi aufi left a comment

Choose a reason for hiding this comment

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

LGTM

@dymurray dymurray added the cherry-pick/release-0.8 This PR should be cherry-picked to release-0.8 branch label Oct 10, 2025
Copy link

codecov bot commented Oct 10, 2025

Codecov Report

❌ Patch coverage is 0% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 24.79%. Comparing base (ebfa7d2) to head (d511763).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
cmd/analyze.go 0.00% 8 Missing ⚠️

❌ Your patch status has failed because the patch coverage (0.00%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #566      +/-   ##
==========================================
+ Coverage   24.29%   24.79%   +0.50%     
==========================================
  Files          32       32              
  Lines        4779     4787       +8     
==========================================
+ Hits         1161     1187      +26     
+ Misses       3492     3471      -21     
- Partials      126      129       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Signed-off-by: Dylan <[email protected]>
Copy link

@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: 0

🧹 Nitpick comments (1)
cmd/analyze-bin_test.go (1)

557-673: LGTM: Integration tests verify runLocal behavior.

These tests properly verify that the containerless listing respects the --run-local flag and defaults to true, which aligns with the PR objectives to fix issue #565.

Optional: Extract flag parsing to reduce duplication.

The manual flag parsing logic at lines 632-643 and 750-761 is duplicated. Consider extracting it into a helper function:

func parseTestFlags(a *analyzeCommand, cmdArgs []string) {
    for _, arg := range cmdArgs {
        switch {
        case arg == "--list-targets":
            a.listTargets = true
        case arg == "--list-sources":
            a.listSources = true
        case arg == "--run-local=true":
            a.runLocal = true
        case arg == "--run-local=false":
            a.runLocal = false
        }
    }
}

Then call it from both test functions to improve maintainability.

Also applies to: 675-791

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bfa4840 and d511763.

📒 Files selected for processing (1)
  • cmd/analyze-bin_test.go (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
cmd/analyze-bin_test.go (1)
cmd/command-context.go (1)
  • AnalyzeCommandContext (21-38)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build & test from commit
🔇 Additional comments (5)
cmd/analyze-bin_test.go (5)

4-4: LGTM: Appropriate imports for new test functionality.

The context and strings packages are correctly imported and used throughout the new containerless label listing tests.

Also applies to: 7-7


385-555: LGTM: Comprehensive test coverage for containerless label listing.

This test thoroughly covers the core containerless label listing functionality with multiple scenarios:

  • Valid target and source labels
  • Mixed label types
  • Edge cases (no matches, empty directories)
  • Proper output format verification

The test structure is well-organized with proper setup, cleanup, and assertions.


793-873: LGTM: Thorough error handling verification.

The error handling tests properly cover critical failure scenarios:

  • Missing kantra directory
  • Missing rulesets directory
  • Empty rulesets directory (should succeed with no output)

Error message assertions ensure failures are reported correctly.


875-963: LGTM: Output format and sorting verification.

This test ensures the containerless listing produces properly formatted output with:

  • Correct header text
  • Expected line count
  • Alphabetically sorted technologies

The sorting verification at lines 956-959 correctly checks ascending order.


966-973: LGTM: Simple and correct helper function.

The sliceContains helper provides a clean way to check for flag presence in test arguments. The implementation is straightforward and correct.

@dymurray dymurray merged commit 4875da1 into konveyor:main Oct 10, 2025
5 of 6 checks passed
github-actions bot pushed a commit that referenced this pull request Oct 10, 2025
* 🐛 Use containerless list-targets/sources by default

Signed-off-by: Dylan <[email protected]>

* Add tests

Signed-off-by: Dylan <[email protected]>

---------

Signed-off-by: Dylan <[email protected]>
Signed-off-by: Cherry Picker <[email protected]>
dymurray added a commit that referenced this pull request Oct 10, 2025
* 🐛 Use containerless list-targets/sources by default



* Add tests



---------

Signed-off-by: Dylan <[email protected]>
Signed-off-by: Cherry Picker <[email protected]>
Co-authored-by: Dylan Murray <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cherry-pick/release-0.8 This PR should be cherry-picked to release-0.8 branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] --list-targets flag always uses container mode

3 participants