skrawcz commented on code in PR #677: URL: https://github.com/apache/burr/pull/677#discussion_r3108227570
########## tests/integrations/test_bip0042_bedrock.py: ########## @@ -0,0 +1,419 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""Tests for Bedrock integration.""" + +import inspect +from unittest.mock import MagicMock + +import pytest +from botocore.exceptions import ClientError + +from burr.core.state import State + +boto3 = pytest.importorskip("boto3", reason="boto3 required for Bedrock tests") + + +class TestBedrockImports: + """Test that Bedrock classes can be imported via lazy loading.""" + + def test_lazy_import_bedrock_action(self): + """Verify BedrockAction can be imported from burr.integrations.""" + from burr.integrations import BedrockAction + + assert BedrockAction is not None + + def test_lazy_import_bedrock_streaming_action(self): + """Verify BedrockStreamingAction can be imported from burr.integrations.""" + from burr.integrations import BedrockStreamingAction + + assert BedrockStreamingAction is not None + + def test_direct_import_bedrock_module(self): + """Verify bedrock.py module exists and has expected classes.""" + from burr.integrations.bedrock import ( + BedrockAction, + BedrockStreamingAction, + StateToPromptMapper, + ) + + assert BedrockAction is not None + assert BedrockStreamingAction is not None + assert StateToPromptMapper is not None + + +class TestBedrockGuardrailValidation: + """guardrail_id requires an explicit guardrail_version.""" + + def test_raises_when_guardrail_id_without_version(self): + from burr.integrations.bedrock import BedrockAction + + with pytest.raises(ValueError, match="guardrail_version is required"): + BedrockAction( + model_id="test-model", + input_mapper=lambda s: {"messages": []}, + reads=[], + writes=["response"], + guardrail_id="gr-123", + ) + + def test_accepts_explicit_draft_version(self): + from burr.integrations.bedrock import BedrockAction + + mock_client = MagicMock() + mock_client.converse.return_value = { + "output": {"message": {"content": [{"text": "ok"}]}}, + "usage": {}, + "stopReason": "end_turn", + } + action = BedrockAction( + model_id="test-model", + input_mapper=lambda s: {"messages": [{"role": "user", "content": "hi"}]}, + reads=[], + writes=["response"], + guardrail_id="gr-123", + guardrail_version="DRAFT", + client=mock_client, + ) + action.run_and_update({}) + call_kw = mock_client.converse.call_args[1] + assert call_kw["guardrailConfig"]["guardrailVersion"] == "DRAFT" + + +class TestBedrockActionInterface: + """Test BedrockAction class interface with mocked boto3.""" + + def test_bedrock_action_extends_single_step_action(self): + """Verify BedrockAction extends SingleStepAction.""" + from burr.core.action import SingleStepAction + from burr.integrations.bedrock import BedrockAction Review Comment: can we move these to the top level? but after the skip check? I think that will be cleaner? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
