Skip to content

Fixes for upstream-pr option - #20817

Merged
tpapaioa merged 1 commit into
SatelliteQE:masterfrom
tpapaioa:upstream_pr_fixes
Mar 20, 2026
Merged

Fixes for upstream-pr option#20817
tpapaioa merged 1 commit into
SatelliteQE:masterfrom
tpapaioa:upstream_pr_fixes

Conversation

@tpapaioa

@tpapaioa tpapaioa commented Feb 18, 2026

Copy link
Copy Markdown
Contributor

Problem Statement

  • Tests not collected when using the --upstream-pr option
  • Case-sensitivity in filename-to-component mapping makes it harder to set up and use

Solution

  • Make upstream pull request filename matching case-insensitive
  • Use lowercase when matching components to tests

Related Issues

SAT-24770

PRT test Cases example

trigger: test-robottelo
pytest: pytest tests/foreman/api/ --upstream-pr foreman/{PR_ID}
env:
  ROBOTTELO_GITHUB_REPOS__FOREMAN__RULES: '@json [{"path":"host", "component":"Hosts"},{"path":"setting","component":"Settings"}]'

Summary by Sourcery

Make upstream pull request file matching case-insensitive and normalize matched components to lowercase.

Bug Fixes:

  • Ensure upstream PR file path matching is case-insensitive to correctly apply rules regardless of filename casing.

Enhancements:

  • Normalize matched rule components to lowercase for consistent component handling in upstream PR processing.

Summary by Sourcery

Ensure upstream pull request rules match file paths case-insensitively and normalize matched components for consistent test selection.

Bug Fixes:

  • Make upstream pull request file path matching case-insensitive so rules apply regardless of filename casing.

Enhancements:

  • Normalize matched rule components to lowercase to ensure consistent component identification during test collection.

@tpapaioa tpapaioa self-assigned this Feb 18, 2026
@tpapaioa tpapaioa added No-CherryPick PR doesnt need CherryPick to previous branches Do Not Merge labels Feb 18, 2026
@sourcery-ai

sourcery-ai Bot commented Feb 18, 2026

Copy link
Copy Markdown
Contributor
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Makes upstream PR filename-to-rule matching case-insensitive and normalizes matched rule components to lowercase so tests are correctly collected when using the --upstream-pr option.

Sequence diagram for pytest collection with upstream-pr case-insensitive matching

sequenceDiagram
    actor Developer
    participant Pytest as PytestRunner
    participant UpstreamPR as UpstreamPROptionHandler
    participant RuleSet as RuleSet
    participant Matcher as match_file_to_rule
    participant Components as ComponentSet

    Developer->>Pytest: run pytest --upstream-pr foreman/PR_ID
    Pytest->>UpstreamPR: parse --upstream-pr option
    UpstreamPR->>RuleSet: load rules from ROBOTTELO_GITHUB_REPOS__FOREMAN__RULES
    Pytest->>UpstreamPR: pytest_collection_modifyitems(session, items, config)

    loop for each filename in upstream PR
        UpstreamPR->>RuleSet: iterate over rules
        loop for each rule
            UpstreamPR->>Matcher: match_file_to_rule(filename, rule)
            Matcher->>Matcher: re.search(rule.path, filename, IGNORECASE)
            Matcher-->>UpstreamPR: True or False
            alt filename matches rule
                UpstreamPR->>Components: components.add(rule.component.lower())
                UpstreamPR->>UpstreamPR: mark filename as processed
            end
        end
    end

    UpstreamPR-->>Pytest: components associated with items
    Pytest-->>Developer: collected tests filtered by components
Loading

Class diagram for upstream_pr matching and collection helpers

classDiagram
    class Rule {
        +str path
        +str component
    }

    class UpstreamPROptionHandler {
        +pytest_collection_modifyitems(session, items, config)
        -set components
        -set unprocessed_filenames
        -set matched_filenames
    }

    class Matcher {
        +match_file_to_rule(filename, rule) bool
    }

    class ComponentSet {
        +add(component)
        +__contains__(component) bool
    }

    UpstreamPROptionHandler --> Rule : uses
    UpstreamPROptionHandler --> Matcher : calls
    UpstreamPROptionHandler --> ComponentSet : stores components
    Matcher --> Rule : reads path and component
Loading

File-Level Changes

Change Details Files
Make upstream PR rule path matching case-insensitive so rules apply regardless of filename casing.
  • Update file-to-rule regex search to use IGNORECASE flag when matching rule path patterns against filenames.
  • Preserve existing error handling for invalid regex patterns while extending matching behavior.
pytest_plugins/upstream_pr.py
Normalize matched rule components to lowercase when building the component set used for test selection.
  • Convert rule.component to lowercase before adding it to the components set when filenames match a rule.
  • Ensure unprocessed filenames are still pruned after matching while using normalized components for selection and logging.
pytest_plugins/upstream_pr.py

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

@tpapaioa
tpapaioa force-pushed the upstream_pr_fixes branch from d12cc51 to e381bad Compare March 16, 2026 13:07
@tpapaioa tpapaioa added Stream Introduced in or relating directly to Satellite Stream/Master and removed Do Not Merge labels Mar 16, 2026
@tpapaioa
tpapaioa marked this pull request as ready for review March 16, 2026 13:33
@tpapaioa
tpapaioa requested a review from a team as a code owner March 16, 2026 13:33

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

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:

  • Consider normalizing rule.component to lowercase at rule creation/parsing time instead of during collection so the component casing is consistent throughout the codebase and you avoid repeated .lower() calls in the hot path.
  • You might want to move the re.IGNORECASE flag into wherever the regex/pattern is first constructed (e.g., precompiling the pattern with the desired flags) to avoid passing flags on every re.search call and to keep matching behavior defined in a single place.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider normalizing `rule.component` to lowercase at rule creation/parsing time instead of during collection so the component casing is consistent throughout the codebase and you avoid repeated `.lower()` calls in the hot path.
- You might want to move the `re.IGNORECASE` flag into wherever the regex/pattern is first constructed (e.g., precompiling the pattern with the desired flags) to avoid passing flags on every `re.search` call and to keep matching behavior defined in a single place.

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.

@tpapaioa
tpapaioa force-pushed the upstream_pr_fixes branch from e381bad to 8db8209 Compare March 20, 2026 15:16
@tpapaioa
tpapaioa merged commit 80c7150 into SatelliteQE:master Mar 20, 2026
9 checks passed
@tpapaioa
tpapaioa deleted the upstream_pr_fixes branch March 20, 2026 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

No-CherryPick PR doesnt need CherryPick to previous branches Stream Introduced in or relating directly to Satellite Stream/Master

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant