Skip to content

Fix the guardrails orchestrator gateway route#608

Merged
adolfo-ab merged 2 commits intoopendatahub-io:mainfrom
kpunwatk:update_builtIn
Sep 15, 2025
Merged

Fix the guardrails orchestrator gateway route#608
adolfo-ab merged 2 commits intoopendatahub-io:mainfrom
kpunwatk:update_builtIn

Conversation

@kpunwatk
Copy link
Copy Markdown
Contributor

@kpunwatk kpunwatk commented Sep 14, 2025

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

  • New Features

    • None.
  • Tests

    • Updated guardrails tests to target the gateway endpoint.
    • Test setup now enforces route availability and applies a 10-minute request timeout.
  • Chores

    • Introduced a shared test setup for the gateway route.

	modified:   tests/fixtures/guardrails.py
	modified:   tests/model_explainability/guardrails/test_guardrails.py
@kpunwatk kpunwatk requested review from a team, adolfo-ab and sheltoncyril as code owners September 14, 2025 15:45
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Sep 14, 2025

📝 Walkthrough

Walkthrough

Introduces a new pytest fixture to create and patch a gateway Route for the guardrails orchestrator, then updates three guardrails tests to depend on this gateway fixture and use its host for request URLs. No other test logic or assertions change.

Changes

Cohort / File(s) Summary
Fixtures: Orchestrator gateway Route
tests/fixtures/guardrails.py
Added fixture guardrails_orchestrator_gateway_route creating a Route named "<guardrails_orchestrator.name>-gateway" in orchestrator namespace, ensuring existence, waiting for readiness, and patching metadata.annotations to set Haproxy timeout to "10m"; yields the Route.
Tests: Use gateway Route in guardrails tests
tests/model_explainability/guardrails/test_guardrails.py
Replaced fixture guardrails_orchestrator_route with guardrails_orchestrator_gateway_route in three tests; updated URL construction to use .host from the new fixture.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Pre-merge checks and finishing touches

❌ 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%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ 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 "Fix the guardrails orchestrator gateway route" is a short, single-sentence summary that directly reflects the primary change in the PR—adding/fixing the guardrails orchestrator gateway route fixture and updating tests to use it. It is concise, specific to the change, and contains no extraneous noise or ambiguous wording.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@github-actions
Copy link
Copy Markdown

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

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

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 (5)
tests/fixtures/guardrails.py (2)

144-165: Silence Ruff ARG001 for unused fixture params; keep fixture dependency ordering.

admin_client and model_namespace are intentionally injected for ordering but unused, triggering Ruff warnings.

Apply:

 def guardrails_orchestrator_gateway_route(
     admin_client: DynamicClient,
     model_namespace: Namespace,
     guardrails_orchestrator: GuardrailsOrchestrator,
 ) -> Generator[Route, Any, Any]:
+    # These fixtures are required for dependency/ordering; explicitly mark as used.
+    del admin_client, model_namespace
     guardrails_orchestrator_gateway_route = Route(
         name=f"{guardrails_orchestrator.name}-gateway",
         namespace=guardrails_orchestrator.namespace,
         wait_for_resource=True,
         ensure_exists=True,
     )

Also, please confirm the operator actually creates the route with the “-gateway” suffix in all target environments. If it differs (e.g., “-gw”), tests will fail at host resolution.


144-165: Reduce duplication across Route fixtures.

guardrails_orchestrator_route, guardrails_orchestrator_health_route, and the new gateway route repeat identical creation/patch logic. Extract a small contextmanager to cut duplication.

Example:

from contextlib import contextmanager

@contextmanager
def route_with_timeout(name: str, namespace: str):
    r = Route(name=name, namespace=namespace, wait_for_resource=True, ensure_exists=True)
    with ResourceEditor(patches={r: {"metadata": {"annotations": {Annotations.HaproxyRouterOpenshiftIo.TIMEOUT: "10m"}}}}):
        yield r

Usage in fixture:

with route_with_timeout(name=f"{guardrails_orchestrator.name}-gateway", namespace=guardrails_orchestrator.namespace) as r:
    yield r
tests/model_explainability/guardrails/test_guardrails.py (3)

166-176: Add HTTP timeout and silence unused qwen_isvc.

Prevents hangs on network issues and appeases Ruff ARG002.

 def test_guardrails_builtin_detectors_unsuitable_input(
-        self, current_client_token, openshift_ca_bundle_file, qwen_isvc, guardrails_orchestrator_gateway_route
+        self, current_client_token, openshift_ca_bundle_file, qwen_isvc, guardrails_orchestrator_gateway_route
     ):
-        response = requests.post(
+        del qwen_isvc  # fixture enforces readiness; silence ARG002
+        response = requests.post(
             url=f"https://{guardrails_orchestrator_gateway_route.host}{PII_ENDPOINT}{OpenAIEnpoints.CHAT_COMPLETIONS}",
             headers=get_auth_headers(token=current_client_token),
             json=get_chat_detections_payload(
                 content=PROMPT_WITH_PII,
                 model=QWEN_MODEL_NAME,
             ),
-            verify=openshift_ca_bundle_file,
+            verify=openshift_ca_bundle_file,
+            timeout=Timeout.TIMEOUT_1MIN,
         )

187-197: Add HTTP timeout and silence unused qwen_isvc.

Same rationale as above.

 def test_guardrails_builtin_detectors_unsuitable_output(
-        self, current_client_token, openshift_ca_bundle_file, qwen_isvc, guardrails_orchestrator_gateway_route
+        self, current_client_token, openshift_ca_bundle_file, qwen_isvc, guardrails_orchestrator_gateway_route
     ):
-        response = requests.post(
+        del qwen_isvc
+        response = requests.post(
             url=f"https://{guardrails_orchestrator_gateway_route.host}{PII_ENDPOINT}{OpenAIEnpoints.CHAT_COMPLETIONS}",
             headers=get_auth_headers(token=current_client_token),
             json=get_chat_detections_payload(
                 content="Output example email address, nothing else.",
                 model=QWEN_MODEL_NAME,
             ),
-            verify=openshift_ca_bundle_file,
+            verify=openshift_ca_bundle_file,
+            timeout=Timeout.TIMEOUT_1MIN,
         )

219-231: Add HTTP timeout and silence unused qwen_isvc.

Prevents flakiness on gateway path variations.

     def test_guardrails_builtin_detectors_negative_detection(
         self,
         current_client_token,
         openshift_ca_bundle_file,
         qwen_isvc,
         guardrails_orchestrator_gateway_route,
         message,
         url_path,
     ):
-        response = requests.post(
+        del qwen_isvc
+        response = requests.post(
             url=f"https://{guardrails_orchestrator_gateway_route.host}{url_path}{OpenAIEnpoints.CHAT_COMPLETIONS}",
             headers=get_auth_headers(token=current_client_token),
             json=get_chat_detections_payload(
                 content=str(message),
                 model=QWEN_MODEL_NAME,
             ),
-            verify=openshift_ca_bundle_file,
+            verify=openshift_ca_bundle_file,
+            timeout=Timeout.TIMEOUT_1MIN,
         )
📜 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 5f9b797 and 7e4a2d5.

📒 Files selected for processing (2)
  • tests/fixtures/guardrails.py (1 hunks)
  • tests/model_explainability/guardrails/test_guardrails.py (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
tests/model_explainability/guardrails/test_guardrails.py (2)
tests/fixtures/guardrails.py (1)
  • guardrails_orchestrator_gateway_route (145-165)
utilities/plugins/constant.py (1)
  • OpenAIEnpoints (1-7)
tests/fixtures/guardrails.py (2)
tests/conftest.py (2)
  • admin_client (68-69)
  • model_namespace (100-120)
utilities/constants.py (2)
  • Annotations (131-150)
  • HaproxyRouterOpenshiftIo (149-150)
🪛 Ruff (0.12.2)
tests/model_explainability/guardrails/test_guardrails.py

166-166: Unused method argument: qwen_isvc

(ARG002)


168-168: Probable use of requests call without timeout

(S113)


187-187: Unused method argument: qwen_isvc

(ARG002)


189-189: Probable use of requests call without timeout

(S113)


223-223: Probable use of requests call without timeout

(S113)

tests/fixtures/guardrails.py

146-146: Unused function argument: admin_client

(ARG001)


147-147: Unused function argument: model_namespace

(ARG001)

@kpunwatk
Copy link
Copy Markdown
Contributor Author

/verified

@rhods-ci-bot rhods-ci-bot added the Verified Verified pr in Jenkins label Sep 15, 2025
@adolfo-ab adolfo-ab merged commit 3d63351 into opendatahub-io:main Sep 15, 2025
12 checks passed
@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
* Fix the guardrails orchestrator gateway route
	modified:   tests/fixtures/guardrails.py
	modified:   tests/model_explainability/guardrails/test_guardrails.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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.

5 participants