Skip to content

test: Add test for merge catalog sources#999

Merged
fege merged 6 commits intoopendatahub-io:mainfrom
fege:merge_sources
Jan 12, 2026
Merged

test: Add test for merge catalog sources#999
fege merged 6 commits intoopendatahub-io:mainfrom
fege:merge_sources

Conversation

@fege
Copy link
Copy Markdown
Contributor

@fege fege commented Jan 9, 2026

Description

How Has This Been Tested?

Merge criteria:

  • The commits are squashed in a cohesive manner and have meaningful messages.
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has manually tested the changes and verified that the changes work

Summary by CodeRabbit

  • Tests
    • Enhanced test coverage for catalog configuration and merging scenarios with improved test infrastructure.

✏️ Tip: You can customize this high-level summary in your review settings.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Jan 9, 2026

The following are automatically added/executed:

  • PR size label.
  • Run pre-commit
  • Run tox
  • Add PR author as the PR assignee
  • Build image based on the PR

Available user actions:

  • To mark a PR as WIP, add /wip in a comment. To remove it from the PR comment /wip cancel to the PR.
  • To block merging of a PR, add /hold in a comment. To un-block merging of PR comment /hold cancel.
  • To mark a PR as approved, add /lgtm in a comment. To remove, add /lgtm cancel.
    lgtm label removed on each new commit push.
  • To mark PR as verified comment /verified to the PR, to un-verify comment /verified cancel to the PR.
    verified label removed on each new commit push.
  • To Cherry-pick a merged PR /cherry-pick <target_branch_name> to the PR. If <target_branch_name> is valid,
    and the current PR is merged, a cherry-picked PR would be created and linked to the current PR.
  • To build and push image to quay, add /build-push-pr-image in a comment. This would create an image with tag
    pr-<pr_number> to quay repository. This image tag, however would be deleted on PR merge or close action.
Supported labels

{'/verified', '/wip', '/hold', '/lgtm', '/build-push-pr-image', '/cherry-pick'}

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jan 9, 2026

📝 Walkthrough

Walkthrough

The PR introduces a data-driven test for catalog source merge validation with sparse overrides, adds a reusable fixture to apply temporary field overrides via ConfigMap modifications, removes the obsolete disabled_catalog_source fixture, and migrates two existing tests to use the new fixture pattern.

Changes

Cohort / File(s) Summary
New Test Module
tests/model_registry/model_catalog/catalog_config/test_catalog_source_merge.py
Adds TestCatalogSourceMerge class with parameterized test covering sparse overrides for name, labels, and enabled fields; validates API response reflects specified overrides while preserving non-overridden field values (+78 lines)
Fixture Enhancement
tests/model_registry/model_catalog/conftest.py
Introduces sparse_override_catalog_source fixture that extracts override parameters from request.param, fetches current catalog state, constructs sparse YAML ConfigMap update, and yields override details for test consumption; includes post-override readiness verification (+59 lines)
Fixture Removal
tests/model_registry/model_catalog/metadata/conftest.py
Removes disabled_catalog_source fixture, consolidating catalog override functionality into the new generalized sparse_override_catalog_source pattern (-52 lines)
Test Migration
tests/model_registry/model_catalog/metadata/test_sources_endpoint.py
Migrates test_disabled_source_status and test_sources_endpoint_returns_all_sources_regardless_of_enabled_field from disabled_catalog_source to sparse_override_catalog_source; adds REDHAT_AI_CATALOG_ID import; updates variable references to access catalog_id from fixture dict (+12/-11 lines)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately reflects the primary change: adding a test for merging catalog sources, which is the main objective demonstrated by the new test module test_catalog_source_merge.py.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing touches
  • 📝 Generate docstrings

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
Copy Markdown
Contributor

@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)
tests/model_registry/model_catalog/catalog_config/test_catalog_source_merge.py (1)

24-24: Minor formatting: add space after colon in ticket reference.

The JIRA ticket reference should have a space after the colon for consistency.

✨ Suggested fix
-        RHOAIENG-41738:Test that a sparse override in custom ConfigMap successfully overrides
+        RHOAIENG-41738: Test that a sparse override in custom ConfigMap successfully overrides
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4592fa9 and 31072c5.

📒 Files selected for processing (2)
  • tests/model_registry/model_catalog/catalog_config/conftest.py
  • tests/model_registry/model_catalog/catalog_config/test_catalog_source_merge.py
🧰 Additional context used
🧬 Code graph analysis (1)
tests/model_registry/model_catalog/catalog_config/test_catalog_source_merge.py (4)
tests/model_registry/utils.py (1)
  • execute_get_command (730-738)
tests/model_registry/model_catalog/catalog_config/conftest.py (1)
  • sparse_override_catalog_source (20-77)
tests/model_registry/model_catalog/conftest.py (1)
  • model_catalog_rest_url (405-414)
tests/model_registry/conftest.py (1)
  • model_registry_rest_headers (399-400)
🔇 Additional comments (9)
tests/model_registry/model_catalog/catalog_config/test_catalog_source_merge.py (4)

1-9: LGTM!

Imports and module-level fixture markers are correctly configured.


31-43: LGTM!

Fixture data extraction and API query logic are correct. The merged catalog lookup includes a clear assertion message.


46-72: LGTM!

The validation logic correctly distinguishes between overridden fields (name, labels) and preserved fields, accumulating detailed error messages for comprehensive test feedback.


74-78: LGTM!

Summary logging provides clear visibility into which fields were overridden versus preserved, aiding in test debugging and validation.

tests/model_registry/model_catalog/catalog_config/conftest.py (5)

1-17: LGTM!

All required imports are present and properly organized.


19-31: LGTM!

Function scope is appropriate for this fixture since it modifies ConfigMap state, ensuring proper test isolation.


33-39: LGTM!

Capturing the original catalog state before applying the override is essential for validating that unspecified fields are correctly preserved during the merge.


41-56: LGTM!

The sparse YAML override is well-crafted to test merge behavior. Including only id, name, and labels ensures that other fields must be inherited from the default ConfigMap.


58-77: LGTM!

Excellent use of ResourceEditor context manager for automatic cleanup and proper wait operations to ensure API stability before and after the test. This pattern prevents race conditions and ensures test isolation.

Copy link
Copy Markdown
Contributor

@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)
tests/model_registry/model_catalog/catalog_config/test_catalog_source_merge.py (1)

74-78: Consider edge case: what if original_catalog has unexpected fields?

The log message assumes len(original_catalog) - 1 preserved fields, but if the API response (merged_catalog) contains additional fields not present in original_catalog, they won't be validated. This is likely acceptable for this test's scope, but worth noting if the API schema could evolve.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f64bd53 and 6db6659.

📒 Files selected for processing (2)
  • tests/model_registry/model_catalog/catalog_config/conftest.py
  • tests/model_registry/model_catalog/catalog_config/test_catalog_source_merge.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/model_registry/model_catalog/catalog_config/conftest.py
🔇 Additional comments (5)
tests/model_registry/model_catalog/catalog_config/test_catalog_source_merge.py (5)

1-9: LGTM!

The imports, logger setup, and module-level pytest markers are appropriate for this test module.


18-26: Good parametrization approach for data-driven testing.

The use of indirect=True correctly delegates parameter handling to the sparse_override_catalog_source fixture. The test covers multiple field types (string, list, boolean) which is good for testing merge behavior across different data types.


42-49: Test query and lookup logic is well-structured.

The approach of querying the sources endpoint, finding the specific catalog by ID, and asserting its presence is correct. Using next() with a None default followed by an explicit assertion provides a clear error message when the catalog is missing.


56-72: Good handling of field preservation validation with special case for enabled.

The logic correctly:

  1. Excludes the overridden field from preservation checks.
  2. Handles the enabled=False special case where status automatically becomes "disabled".
  3. Iterates over remaining fields to verify they retain original values.

Using is False on line 60 is the correct strict boolean comparison.


30-31: The fixture model_catalog_rest_url includes assertions that guarantee the returned list is never empty, making the [0] access at line 43 safe. The type hint list[str] is appropriate for representing multiple catalog API URLs across routes.

dbasunag
dbasunag previously approved these changes Jan 12, 2026
Copy link
Copy Markdown
Contributor

@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)
tests/model_registry/model_catalog/metadata/test_sources_endpoint.py (1)

80-113: Fix false-positive risk + address Ruff ARG002 by asserting the specific catalog is disabled.
Currently this can pass if any source is disabled (even if REDHAT_AI_CATALOG_ID wasn’t actually disabled).

Proposed diff
 def test_sources_endpoint_returns_all_sources_regardless_of_enabled_field(
     self,
     sparse_override_catalog_source: dict,
     model_catalog_rest_url: list[str],
     model_registry_rest_headers: dict[str, str],
 ):
@@
     response = execute_get_command(url=f"{model_catalog_rest_url[0]}sources", headers=model_registry_rest_headers)
     items = response.get("items", [])
 
     assert len(items) > 1, "Expected multiple sources to be returned"
 
+    catalog_id = sparse_override_catalog_source["catalog_id"]
+    target = next((item for item in items if item.get("id") == catalog_id), None)
+    assert target is not None, f"Expected catalog '{catalog_id}' to be present in sources response"
+    validate_source_status(catalog=target, expected_status="disabled")
+
     # Verify we have at least one enabled source
     enabled_sources = [item for item in items if item.get("status") == "available"]
     assert enabled_sources, "Expected at least one enabled source"
 
     # Verify we have at least one disabled source
     disabled_sources = [item for item in items if item.get("status") == "disabled"]
     assert disabled_sources, "Expected at least one disabled source"
🤖 Fix all issues with AI agents
In @tests/model_registry/model_catalog/conftest.py:
- Around line 65-98: The fixture currently restarts pods and waits for the API
but does not confirm the sparse ConfigMap override was reconciled; update the
code after writing the ConfigMap inside the ResourceEditor so that, before
yielding, you poll the /sources API (using execute_get_command with
model_catalog_rest_url[0] and model_registry_rest_headers) until you find the
item with id == catalog_id and that item's field_name equals field_value (use
the same TimeoutSampler pattern used in other tests like
test_labels_endpoint.py/test_default_model_catalog.py); keep existing calls to
is_model_catalog_ready and wait_for_model_catalog_api but add this
TimeoutSampler-based assertion referencing catalog_id, field_name, and
field_value to ensure the override is visible in the API before yield.
🧹 Nitpick comments (1)
tests/model_registry/model_catalog/conftest.py (1)

41-64: Harden fixture parameter validation (avoid noisy KeyError / IndexError).
Right now missing keys (or empty model_catalog_rest_url) will fail with less actionable errors.

Proposed diff
 @pytest.fixture()
 def sparse_override_catalog_source(
     request: pytest.FixtureRequest,
     admin_client,
     model_registry_namespace: str,
     model_catalog_rest_url: list[str],
     model_registry_rest_headers: dict[str, str],
 ) -> Generator[dict, None, None]:
@@
     # Get fields from pytest param
     param = getattr(request, "param", None)
-    assert param, "sparse_override_catalog_source requires request.param dict"
+    if not isinstance(param, dict):
+        raise pytest.UsageError("sparse_override_catalog_source requires request.param dict")
+    missing = {"id", "field_name", "field_value"} - set(param)
+    if missing:
+        raise pytest.UsageError(f"sparse_override_catalog_source missing request.param keys: {sorted(missing)}")
+    assert model_catalog_rest_url, "model_catalog_rest_url is empty"
+    base_url = model_catalog_rest_url[0]
 
-    catalog_id = param["id"]
-    field_name = param["field_name"]
-    field_value = param["field_value"]
+    catalog_id = param["id"]
+    field_name = param["field_name"]
+    field_value = param["field_value"]
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6db6659 and 1e82ba3.

📒 Files selected for processing (3)
  • tests/model_registry/model_catalog/conftest.py
  • tests/model_registry/model_catalog/metadata/conftest.py
  • tests/model_registry/model_catalog/metadata/test_sources_endpoint.py
💤 Files with no reviewable changes (1)
  • tests/model_registry/model_catalog/metadata/conftest.py
🧰 Additional context used
🧬 Code graph analysis (1)
tests/model_registry/model_catalog/metadata/test_sources_endpoint.py (1)
tests/model_registry/model_catalog/conftest.py (1)
  • sparse_override_catalog_source (42-97)
🪛 Ruff (0.14.10)
tests/model_registry/model_catalog/metadata/test_sources_endpoint.py

88-88: Unused method argument: sparse_override_catalog_source

(ARG002)

🔇 Additional comments (1)
tests/model_registry/model_catalog/metadata/test_sources_endpoint.py (1)

40-78: Good migration to sparse override fixture + targeted disabled-source validation.
The test now validates the specific catalog by id (vs relying on global state).

@fege fege enabled auto-merge (squash) January 12, 2026 16:38
@fege fege merged commit 40e2274 into opendatahub-io:main Jan 12, 2026
13 checks passed
@fege fege deleted the merge_sources branch January 12, 2026 16:42
@github-actions
Copy link
Copy Markdown

Status of building tag latest: success.
Status of pushing tag latest to image registry: success.

mwaykole pushed a commit to mwaykole/opendatahub-tests that referenced this pull request Jan 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants