Skip to content

Add negative test for allowedOrganization#1004

Merged
dbasunag merged 5 commits intoopendatahub-io:mainfrom
dbasunag:HF_neg
Jan 13, 2026
Merged

Add negative test for allowedOrganization#1004
dbasunag merged 5 commits intoopendatahub-io:mainfrom
dbasunag:HF_neg

Conversation

@dbasunag
Copy link
Copy Markdown
Collaborator

@dbasunag dbasunag 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

    • Added focused negative test coverage for Hugging Face catalog configurations, covering various invalid patterns and messages.
    • Renamed and reorganized existing negative tests to use a standardized helper for consistent error-state verification.
    • Introduced a new helper to assert source error states and expected messages.
  • Chores

    • Added an additional model catalog API readiness check during test teardown.

✏️ 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

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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jan 9, 2026

📝 Walkthrough

Walkthrough

Consolidates source error assertions into a new helper, moves Hugging Face negative cases into a new test module, renames a default catalog test, and adds a post-teardown Model Catalog API readiness wait in the catalog config fixture.

Changes

Cohort / File(s) Summary
Catalog negative tests (refactor)
tests/model_registry/model_catalog/catalog_config/test_model_catalog_negative.py
Removed many HF-specific negative cases; renamed test_source_error_statetest_default_source_error_state; updated parameterization and replaced direct REST calls with the new helper assert_source_error_state_message.
New Hugging Face negative tests
tests/model_registry/model_catalog/huggingface/test_huggingface_negative.py
Added TestHuggingFaceNegative module with parameterized invalid HF catalog configurations that call assert_source_error_state_message (uses source_id "error_catalog") to verify error-state messages.
Test utilities (helper added)
tests/model_registry/model_catalog/utils.py
Added assert_source_error_state_message(model_catalog_rest_url, model_registry_rest_headers, expected_error_message, source_id) which GETs catalog sources, finds the source by id, asserts status == "error", and checks the expected message is contained in the source error field.
Fixture tweak (post-teardown readiness)
tests/model_registry/model_catalog/conftest.py
updated_catalog_config_map_scope_function now performs an additional wait_for_model_catalog_api call using model_registry_rest_headers after yielding (teardown) to ensure API readiness.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly aligns with the main change: adding negative test cases for allowedOrganization validation in Hugging Face catalog configurations.

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

✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent 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 04e4d3f and d258b2c.

📒 Files selected for processing (4)
  • tests/model_registry/model_catalog/catalog_config/test_model_catalog_negative.py
  • tests/model_registry/model_catalog/conftest.py
  • tests/model_registry/model_catalog/huggingface/test_huggingface_negative.py
  • tests/model_registry/model_catalog/utils.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/model_registry/model_catalog/utils.py
  • tests/model_registry/model_catalog/conftest.py
🧰 Additional context used
🧬 Code graph analysis (1)
tests/model_registry/model_catalog/huggingface/test_huggingface_negative.py (2)
tests/model_registry/model_catalog/utils.py (1)
  • assert_source_error_state_message (256-272)
tests/model_registry/model_catalog/conftest.py (2)
  • updated_catalog_config_map_scope_function (382-397)
  • model_catalog_rest_url (413-422)
🪛 Ruff (0.14.11)
tests/model_registry/model_catalog/catalog_config/test_model_catalog_negative.py

83-83: Unused method argument: updated_catalog_config_map_scope_function

(ARG002)

tests/model_registry/model_catalog/huggingface/test_huggingface_negative.py

123-123: Unused method argument: updated_catalog_config_map_scope_function

(ARG002)

🔇 Additional comments (3)
tests/model_registry/model_catalog/catalog_config/test_model_catalog_negative.py (1)

81-93: LGTM! Clean refactor to use centralized helper.

The migration to assert_source_error_state_message improves consistency across test modules. The rename to test_default_source_error_state adds clarity.

Regarding the static analysis hint (ARG002): updated_catalog_config_map_scope_function is intentionally unused in the function body—its presence triggers pytest's indirect parametrization, invoking the fixture's setup/teardown lifecycle. This is a standard pytest pattern.

tests/model_registry/model_catalog/huggingface/test_huggingface_negative.py (2)

1-15: LGTM! Well-structured test module setup.

The imports, logger setup, and pytest marks follow the established patterns in the codebase. The pytestmark correctly applies session-scoped fixtures.


18-133: Comprehensive negative test coverage for HuggingFace catalogs.

The parameterized test cases cover a good range of invalid configurations:

  • Missing includedModels
  • Various invalid wildcard patterns (*, */*, abc-random*, *RedHatAI*)
  • Empty model name (RedHatAI/)
  • Non-existent allowedOrganization

The consistent use of source_id="error_catalog" across all test cases and the centralized assert_source_error_state_message helper makes the tests maintainable.

The error message validation is performed at runtime via REST API calls to the actual backend service. The test will automatically fail if backend error messages change, providing robust protection against unintended API changes.

Regarding ARG002: Same as the other file—updated_catalog_config_map_scope_function triggers fixture setup via indirect parametrization.


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_model_catalog_negative.py (1)

159-173: Reduce test flakiness and brittle error matching

The test case uses allowedOrganization: "abc-random", which could become a real HuggingFace organization in the future, causing this negative test to unexpectedly pass. Additionally, since the assertion uses substring matching (in), you can safely match only the stable suffix ("no models found") instead of the full error message, making the test less sensitive to error message prefix changes.

Suggested improvements
             pytest.param(
                 """
 catalogs:
   - name: HuggingFace Hub
     id: error_catalog
     type: hf
     enabled: true
     properties:
-      allowedOrganization: "abc-random"
+      allowedOrganization: "this-org-should-not-exist-000000000000000000"
     includedModels:
     - '*'
 """,
-                "failed to expand model patterns: no models found",
+                "no models found",
                 id="test_hf_source_non_existent_allowed_organization",
             ),
📜 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 b6df07a and a65ffc8.

📒 Files selected for processing (1)
  • tests/model_registry/model_catalog/catalog_config/test_model_catalog_negative.py

Copy link
Copy Markdown
Contributor

@fege fege left a comment

Choose a reason for hiding this comment

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

move the HF test in the HF folder

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

🤖 Fix all issues with AI agents
In @tests/model_registry/model_catalog/huggingface/test_huggingface_negative.py:
- Around line 22-33: Remove the duplicate pytest.param entry with id
"test_source_error_invalid_path" from the HuggingFace negative test file (the
pytest.param that defines a YAML catalog with type: yaml and yamlCatalogPath:
non-existent-catalog.yaml); this case tests generic YAML catalog error handling
and is already covered in test_model_catalog_negative.py, so delete that
pytest.param from
tests/model_registry/model_catalog/huggingface/test_huggingface_negative.py
(inside the failing_cases/param list) so the file only contains
HuggingFace-specific negative tests.
🧹 Nitpick comments (2)
tests/model_registry/model_catalog/utils.py (2)

256-261: Add return type annotation for completeness.

The function is missing a return type annotation. For consistency with the codebase's type hints:

Suggested fix
 def assert_source_error_state_message(
     model_catalog_rest_url: list[str],
     model_registry_rest_headers: dict[str, str],
     expected_error_message: str,
     source_id: str,
-):
+) -> None:

262-268: Consider defensive handling for API response.

Direct access to ["items"] will raise a KeyError if the API returns an unexpected response format. Consider using .get("items", []) for more resilient behavior:

Suggested fix
     results = execute_get_command(
         url=f"{model_catalog_rest_url[0]}sources",
         headers=model_registry_rest_headers,
-    )["items"]
+    ).get("items", [])
+    assert results, "No items returned from sources API"
📜 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 a65ffc8 and 04e4d3f.

📒 Files selected for processing (4)
  • tests/model_registry/model_catalog/catalog_config/test_model_catalog_negative.py
  • tests/model_registry/model_catalog/conftest.py
  • tests/model_registry/model_catalog/huggingface/test_huggingface_negative.py
  • tests/model_registry/model_catalog/utils.py
🧰 Additional context used
🧬 Code graph analysis (3)
tests/model_registry/model_catalog/utils.py (3)
tests/model_registry/model_catalog/conftest.py (1)
  • model_catalog_rest_url (413-422)
tests/model_registry/conftest.py (1)
  • model_registry_rest_headers (399-400)
tests/model_registry/utils.py (1)
  • execute_get_command (730-738)
tests/model_registry/model_catalog/conftest.py (2)
tests/model_registry/utils.py (1)
  • wait_for_model_catalog_api (718-727)
tests/model_registry/conftest.py (1)
  • model_registry_rest_headers (399-400)
tests/model_registry/model_catalog/huggingface/test_huggingface_negative.py (3)
tests/model_registry/model_catalog/utils.py (1)
  • assert_source_error_state_message (256-272)
tests/model_registry/model_catalog/conftest.py (2)
  • updated_catalog_config_map_scope_function (382-397)
  • model_catalog_rest_url (413-422)
tests/model_registry/conftest.py (1)
  • model_registry_rest_headers (399-400)
🪛 Ruff (0.14.10)
tests/model_registry/model_catalog/catalog_config/test_model_catalog_negative.py

83-83: Unused method argument: updated_catalog_config_map_scope_function

(ARG002)

tests/model_registry/model_catalog/huggingface/test_huggingface_negative.py

135-135: Unused method argument: updated_catalog_config_map_scope_function

(ARG002)

🔇 Additional comments (3)
tests/model_registry/model_catalog/conftest.py (1)

396-397: LGTM!

Adding the API readiness wait after teardown aligns with the pattern used in other fixtures (updated_catalog_config_map, sparse_override_catalog_source) and ensures subsequent tests don't encounter race conditions from incomplete API initialization.

tests/model_registry/model_catalog/catalog_config/test_model_catalog_negative.py (1)

81-93: LGTM! Good refactoring to use the shared helper.

The test is correctly simplified to use assert_source_error_state_message, reducing code duplication.

Regarding the static analysis hint about updated_catalog_config_map_scope_function being unused: this is a false positive. The fixture is an indirect parameterized fixture that pytest invokes to set up the ConfigMap configuration before the test runs. It must be declared as a test parameter even though the test body doesn't reference it directly.

tests/model_registry/model_catalog/huggingface/test_huggingface_negative.py (1)

133-145: Good coverage of HuggingFace negative scenarios.

The test method correctly uses the shared assert_source_error_state_message helper. The parameterized cases provide comprehensive coverage of invalid HuggingFace catalog configurations including:

  • Missing includedModels
  • Various invalid wildcard patterns
  • Non-existent allowedOrganization

Regarding the static analysis hint about updated_catalog_config_map_scope_function being unused: this is a false positive – the fixture is invoked indirectly by pytest to configure the ConfigMap before each test case.

Copy link
Copy Markdown
Contributor

@fege fege left a comment

Choose a reason for hiding this comment

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

/lgtm

Copy link
Copy Markdown
Contributor

@sheltoncyril sheltoncyril left a comment

Choose a reason for hiding this comment

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

/lgtm

@dbasunag dbasunag merged commit 24645b1 into opendatahub-io:main Jan 13, 2026
8 checks passed
@dbasunag dbasunag deleted the HF_neg branch January 13, 2026 22:40
@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
* Add negative test for allowedOrganization

* Move HF tests to separate location
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