Fix the guardrails orchestrator gateway route#608
Fix the guardrails orchestrator gateway route#608adolfo-ab merged 2 commits intoopendatahub-io:mainfrom
Conversation
modified: tests/fixtures/guardrails.py modified: tests/model_explainability/guardrails/test_guardrails.py
📝 WalkthroughWalkthroughIntroduces 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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
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. Comment |
|
The following are automatically added/executed:
Available user actions:
Supported labels{'/wip', '/cherry-pick', '/lgtm', '/build-push-pr-image', '/hold', '/verified'} |
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
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_clientandmodel_namespaceare 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 rUsage in fixture:
with route_with_timeout(name=f"{guardrails_orchestrator.name}-gateway", namespace=guardrails_orchestrator.namespace) as r: yield rtests/model_explainability/guardrails/test_guardrails.py (3)
166-176: Add HTTP timeout and silence unusedqwen_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 unusedqwen_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 unusedqwen_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
📒 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)
|
/verified |
|
Status of building tag latest: success. |
* 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>
Description
How Has This Been Tested?
Merge criteria:
Summary by CodeRabbit
New Features
Tests
Chores