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

slachiewicz pushed a commit to branch mvnd-1.x
in repository https://gitbox.apache.org/repos/asf/maven-mvnd.git

commit e9a32e0d6af45307c942e0b8d4c5f029e8bfe818
Author: Adriano Machado <[email protected]>
AuthorDate: Tue Aug 4 10:03:26 2026 -0400

    fix: feed real stdin to native mvnd process in NativeTestClient
    
    (cherry picked from commit eb5e83dfc63b88489889b8a311e723b6c251b7c1)
    
    Applied unchanged.
---
 .../mvndaemon/mvnd/assertj/TestClientOutput.java    | 11 +++++++++++
 .../org/mvndaemon/mvnd/it/InputStreamNativeIT.java  |  6 ++++++
 .../org/mvndaemon/mvnd/junit/NativeTestClient.java  | 21 +++++++++++++++++----
 3 files changed, 34 insertions(+), 4 deletions(-)

diff --git 
a/integration-tests/src/test/java/org/mvndaemon/mvnd/assertj/TestClientOutput.java
 
b/integration-tests/src/test/java/org/mvndaemon/mvnd/assertj/TestClientOutput.java
index 524a6ae7..47aac9fb 100644
--- 
a/integration-tests/src/test/java/org/mvndaemon/mvnd/assertj/TestClientOutput.java
+++ 
b/integration-tests/src/test/java/org/mvndaemon/mvnd/assertj/TestClientOutput.java
@@ -71,6 +71,17 @@ public class TestClientOutput implements ClientOutput {
         return messages;
     }
 
+    /**
+     * Bytes to feed to the real OS-level stdin of a natively spawned {@code 
mvnd} process
+     * (see {@code NativeTestClient}), or {@code null} if the test doesn't 
need to simulate stdin.
+     * The {@link #accept(Message)}-based {@code RequestInput}/{@code 
RequestInputAvailable}
+     * interception only works for the in-process JVM test client, since for a 
native test the
+     * daemon talks to the spawned binary's own real stdin, which this JVM 
never sees as messages.
+     */
+    public byte[] nativeStdin() {
+        return null;
+    }
+
     public void assertContainsMatchingSubsequence(String... patterns) {
         Assertions.assertThat(messagesToString()).is(new 
MatchInOrderAmongOthers<>(patterns));
     }
diff --git 
a/integration-tests/src/test/java/org/mvndaemon/mvnd/it/InputStreamNativeIT.java
 
b/integration-tests/src/test/java/org/mvndaemon/mvnd/it/InputStreamNativeIT.java
index e3aa0c56..fb4d0b11 100644
--- 
a/integration-tests/src/test/java/org/mvndaemon/mvnd/it/InputStreamNativeIT.java
+++ 
b/integration-tests/src/test/java/org/mvndaemon/mvnd/it/InputStreamNativeIT.java
@@ -21,6 +21,7 @@ package org.mvndaemon.mvnd.it;
 import javax.inject.Inject;
 
 import java.io.IOException;
+import java.nio.charset.StandardCharsets;
 
 import org.junit.jupiter.api.Test;
 import org.mvndaemon.mvnd.assertj.TestClientOutput;
@@ -85,6 +86,11 @@ class InputStreamNativeIT {
                     super.accept(message);
                 }
             }
+
+            @Override
+            public byte[] nativeStdin() {
+                return data.getBytes(StandardCharsets.UTF_8);
+            }
         };
         client.execute(output, "install").assertSuccess();
 
diff --git 
a/integration-tests/src/test/java/org/mvndaemon/mvnd/junit/NativeTestClient.java
 
b/integration-tests/src/test/java/org/mvndaemon/mvnd/junit/NativeTestClient.java
index 03ae48a6..6f3f7dc8 100644
--- 
a/integration-tests/src/test/java/org/mvndaemon/mvnd/junit/NativeTestClient.java
+++ 
b/integration-tests/src/test/java/org/mvndaemon/mvnd/junit/NativeTestClient.java
@@ -27,6 +27,7 @@ import java.util.Map;
 import java.util.function.Consumer;
 import java.util.function.Supplier;
 
+import org.mvndaemon.mvnd.assertj.TestClientOutput;
 import org.mvndaemon.mvnd.client.Client;
 import org.mvndaemon.mvnd.client.DaemonParameters;
 import org.mvndaemon.mvnd.client.ExecutionResult;
@@ -100,10 +101,22 @@ public class NativeTestClient implements Client {
                 log.add(s);
             }
         };
-        try (CommandProcess process =
-                new CommandProcess(builder.start(), loggingConsumer.andThen(s 
-> output.accept(Message.log(s))))) {
-            final int exitCode = process.waitFor(timeoutMs);
-            return new Result(args, exitCode, log);
+        try {
+            final Process rawProcess = builder.start();
+            if (output instanceof TestClientOutput) {
+                final byte[] stdin = ((TestClientOutput) output).nativeStdin();
+                if (stdin != null) {
+                    // Feed the process's real stdin, like piping data into a 
real mvnd invocation.
+                    // The daemon talks to this spawned binary's own stdin, 
not to any in-JVM message queue.
+                    rawProcess.getOutputStream().write(stdin);
+                    rawProcess.getOutputStream().close();
+                }
+            }
+            try (CommandProcess process =
+                    new CommandProcess(rawProcess, loggingConsumer.andThen(s 
-> output.accept(Message.log(s))))) {
+                final int exitCode = process.waitFor(timeoutMs);
+                return new Result(args, exitCode, log);
+            }
         } catch (IOException e) {
             throw new RuntimeException("Could not execute: " + cmdString, e);
         }

Reply via email to