This is an automated email from the ASF dual-hosted git repository.

jamesnetherton pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git


The following commit(s) were added to refs/heads/main by this push:
     new 2c16e56792 [fixes #8007] Fix LangChain4j Agent MCP tests on Windows
2c16e56792 is described below

commit 2c16e567924bb6273b51cc0ff8da97da09a63d4b
Author: Lukas Lowinger <[email protected]>
AuthorDate: Mon Dec 1 08:08:36 2025 +0100

    [fixes #8007] Fix LangChain4j Agent MCP tests on Windows
---
 .../langchain4j/agent/it/AgentProducers.java       |  2 ++
 .../src/main/resources/application.properties      |  3 ++
 .../agent/it/Langchain4jAgentTestResource.java     | 39 +++++++++++++++++-----
 3 files changed, 35 insertions(+), 9 deletions(-)

diff --git 
a/integration-tests/langchain4j-agent/src/main/java/org/apache/camel/quarkus/component/langchain4j/agent/it/AgentProducers.java
 
b/integration-tests/langchain4j-agent/src/main/java/org/apache/camel/quarkus/component/langchain4j/agent/it/AgentProducers.java
index a3d9bdff67..7e9b15314a 100644
--- 
a/integration-tests/langchain4j-agent/src/main/java/org/apache/camel/quarkus/component/langchain4j/agent/it/AgentProducers.java
+++ 
b/integration-tests/langchain4j-agent/src/main/java/org/apache/camel/quarkus/component/langchain4j/agent/it/AgentProducers.java
@@ -235,6 +235,8 @@ public class AgentProducers {
             return new AgentWithoutMemory(new AgentConfiguration()
                     .withChatModel(chatModel)
                     .withMcpClient(new DefaultMcpClient.Builder()
+                            // Startup on Windows is really slow (around 1min).
+                            .initializationTimeout(Duration.ofSeconds(120))
                             .transport(new StdioMcpTransport.Builder()
                                     
.command(List.of(ProcessUtils.getNpxExecutable(), "-y",
                                             
"@modelcontextprotocol/server-everything"))
diff --git 
a/integration-tests/langchain4j-agent/src/main/resources/application.properties 
b/integration-tests/langchain4j-agent/src/main/resources/application.properties
index 63b00b4664..e336e0a1bc 100644
--- 
a/integration-tests/langchain4j-agent/src/main/resources/application.properties
+++ 
b/integration-tests/langchain4j-agent/src/main/resources/application.properties
@@ -16,3 +16,6 @@
 ## ---------------------------------------------------------------------------
 quarkus.native.resources.includes=rag/*
 quarkus.http.test-timeout=120S
+
+# This can be handy for detecting output from DefaultMcpClient npx process in 
case of eg. slow Windows machine.
+# quarkus.log.category."dev.langchain4j.mcp.client.transport.stdio".level=DEBUG
\ No newline at end of file
diff --git 
a/integration-tests/langchain4j-agent/src/test/java/org/apache/camel/quarkus/component/langchain4j/agent/it/Langchain4jAgentTestResource.java
 
b/integration-tests/langchain4j-agent/src/test/java/org/apache/camel/quarkus/component/langchain4j/agent/it/Langchain4jAgentTestResource.java
index ab750a8612..e579e9c27f 100644
--- 
a/integration-tests/langchain4j-agent/src/test/java/org/apache/camel/quarkus/component/langchain4j/agent/it/Langchain4jAgentTestResource.java
+++ 
b/integration-tests/langchain4j-agent/src/test/java/org/apache/camel/quarkus/component/langchain4j/agent/it/Langchain4jAgentTestResource.java
@@ -17,6 +17,8 @@
 package org.apache.camel.quarkus.component.langchain4j.agent.it;
 
 import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
@@ -27,7 +29,6 @@ import java.util.concurrent.TimeUnit;
 import com.github.tomakehurst.wiremock.stubbing.StubMapping;
 import 
org.apache.camel.quarkus.component.langchain4j.agent.it.util.ProcessUtils;
 import 
org.apache.camel.quarkus.test.wiremock.WireMockTestResourceLifecycleManager;
-import org.junit.jupiter.api.condition.OS;
 
 public class Langchain4jAgentTestResource extends 
WireMockTestResourceLifecycleManager {
     private static final String OLLAMA_ENV_URL = "LANGCHAIN4J_OLLAMA_BASE_URL";
@@ -93,20 +94,40 @@ public class Langchain4jAgentTestResource extends 
WireMockTestResourceLifecycleM
 
     private Boolean isNodeJSInstallationExists() {
         try {
-            // TODO: Suppress MCP tests in GitHub Actions for windows - 
https://github.com/apache/camel-quarkus/issues/8007
-            if (OS.current().equals(OS.WINDOWS) && System.getenv("CI") != 
null) {
+            ProcessBuilder pb = new ProcessBuilder()
+                    .command(ProcessUtils.getNpxExecutable(), "--version");
+            Process process = pb.start();
+
+            boolean finished = process.waitFor(20, TimeUnit.SECONDS);
+
+            if (!finished) {
+                process.destroyForcibly();
+                LOG.error("Command: %s took too long.".formatted(String.join(" 
", pb.command())));
                 return false;
             }
 
-            Process process = new ProcessBuilder()
-                    .command(ProcessUtils.getNpxExecutable(), "--version")
-                    .start();
+            int exitCode = process.exitValue();
+            String output = readStream(process.getInputStream());
+            String errorOutput = readStream(process.getErrorStream());
+
+            if (exitCode == 0) {
+                LOG.info("Command: %s: %s".formatted(String.join(" ", 
pb.command()), output.trim()));
+            } else {
+                LOG.error("Command: %s failed with %s".formatted(String.join(" 
", pb.command()), exitCode));
+                LOG.error("Process standard output 
%s".formatted(output.trim()));
+                LOG.error("Process error output 
%s".formatted(errorOutput.trim()));
+            }
 
-            process.waitFor(10, TimeUnit.SECONDS);
-            return process.exitValue() == 0;
+            return exitCode == 0;
         } catch (Exception e) {
             LOG.error("Failed detecting Node.js", e);
+            return false;
+        }
+    }
+
+    private String readStream(InputStream inputStream) throws IOException {
+        try (inputStream) {
+            return new String(inputStream.readAllBytes(), 
StandardCharsets.UTF_8);
         }
-        return false;
     }
 }

Reply via email to