Skip to content

Conversation

@ctron
Copy link
Contributor

@ctron ctron commented Mar 5, 2025

Summary by Sourcery

Add comprehensive tests for CycloneDX image index variant relationships and streamline UID handling in SBOM tests.

Enhancements:

  • Introduce split_uid helper to convert ingestion results into UID arrays and refactor tests to use it.

Tests:

  • Add cdx_imageindex_variant async test that ingests image index and variant SBOMs, loads graphs via AnalysisService, and asserts variant relationships using JSON subset matching.
  • Refactor existing cdx_prod_comp test to utilize split_uid for cleaner UID extraction.
  • Import serde_json::json, ContainsSubset, AnalysisService, ComponentReference, QueryOptions, and Paginated to support graph queries and JSON assertions in tests.

@ctron ctron requested a review from JimFuller-RedHat March 5, 2025 14:40
Copy link
Contributor

@JimFuller-RedHat JimFuller-RedHat left a comment

Choose a reason for hiding this comment

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

you might consider adding document_id to the test assert as that is the main (stable) indicator) when we transition to external document in the returned REST API results, otherwise LGTM

@helio-frota
Copy link
Contributor

@sourcery-ai review

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jul 10, 2025

Reviewer's Guide

This PR refactors UID handling in cyclonedx external tests by introducing a reusable split_uid helper, updates the existing product-component test to use it, enriches imports for analysis queries and JSON assertions, and adds a comprehensive image-index-variant test leveraging AnalysisService and serde_json subset assertions.

File-Level Changes

Change Details Files
Introduce and apply split_uid helper for UID extraction
  • Import IngestResult and Uuid in mod.rs
  • Define generic split_uid fn with doc comment
  • Import and use split_uid in rh.rs
  • Replace manual pop/try_as_uid logic with split_uid destructure
modules/fundamental/tests/sbom/cyclonedx/external/mod.rs
modules/fundamental/tests/sbom/cyclonedx/external/rh.rs
Add new cdx_imageindex_variant integration test
  • Ingest multiple SBOM documents for index and variants
  • Destructure UIDs via split_uid
  • Initialize AnalysisService and load graphs
  • Retrieve component graph with descendants via retrieve_single
  • Convert result to JSON and assert subset of expected structure
modules/fundamental/tests/sbom/cyclonedx/external/rh.rs
Extend imports to support analysis queries and JSON assertions
  • Add serde_json::json and Paginated import
  • Import AnalysisConfig, AnalysisService, ComponentReference, QueryOptions
  • Bring in ContainsSubset for JSON subset testing
modules/fundamental/tests/sbom/cyclonedx/external/rh.rs

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
Contributor

@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 @ctron - I've reviewed your changes - here's some feedback:

  • Remove the debug println!("{json:#?}") from the test to avoid cluttering CI logs.
  • Add an explicit assertion on result.len() before calling split_uid so failures in item count yield clearer errors than a panic.
  • The deeply nested JSON contains_subset assertion is brittle—consider extracting the expected structure into a constant or using more focused assertions on key fields for clarity and maintainability.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Remove the debug `println!("{json:#?}")` from the test to avoid cluttering CI logs.
- Add an explicit assertion on `result.len()` before calling `split_uid` so failures in item count yield clearer errors than a panic.
- The deeply nested JSON `contains_subset` assertion is brittle—consider extracting the expected structure into a constant or using more focused assertions on key fields for clarity and maintainability.

## Individual Comments

### Comment 1
<location> `modules/fundamental/tests/sbom/cyclonedx/external/rh.rs:67` </location>
<code_context>
+
+    let json = serde_json::to_value(comp_index.items)?;
+
+    println!("{json:#?}");
+
+    assert!(json.contains_subset(json!([
</code_context>

<issue_to_address>
Consider removing or gating debug print statements in tests.

`println!` can clutter CI logs. Remove it or guard with a feature flag or environment variable if only needed for local debugging.
</issue_to_address>

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.

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.

3 participants