Skip to content

Conversation

@jeremylenz
Copy link
Collaborator

@jeremylenz jeremylenz commented Jan 19, 2026

Summary

  • Modified Queries.for_slice to skip the host_registration_insights_inventory parameter filter when operating in IoP mode
  • In IoP mode, all subscribed hosts should be included in inventory reports regardless of the opt-out parameter
  • The parameter is designed for cloud mode uploads; IoP mode requires single-host reports for the Vulnerability service

Test plan

  • Updated existing test to clarify cloud mode behavior with IoP stub
  • Added test for IoP mode behavior (hosts with parameter=false are included)
  • Added integration test for mode switching (cloud excludes, IoP includes)
  • All 394 tests pass with 0 failures

🤖 Generated with Claude Code

Summary by Sourcery

Adjust inventory query behavior to treat host opt-out parameters differently depending on cloud vs IoP mode.

Bug Fixes:

  • Ensure IoP mode inventory uploads include all subscribed hosts regardless of the host_registration_insights_inventory opt-out parameter.

Tests:

  • Extend unit tests to cover cloud vs IoP behavior for the host_registration_insights_inventory parameter and mode switching.

In IoP mode, the host_registration_insights_inventory parameter should be
ignored because single-host reports are required for the IoP Vulnerability
service. The parameter is designed for cloud mode to allow users to opt-out
of inventory uploads, but in IoP mode all subscribed hosts should be included.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
@sourcery-ai
Copy link

sourcery-ai bot commented Jan 19, 2026

Reviewer's Guide

Adjusts inventory upload query behavior so that the host_registration_insights_inventory opt-out parameter is only applied in cloud mode, not in IoP mode, and extends tests to cover both modes and mode switching behavior.

Sequence diagram for query generation behavior in cloud vs IoP modes

sequenceDiagram
    participant Caller
    participant Queries
    participant ForemanRhCloud
    participant InsightsCloud
    participant BaseQuery

    Caller->>Queries: for_slice(base)
    activate Queries
    Queries->>BaseQuery: assign_to_local_query(base)

    Queries->>ForemanRhCloud: with_iop_smart_proxy?
    alt IoP_mode
        ForemanRhCloud-->>Queries: true
        Note right of Queries: Skip host_registration_insights_inventory filter
    else Cloud_mode
        ForemanRhCloud-->>Queries: false
        Queries->>InsightsCloud: enable_client_param_inventory
        InsightsCloud-->>Queries: param_name
        Queries->>BaseQuery: search_for(not_params_param_false_filter)
        BaseQuery-->>Queries: filtered_query
    end

    Queries->>BaseQuery: joins(subscription_facet)
    Queries->>BaseQuery: preload(interfaces, hostgroup, facts)
    BaseQuery-->>Queries: final_query
    Queries-->>Caller: final_query
    deactivate Queries
Loading

Updated class diagram for query generation and mode handling

classDiagram
    class Queries {
        +for_slice(base)
        +fact_names()
    }

    class ForemanRhCloud {
        +with_iop_smart_proxy?()
    }

    class InsightsCloud {
        +enable_client_param_inventory
    }

    class BaseQuery {
        +search_for(filter)
        +joins(association)
        +preload(associations)
    }

    Queries --> ForemanRhCloud : uses
    Queries --> InsightsCloud : uses
    Queries --> BaseQuery : extends_or_uses_base_query_behavior
Loading

File-Level Changes

Change Details Files
Conditionally apply the host_registration_insights_inventory opt-out filter based on IoP vs cloud mode in the inventory upload queries.
  • Refactored for_slice to build the query in a local variable before chaining additional scopes.
  • Added a ForemanRhCloud.with_iop_smart_proxy? guard so the host_registration_insights_inventory parameter filter is skipped in IoP mode.
  • Kept the existing parameter-based exclusion logic for non-IoP (cloud) mode and preserved the subsequent joins and preloads.
lib/foreman_inventory_upload/generators/queries.rb
Clarify and extend tests to validate different behaviors in cloud and IoP modes and when switching between them.
  • Renamed the existing exclusion test to explicitly state it covers cloud mode behavior.
  • Stubbed ForemanRhCloud.with_iop_smart_proxy? to false in the cloud mode test to make the mode explicit.
  • Added a new IoP mode test asserting that hosts with host_registration_insights_inventory=false are still included.
  • Added a mode-switching test that first asserts exclusion in cloud mode and then inclusion in IoP mode for the same host parameter setup.
test/unit/slice_generator_test.rb

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • The tests that stub ForemanRhCloud.with_iop_smart_proxy? would be more robust if they explicitly restore the original behavior in teardown/ensure, to avoid accidental leakage of the stub into other tests.
  • In Queries.for_slice, consider extracting the mode check (ForemanRhCloud.with_iop_smart_proxy?) behind a small helper or collaborator to keep the query builder focused purely on query construction and make future mode logic changes easier to localize.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The tests that stub `ForemanRhCloud.with_iop_smart_proxy?` would be more robust if they explicitly restore the original behavior in teardown/ensure, to avoid accidental leakage of the stub into other tests.
- In `Queries.for_slice`, consider extracting the mode check (`ForemanRhCloud.with_iop_smart_proxy?`) behind a small helper or collaborator to keep the query builder focused purely on query construction and make future mode logic changes easier to localize.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

- Add explicit teardown to restore stubs in all test files that stub
  ForemanRhCloud.with_iop_smart_proxy? to prevent stub leakage into
  other tests
- Extract mode check from Queries.for_slice to a helper method
  skip_inventory_parameter_filter? to improve maintainability and
  localize future mode logic changes

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
@chris1984 chris1984 self-assigned this Jan 22, 2026
@chris1984
Copy link
Member

Starting to review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants