This is an automated email from the ASF dual-hosted git repository. wenjin272 pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/flink-agents.git
commit 65badf936daa8e82453dd10234cfa59a8c589ac5 Author: purshotam shah <[email protected]> AuthorDate: Fri Sep 18 10:50:18 2026 -0700 [e2e] Tighten the API-key gating in ChatModelIntegrationTest ChatModelIntegrationTest gates its API-key providers on a non-blank <PROVIDER>_API_KEY through a new shared OllamaPreparationUtils.hasApiKey helper. This re-arms the OPENAI_RESPONSES case, which was gated on a variable nothing sets (the agent reads OPENAI_API_KEY), and clears MODEL_PROVIDER after each run. Generated-by: Claude Code 2.1.273 (Claude Fable 5.1) --- .../integration/test/ChatModelIntegrationTest.java | 88 ++++++++++++---------- .../integration/test/OllamaPreparationUtils.java | 9 +++ 2 files changed, 57 insertions(+), 40 deletions(-) diff --git a/e2e-test/flink-agents-end-to-end-tests-integration/src/test/java/org/apache/flink/agents/integration/test/ChatModelIntegrationTest.java b/e2e-test/flink-agents-end-to-end-tests-integration/src/test/java/org/apache/flink/agents/integration/test/ChatModelIntegrationTest.java index d51852b8..fec78d04 100644 --- a/e2e-test/flink-agents-end-to-end-tests-integration/src/test/java/org/apache/flink/agents/integration/test/ChatModelIntegrationTest.java +++ b/e2e-test/flink-agents-end-to-end-tests-integration/src/test/java/org/apache/flink/agents/integration/test/ChatModelIntegrationTest.java @@ -40,7 +40,6 @@ import static org.apache.flink.agents.integration.test.ChatModelIntegrationAgent */ public class ChatModelIntegrationTest extends OllamaPreparationUtils { - private static final String API_KEY = "_API_KEY"; private static final String OLLAMA = "OLLAMA"; private final boolean ollamaReady; @@ -49,53 +48,62 @@ public class ChatModelIntegrationTest extends OllamaPreparationUtils { ollamaReady = pullModel(OLLAMA_MODEL); } + /** The Responses API case is built from OPENAI_API_KEY in {@link ChatModelIntegrationAgent}. */ + private static String apiKeyProvider(String provider) { + return "OPENAI_RESPONSES".equals(provider) ? "OPENAI" : provider; + } + @ParameterizedTest() @ValueSource(strings = {"ANTHROPIC", "AZURE_OPENAI", "OLLAMA", "OPENAI", "OPENAI_RESPONSES"}) public void testChatModeIntegration(String provider) throws Exception { Assumptions.assumeTrue( - (OLLAMA.equals(provider) && ollamaReady) - || System.getenv().get(provider + API_KEY) != null, + OLLAMA.equals(provider) ? ollamaReady : hasApiKey(apiKeyProvider(provider)), String.format( "Server or authentication information is not provided for %s", provider)); System.setProperty("MODEL_PROVIDER", provider); - - // Create the execution environment - StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); - env.setParallelism(1); - - // Use prompts that trigger different tool calls in the agent - DataStream<String> inputStream = - env.fromData( - "Convert 25 degrees Celsius to Fahrenheit", - "Convert 98.6 degrees Fahrenheit to Celsius", - "Change 32 degrees Celsius to Fahrenheit", - "If it's 75 degrees Fahrenheit, what would that be in Celsius?", - "Convert room temperature of 20C to F", - "Calculate BMI for someone who is 1.75 meters tall and weighs 70 kg", - "What's the BMI for a person weighing 85 kg with height 1.80 meters?", - "Can you tell me the BMI if I'm 1.65m tall and weigh 60kg?", - "Find BMI for 75kg weight and 1.78m height", - "Create me a random number please"); - - // Create agents execution environment - AgentsExecutionEnvironment agentsEnv = - AgentsExecutionEnvironment.getExecutionEnvironment(env); - - // Apply agent to the DataStream and use the prompt itself as the key - DataStream<Object> outputStream = - agentsEnv - .fromDataStream(inputStream, (KeySelector<String, String>) value -> value) - .apply(new ChatModelIntegrationAgent()) - .toDataStream(); - - // Collect the results - CloseableIterator<Object> results = outputStream.collectAsync(); - - // Execute the pipeline - agentsEnv.execute(); - - checkResult(results); + try { + + // Create the execution environment + StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); + env.setParallelism(1); + + // Use prompts that trigger different tool calls in the agent + DataStream<String> inputStream = + env.fromData( + "Convert 25 degrees Celsius to Fahrenheit", + "Convert 98.6 degrees Fahrenheit to Celsius", + "Change 32 degrees Celsius to Fahrenheit", + "If it's 75 degrees Fahrenheit, what would that be in Celsius?", + "Convert room temperature of 20C to F", + "Calculate BMI for someone who is 1.75 meters tall and weighs 70 kg", + "What's the BMI for a person weighing 85 kg with height 1.80 meters?", + "Can you tell me the BMI if I'm 1.65m tall and weigh 60kg?", + "Find BMI for 75kg weight and 1.78m height", + "Create me a random number please"); + + // Create agents execution environment + AgentsExecutionEnvironment agentsEnv = + AgentsExecutionEnvironment.getExecutionEnvironment(env); + + // Apply agent to the DataStream and use the prompt itself as the key + DataStream<Object> outputStream = + agentsEnv + .fromDataStream( + inputStream, (KeySelector<String, String>) value -> value) + .apply(new ChatModelIntegrationAgent()) + .toDataStream(); + + // Collect the results + CloseableIterator<Object> results = outputStream.collectAsync(); + + // Execute the pipeline + agentsEnv.execute(); + + checkResult(results); + } finally { + System.clearProperty("MODEL_PROVIDER"); + } } public void checkResult(CloseableIterator<Object> results) { diff --git a/e2e-test/flink-agents-end-to-end-tests-integration/src/test/java/org/apache/flink/agents/integration/test/OllamaPreparationUtils.java b/e2e-test/flink-agents-end-to-end-tests-integration/src/test/java/org/apache/flink/agents/integration/test/OllamaPreparationUtils.java index c236605a..6426c982 100644 --- a/e2e-test/flink-agents-end-to-end-tests-integration/src/test/java/org/apache/flink/agents/integration/test/OllamaPreparationUtils.java +++ b/e2e-test/flink-agents-end-to-end-tests-integration/src/test/java/org/apache/flink/agents/integration/test/OllamaPreparationUtils.java @@ -27,6 +27,15 @@ import java.util.concurrent.TimeUnit; public class OllamaPreparationUtils { private static final Logger LOG = LoggerFactory.getLogger(OllamaPreparationUtils.class); + /** + * Whether a non-blank {@code <PROVIDER>_API_KEY} is exported. An exported but blank key would + * fail in the connection constructor instead of skipping the provider. + */ + public static boolean hasApiKey(String provider) { + String key = System.getenv(provider + "_API_KEY"); + return key != null && !key.isBlank(); + } + public static boolean pullModel(String model) throws IOException { String path = Objects.requireNonNull(
