gnodet commented on code in PR #23147:
URL: https://github.com/apache/camel/pull/23147#discussion_r3226825238
##########
components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/agentruntime/BedrockAgentRuntimeProducer.java:
##########
@@ -71,6 +75,9 @@ public void process(Exchange exchange) throws Exception {
case invokeFlow:
invokeFlow(exchange);
break;
+ case retrieve:
+ retrieve(getEndpoint().getBedrockAgentRuntimeClient(),
exchange);
Review Comment:
Nit: minor style inconsistency — the existing `retrieveAndGenerate` and
`invokeFlow` cases call their methods with just `exchange`, and those methods
fetch the client internally via `getEndpoint().getBedrockAgentRuntimeClient()`.
Here the client is resolved at the call site and passed in as a parameter.
Not a functional issue at all, just a pattern mismatch that caught my eye.
Feel free to ignore.
_Claude Code on behalf of Guillaume Nodet_
##########
components/camel-aws/camel-aws-bedrock/src/test/java/org/apache/camel/component/aws2/bedrock/agentruntime/BedrockAgentRuntimeProducerRetrieveTest.java:
##########
@@ -0,0 +1,210 @@
+/*
+ * 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.
+ */
+package org.apache.camel.component.aws2.bedrock.agentruntime;
+
+import java.util.List;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.Exchange;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.support.SimpleRegistry;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import
software.amazon.awssdk.services.bedrockagentruntime.BedrockAgentRuntimeClient;
+import
software.amazon.awssdk.services.bedrockagentruntime.model.KnowledgeBaseRetrievalResult;
+import
software.amazon.awssdk.services.bedrockagentruntime.model.RetrievalResultContent;
+import
software.amazon.awssdk.services.bedrockagentruntime.model.RetrieveRequest;
+import
software.amazon.awssdk.services.bedrockagentruntime.model.RetrieveResponse;
+import software.amazon.awssdk.services.bedrockagentruntime.model.SearchType;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.lenient;
+
+@ExtendWith(MockitoExtension.class)
+public class BedrockAgentRuntimeProducerRetrieveTest {
+
+ @Mock
+ private BedrockAgentRuntimeClient syncClient;
+
+ private CamelContext camelContext;
+ private ProducerTemplate template;
+ private AtomicReference<RetrieveRequest> capturedRequest;
+
+ @BeforeEach
+ public void setup() throws Exception {
+ capturedRequest = new AtomicReference<>();
+ // Capture the request, return a small synthetic response so the
producer's response-handling path is also
+ // exercised (results in body + RETRIEVED_RESULTS header, optional
nextToken header). lenient(): one of the
+ // tests verifies a producer-side validation that throws before
reaching the client.
+ lenient().doAnswer(invocation -> {
+ capturedRequest.set(invocation.getArgument(0,
RetrieveRequest.class));
+ KnowledgeBaseRetrievalResult result =
KnowledgeBaseRetrievalResult.builder()
+ .content(RetrievalResultContent.builder().text("matched
chunk").build())
+ .score(0.87)
+ .build();
+ return RetrieveResponse.builder()
+ .retrievalResults(result)
+ .nextToken("page-2-token")
Review Comment:
The mock response exercises the `nextToken` path nicely, but the
`guardrailAction` response-handling path in `prepareRetrieveResponse` is never
covered — the mock response does not set a guardrail action, so the
`RETRIEVE_GUARDRAIL_ACTION` header branch is untested.
Consider either adding `.guardrailAction(...)` to this mock response (and
asserting the header in the first test), or adding a small dedicated test with
its own mock response that includes a guardrail action. Low priority but would
close the gap.
_Claude Code on behalf of Guillaume Nodet_
--
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]