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

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

commit 4ecfeb202e01eedc9e466bdc82f157fffd77fbd0
Author: Luigi De Masi <[email protected]>
AuthorDate: Mon Nov 30 15:02:17 2026 +0100

    Fix #110: Resolve command shims from the Windows Path
    
    Share absolute PATH directory lookup between CLI probes and Ship. Check a 
command shim in a Windows child with a mixed-case Path and an invalid entry. 
Report retained tool filters and preview their explicit reset.
    
    Co-authored-by: OpenAI Codex <[email protected]>
---
 docs/modules/ROOT/pages/agents.adoc                |  3 +-
 docs/modules/ROOT/pages/commands.adoc              |  5 +--
 .../org/apache/camel/kit/command/InitCommand.java  |  4 +++
 .../apache/camel/kit/command/ship/ShipRuntime.java | 30 ++--------------
 .../java/org/apache/camel/kit/config/CamelCli.java |  2 +-
 .../camel/kit/generator/CodexConfigMerger.java     |  8 ++++-
 .../apache/camel/kit/generator/ManagedFiles.java   |  4 ++-
 .../camel/kit/generator/McpConfigGenerator.java    | 20 ++++++++---
 .../org/apache/camel/kit/service/InitService.java  |  4 ++-
 .../org/apache/camel/kit/util/ProcessRunner.java   | 41 +++++++++++++---------
 .../skills/camel-test/guides/test-runner.md        |  8 +++--
 .../apache/camel/kit/command/InitCommandTest.java  | 30 ++++++++++++++++
 .../camel/kit/command/ship/ShipRuntimeTest.java    | 16 +++++----
 .../org/apache/camel/kit/config/CamelCliTest.java  | 15 +++++---
 14 files changed, 121 insertions(+), 69 deletions(-)

diff --git a/docs/modules/ROOT/pages/agents.adoc 
b/docs/modules/ROOT/pages/agents.adoc
index 594cb6fa..77ac1d1d 100644
--- a/docs/modules/ROOT/pages/agents.adoc
+++ b/docs/modules/ROOT/pages/agents.adoc
@@ -127,7 +127,8 @@ camel-kit init my-integration --ai antigravity
 inherited MCP access, `camel-ship-worker` with read and search tools for Ship 
stages), the role
 personas under `.agents/camel-kit-personas/` and the MCP servers in 
`.agents/mcp_config.json` (two by default; three with `--with-citrus-mcp`). 
Open the
 project root in Antigravity and invoke `/camel-start` in the CLI, or ask it to 
use the `camel-start` skill by name;
-`/skills` lists the native skills and `/mcp` the connections.
+`/skills` lists the native skills and `/mcp` the connections. Launcher-mode 
MCP startup in Antigravity IDE
+is unverified. The generated Java command resolves its source file relative to 
the project root.
 
 The primary conversation owns questions, approvals, orchestration and report 
writes, and dispatches independent
 tasks with the native `invoke_subagent`; the children inherit the workspace 
permissions and MCP servers. Tool calls
diff --git a/docs/modules/ROOT/pages/commands.adoc 
b/docs/modules/ROOT/pages/commands.adoc
index 2b268bc0..047450f7 100644
--- a/docs/modules/ROOT/pages/commands.adoc
+++ b/docs/modules/ROOT/pages/commands.adoc
@@ -88,7 +88,8 @@ The explicit switch overrides the workspace's `camel.cli`. 
Without either settin
 invoking plugin's backend or probes the actual Camel executable. An ambiguous 
wrapper requires an explicit
 choice. Select a distribution script with `CAMEL_KIT_LAUNCHER` when several 
installations are present.
 Standalone init and its dry run select JBang when neither a Camel executable 
nor a Launcher override is
-present. JBang must answer its version probe. Generated JBang MCP commands use 
`jbang` on the agent's PATH;
+present. For bare command names, Kit searches absolute directories in PATH and 
skips malformed entries.
+JBang must answer its version probe. Generated JBang MCP commands use `jbang` 
on the agent's PATH;
 `CAMEL_KIT_JBANG` selects a custom executable for init's probe and Main run 
scripts.
 
 To migrate, close the agent and run `camel kit init --here --ai qwen --force 
--camel-cli=launcher`
@@ -99,7 +100,7 @@ from the workspace root. Inspect the generated MCP commands 
alongside the worksp
 trusting the project. To switch back, rerun the same command with 
`--camel-cli=jbang`.
 Kit removes its unedited Launcher assets once other installed agent configs 
have stopped using them.
 
-A narrower MCP tool list survives regeneration. Doctor lists the omitted tools 
as a warning.
+A narrower MCP tool list survives regeneration. Init names each server whose 
list it kept. Doctor lists the omitted tools as a warning.
 To adopt Kit's current defaults, including tools introduced by an upgrade, run 
e.g.
 `camel kit init --here --force --ai qwen --replace .qwen/settings.json`, 
repeating
 `--with-citrus-mcp` if enabled. This restores the managed servers' allowlists 
while preserving
diff --git 
a/kit/camel-kit-core/src/main/java/org/apache/camel/kit/command/InitCommand.java
 
b/kit/camel-kit-core/src/main/java/org/apache/camel/kit/command/InitCommand.java
index f31e3df6..d5d96e9d 100644
--- 
a/kit/camel-kit-core/src/main/java/org/apache/camel/kit/command/InitCommand.java
+++ 
b/kit/camel-kit-core/src/main/java/org/apache/camel/kit/command/InitCommand.java
@@ -223,6 +223,7 @@ public class InitCommand extends CamelKitCommand {
                 case MOVE -> green("move    ");
                 case CREATE -> green("create  ");
                 case REFRESH -> green("replace ");
+                case RESET_TOOLS -> green("reset tool lists");
                 case MERGE -> green("merge   ");
                 case REMOVE -> green("remove  ");
                 case PRESERVE -> yellow("preserve");
@@ -239,6 +240,9 @@ public class InitCommand extends CamelKitCommand {
             printer().println("  " + unchanged + " unchanged catalog files");
         }
         printer().println(dim("  merge: Camel Kit's block or servers are added 
and your content is kept."));
+        if (changes.stream().anyMatch(change -> change.action() == 
ManagedFiles.Action.RESET_TOOLS))
+            printer().println(dim(
+                    "  reset tool lists: restore Kit's current allowlists and 
keep explicit deny lists and unrelated servers."));
         printer().println(
                 dim("  preserve: the file stays as it is. Use --replace <path> 
to accept a file or the selected assets in a catalog directory."));
         printer().println(dim(
diff --git 
a/kit/camel-kit-core/src/main/java/org/apache/camel/kit/command/ship/ShipRuntime.java
 
b/kit/camel-kit-core/src/main/java/org/apache/camel/kit/command/ship/ShipRuntime.java
index ba353289..df7ecefe 100644
--- 
a/kit/camel-kit-core/src/main/java/org/apache/camel/kit/command/ship/ShipRuntime.java
+++ 
b/kit/camel-kit-core/src/main/java/org/apache/camel/kit/command/ship/ShipRuntime.java
@@ -1,19 +1,17 @@
 package org.apache.camel.kit.command.ship;
 
-import java.io.File;
 import java.io.IOException;
-import java.nio.file.Files;
 import java.nio.file.Path;
 import java.time.Duration;
 import java.util.List;
 import java.util.Locale;
 import java.util.Objects;
-import java.util.Optional;
 
 import org.apache.camel.kit.config.DistributionConfig;
 import org.apache.camel.kit.ship.context.ShipContext;
 import org.apache.camel.kit.ship.controller.ShipCoordinator;
 import org.apache.camel.kit.ship.controller.ShipRun;
+import org.apache.camel.kit.util.ProcessRunner;
 
 /**
  * Resolves the local Pi runtime and builds the coordinator-backed workflow.
@@ -106,31 +104,9 @@ final class ShipRuntime implements 
ShipCommand.WorkflowLauncher {
         if (configured != null) {
             return configured;
         }
-        return findOnPath(searchPath, name).orElseThrow(() -> new 
IllegalArgumentException(
+        return ProcessRunner.findOnPath(searchPath, name).orElseThrow(() -> 
new IllegalArgumentException(
                 label + " is missing or not executable; install " + label
-                                                                               
            + " and configure its executable path"));
-    }
-
-    static Optional<Path> findOnPath(String searchPath, String name) {
-        if (searchPath == null || searchPath.isBlank()) {
-            return Optional.empty();
-        }
-        for (String entry : searchPath.split(File.pathSeparator, -1)) {
-            if (entry.isBlank()) {
-                continue;
-            }
-            Path directory = Path.of(entry);
-            // Relative PATH entries would resolve against the current 
(possibly untrusted)
-            // project directory; never discover a stage executable there.
-            if (!directory.isAbsolute()) {
-                continue;
-            }
-            Path candidate = directory.resolve(name);
-            if (Files.isRegularFile(candidate) && 
Files.isExecutable(candidate)) {
-                return Optional.of(candidate);
-            }
-        }
-        return Optional.empty();
+                                                                               
                          + " and configure its executable path"));
     }
 
     // Native dispatch does not broaden the controller's validation and 
lifecycle platform support.
diff --git 
a/kit/camel-kit-core/src/main/java/org/apache/camel/kit/config/CamelCli.java 
b/kit/camel-kit-core/src/main/java/org/apache/camel/kit/config/CamelCli.java
index 24135bfb..44ee9707 100644
--- a/kit/camel-kit-core/src/main/java/org/apache/camel/kit/config/CamelCli.java
+++ b/kit/camel-kit-core/src/main/java/org/apache/camel/kit/config/CamelCli.java
@@ -149,7 +149,7 @@ public record CamelCli(String mode, String executable) {
             probe = probeLauncher(launcher);
             requested = detect(probe.output(), probe.succeeded());
             if (requested == null && System.getenv("CAMEL_KIT_LAUNCHER") == 
null
-                    && ProcessRunner.findOnPath("camel") == null) {
+                    && ProcessRunner.findOnPath(System.getenv("PATH"), 
"camel").isEmpty()) {
                 requested = "jbang";
             }
         }
diff --git 
a/kit/camel-kit-core/src/main/java/org/apache/camel/kit/generator/CodexConfigMerger.java
 
b/kit/camel-kit-core/src/main/java/org/apache/camel/kit/generator/CodexConfigMerger.java
index bd3a6b41..4342468a 100644
--- 
a/kit/camel-kit-core/src/main/java/org/apache/camel/kit/generator/CodexConfigMerger.java
+++ 
b/kit/camel-kit-core/src/main/java/org/apache/camel/kit/generator/CodexConfigMerger.java
@@ -5,6 +5,7 @@ import java.nio.file.Files;
 import java.nio.file.LinkOption;
 import java.nio.file.Path;
 import java.util.List;
+import java.util.function.Consumer;
 
 import org.tomlj.Toml;
 import org.tomlj.TomlParseResult;
@@ -14,7 +15,10 @@ final class CodexConfigMerger {
 
     private final boolean resetTools;
 
-    CodexConfigMerger(boolean resetTools) {
+    private final Consumer<String> narrowerList;
+
+    CodexConfigMerger(boolean resetTools, Consumer<String> narrowerList) {
+        this.narrowerList = narrowerList;
         this.resetTools = resetTools;
     }
 
@@ -125,6 +129,8 @@ final class CodexConfigMerger {
             var allowed = next.getArray(key + ".enabled_tools").toList();
             var enabled = !resetTools && source.get("enabled_tools") 
instanceof org.tomlj.TomlArray tools
                     ? tools.toList() : allowed;
+            if (allowed.containsAll(enabled) && !enabled.containsAll(allowed))
+                narrowerList.accept(name);
             if (allowed.equals(enabled) && source.get("disabled_tools") == null
                     && !Boolean.FALSE.equals(source.get("enabled"))) {
                 continue;
diff --git 
a/kit/camel-kit-core/src/main/java/org/apache/camel/kit/generator/ManagedFiles.java
 
b/kit/camel-kit-core/src/main/java/org/apache/camel/kit/generator/ManagedFiles.java
index 48364438..3ea79a1b 100644
--- 
a/kit/camel-kit-core/src/main/java/org/apache/camel/kit/generator/ManagedFiles.java
+++ 
b/kit/camel-kit-core/src/main/java/org/apache/camel/kit/generator/ManagedFiles.java
@@ -101,6 +101,8 @@ public final class ManagedFiles {
         MOVE,
         /** Camel-Kit's block is added to, or replaced inside, a file that 
also holds the user's content. */
         MERGE,
+        /** Merge managed MCP servers and restore the generated tool 
allowlists. */
+        RESET_TOOLS,
         /** The file belongs to the user and is left untouched. */
         PRESERVE,
         /** A file retired from the catalog still matches the installed 
content. */
@@ -631,7 +633,7 @@ public final class ManagedFiles {
         return unused;
     }
 
-    boolean requestedMcpTools(String configPath) {
+    public boolean requestedMcpTools(String configPath) {
         if (!replace.contains(configPath))
             return false;
         usedReplacements.add(configPath);
diff --git 
a/kit/camel-kit-core/src/main/java/org/apache/camel/kit/generator/McpConfigGenerator.java
 
b/kit/camel-kit-core/src/main/java/org/apache/camel/kit/generator/McpConfigGenerator.java
index 7ce587b0..a94b1d97 100644
--- 
a/kit/camel-kit-core/src/main/java/org/apache/camel/kit/generator/McpConfigGenerator.java
+++ 
b/kit/camel-kit-core/src/main/java/org/apache/camel/kit/generator/McpConfigGenerator.java
@@ -4,6 +4,7 @@ import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.LinkOption;
 import java.nio.file.Path;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 
@@ -39,8 +40,9 @@ class McpConfigGenerator {
             }
             String processed = render(ctx, workflow);
             boolean resetTools = 
ctx.files().requestedMcpTools(ctx.agent().mcpConfigPath());
+            var narrowed = new LinkedHashSet<String>();
             if ("toml".equals(ctx.agent().mcpConfigFormat())) {
-                new CodexConfigMerger(resetTools).merge(configFile, processed, 
ctx.withCitrusMcp());
+                new CodexConfigMerger(resetTools, 
narrowed::add).merge(configFile, processed, ctx.withCitrusMcp());
             } else if ("opencode".equals(ctx.agentName())) {
                 new OpenCodeConfigMerger().merge(configFile, processed, 
ctx.withCitrusMcp());
             } else {
@@ -58,9 +60,14 @@ class McpConfigGenerator {
                                 "tools")) {
                             JsonNode allowed = server.path(field);
                             JsonNode selected = previous.path(field);
-                            if (!resetTools && allowed.isArray() && 
selected.isArray() && allowed.valueStream().toList()
-                                    
.containsAll(selected.valueStream().toList())) {
+                            if (resetTools || !allowed.isArray() || 
!selected.isArray())
+                                continue;
+                            var defaults = allowed.valueStream().toList();
+                            var previousTools = 
selected.valueStream().toList();
+                            if (defaults.containsAll(previousTools)) {
                                 server.set(field, selected);
+                                if (!previousTools.containsAll(defaults))
+                                    narrowed.add(entry.getKey());
                             }
                         }
                         for (String field : List.of("excludeTools", 
"disabledTools")) {
@@ -106,6 +113,10 @@ class McpConfigGenerator {
                 }
             }
 
+            for (String name : narrowed) {
+                ctx.printer().println("Kept narrower MCP tool list for '" + 
name + "'. Use --force --replace "
+                                      + ctx.agent().mcpConfigPath() + " to 
restore Kit's tool lists.");
+            }
             ctx.printer().println(AnsiColors.green("✓") + " MCP config created 
for " + ctx.agent().name());
         } catch (InvalidAgentConfigurationException e) {
             throw e;
@@ -125,7 +136,8 @@ class McpConfigGenerator {
     static void preflight(InitContext ctx) throws IOException {
         if ("toml".equals(ctx.agent().mcpConfigFormat())) {
             // The merge itself is checked, with the block initialization will 
write, not only the existing file.
-            new 
CodexConfigMerger(ctx.files().requestedMcpTools(ctx.agent().mcpConfigPath())).validate(
+            new 
CodexConfigMerger(ctx.files().requestedMcpTools(ctx.agent().mcpConfigPath()), 
name -> {
+            }).validate(
                     ctx.projectDir().resolve(ctx.agent().mcpConfigPath()),
                     render(ctx, WorkflowManifestLoader.loadDefault()), 
ctx.withCitrusMcp());
         } else if (!"opencode".equals(ctx.agentName())) {
diff --git 
a/kit/camel-kit-core/src/main/java/org/apache/camel/kit/service/InitService.java
 
b/kit/camel-kit-core/src/main/java/org/apache/camel/kit/service/InitService.java
index 1324ab8f..d9433476 100644
--- 
a/kit/camel-kit-core/src/main/java/org/apache/camel/kit/service/InitService.java
+++ 
b/kit/camel-kit-core/src/main/java/org/apache/camel/kit/service/InitService.java
@@ -109,7 +109,9 @@ public class InitService {
         }
         Path mcpConfig = targetDir.resolve(agent.mcpConfigPath());
         changes.add(change(targetDir, mcpConfig,
-                Files.exists(mcpConfig) ? ManagedFiles.Action.MERGE : 
ManagedFiles.Action.CREATE));
+                !Files.exists(mcpConfig) ? ManagedFiles.Action.CREATE
+                        : files.requestedMcpTools(agent.mcpConfigPath()) ? 
ManagedFiles.Action.RESET_TOOLS
+                        : ManagedFiles.Action.MERGE));
         return changes;
     }
 
diff --git 
a/kit/camel-kit-core/src/main/java/org/apache/camel/kit/util/ProcessRunner.java 
b/kit/camel-kit-core/src/main/java/org/apache/camel/kit/util/ProcessRunner.java
index 1ceda7a7..3bc533f1 100644
--- 
a/kit/camel-kit-core/src/main/java/org/apache/camel/kit/util/ProcessRunner.java
+++ 
b/kit/camel-kit-core/src/main/java/org/apache/camel/kit/util/ProcessRunner.java
@@ -1,11 +1,16 @@
 package org.apache.camel.kit.util;
 
 import java.io.BufferedReader;
+import java.io.File;
 import java.io.InputStreamReader;
 import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.InvalidPathException;
 import java.nio.file.Path;
 import java.time.Duration;
+import java.util.List;
 import java.util.Objects;
+import java.util.Optional;
 
 /**
  * Runs short-lived external commands with timeout-bound output capture.
@@ -31,13 +36,12 @@ public final class ProcessRunner {
 
         Process process = null;
         try {
-            if (java.io.File.separatorChar == '\\' && 
Path.of(command[0]).getNameCount() == 1
-                    && !Path.of(command[0]).isAbsolute()) {
-                Path file = findOnPath(command[0]);
-                if (file != null) {
-                    command = command.clone();
-                    command[0] = file.toString();
-                }
+            if (Path.of(command[0]).getParent() == null && 
Path.of(command[0]).getRoot() == null) {
+                var file = findOnPath(System.getenv("PATH"), command[0]);
+                if (file.isEmpty())
+                    return new Result(false, -1, "");
+                command = command.clone();
+                command[0] = file.get().toString();
             }
             ProcessBuilder pb = new ProcessBuilder(command);
             pb.environment().putAll(environment);
@@ -68,24 +72,29 @@ public final class ProcessRunner {
         }
     }
 
-    public static Path findOnPath(String command) {
-        boolean windows = java.io.File.separatorChar == '\\';
+    public static Optional<Path> findOnPath(String searchPath, String command) 
{
+        if (searchPath == null || searchPath.isBlank())
+            return Optional.empty();
+        boolean windows = File.separatorChar == '\\';
         var suffixes = windows && !command.contains(".")
-                ? java.util.List.of(".exe", ".cmd", ".bat", ".com") : 
java.util.List.of("");
-        for (String entry : System.getenv().getOrDefault("PATH", 
"").split(java.io.File.pathSeparator, -1)) {
+                ? List.of(".exe", ".cmd", ".bat", ".com") : List.of("");
+        for (String entry : searchPath.split(File.pathSeparator, -1)) {
             try {
                 Path directory = Path.of(entry);
+                // Resolve bare commands only in absolute PATH directories.
+                if (!directory.isAbsolute())
+                    continue;
                 for (String suffix : suffixes) {
                     Path candidate = directory.resolve(command + suffix);
-                    if (java.nio.file.Files.isRegularFile(candidate)
-                            && (windows || 
java.nio.file.Files.isExecutable(candidate)))
-                        return candidate.toAbsolutePath();
+                    if (Files.isRegularFile(candidate)
+                            && (windows || Files.isExecutable(candidate)))
+                        return Optional.of(candidate);
                 }
-            } catch (java.nio.file.InvalidPathException ignored) {
+            } catch (InvalidPathException ignored) {
                 // An invalid PATH entry does not invalidate the remaining 
search locations.
             }
         }
-        return null;
+        return Optional.empty();
     }
 
     private static void drain(Process process, StringBuffer output) {
diff --git 
a/kit/camel-kit-core/src/main/resources/skills/camel-test/guides/test-runner.md 
b/kit/camel-kit-core/src/main/resources/skills/camel-test/guides/test-runner.md
index f477188e..1c8f3615 100644
--- 
a/kit/camel-kit-core/src/main/resources/skills/camel-test/guides/test-runner.md
+++ 
b/kit/camel-kit-core/src/main/resources/skills/camel-test/guides/test-runner.md
@@ -37,9 +37,11 @@ target build or Kit profile. Require exact numeric release 
versions before using
 When `camel.cli=launcher`, start a Main integration with its approved, 
version-checked run script.
 For Spring Boot and Quarkus keep the target's existing Maven build and startup 
procedure.
 Wait for the expected route to start. Generate a container-free test against 
that running route. Keep its assertions
-and stop the process you started in a finally block, including on test 
failure. On Linux the Citrus `camel:jbang:run` action loses the Launcher JAR 
arguments
-in its shell adapter. This was verified with 5.0.1, 5.0.2, 5.1.0 and 5.2.1. 
Mark an existing test
-with those lifecycle actions unverified and report the limitation. For later 
or untested Citrus releases, keep
+and stop the process you started in a finally block, including on test failure.
+
+On Linux the Citrus `camel:jbang:run` action loses the Launcher JAR arguments 
in its shell adapter.
+This was verified with 5.0.1, 5.0.2, 5.1.0 and 5.2.1. Mark existing tests with 
those lifecycle actions
+unverified and report the limitation. For later or untested Citrus releases, 
keep
 the route external until a test on that exact release starts it through 
Launcher, observes its output and fails
 when the expected output is absent. Do not silently remove actions from a test.
 
diff --git 
a/kit/camel-kit-core/src/test/java/org/apache/camel/kit/command/InitCommandTest.java
 
b/kit/camel-kit-core/src/test/java/org/apache/camel/kit/command/InitCommandTest.java
index 2660ecd7..3728508b 100644
--- 
a/kit/camel-kit-core/src/test/java/org/apache/camel/kit/command/InitCommandTest.java
+++ 
b/kit/camel-kit-core/src/test/java/org/apache/camel/kit/command/InitCommandTest.java
@@ -269,6 +269,36 @@ class InitCommandTest {
         assertTrue(rejected.output().contains("Cannot replace 'pom.xml'"), 
rejected.output());
     }
 
+    @Test
+    void 
reinitializationReportsNarrowedToolsAndPreviewsAnExplicitReset(@TempDir Path 
project) throws Exception {
+        var output = new CapturingPrinter();
+        var init = initCommand(project, output);
+        init.ai = "qwen";
+        assertEquals(0, init.doCall(), output.output());
+        String relative = ".qwen/settings.json";
+        Path file = project.resolve(relative);
+        var json = new com.fasterxml.jackson.databind.ObjectMapper();
+        var config = json.readTree(file.toFile());
+        ((com.fasterxml.jackson.databind.node.ArrayNode) 
config.at("/mcpServers/camel/includeTools")).remove(0);
+        json.writeValue(file.toFile(), config);
+        var regenerate = initCommand(project, output);
+        regenerate.ai = "qwen";
+        regenerate.force = true;
+        assertEquals(0, regenerate.doCall(), output.output());
+        assertTrue(output.output().contains("Kept narrower MCP tool list for 
'camel'"), output.output());
+        var before = Files.readString(file);
+        var preview = initCommand(project, output);
+        preview.ai = "qwen";
+        preview.force = true;
+        preview.replace = java.util.List.of(relative);
+        preview.dryRun = true;
+        assertEquals(0, preview.doCall(), output.output());
+        assertTrue(
+                output.output().lines().anyMatch(line -> line.contains("reset 
tool lists") && line.contains(relative)),
+                output.output());
+        assertEquals(before, Files.readString(file));
+    }
+
     private static InitCommand initCommand(Path project, CapturingPrinter 
printer) {
         CamelKitMain main = new CamelKitMain() {
             @Override
diff --git 
a/kit/camel-kit-core/src/test/java/org/apache/camel/kit/command/ship/ShipRuntimeTest.java
 
b/kit/camel-kit-core/src/test/java/org/apache/camel/kit/command/ship/ShipRuntimeTest.java
index 210cd5d8..817a9675 100644
--- 
a/kit/camel-kit-core/src/test/java/org/apache/camel/kit/command/ship/ShipRuntimeTest.java
+++ 
b/kit/camel-kit-core/src/test/java/org/apache/camel/kit/command/ship/ShipRuntimeTest.java
@@ -9,6 +9,8 @@ import java.time.Duration;
 import java.util.List;
 import java.util.Optional;
 
+import org.apache.camel.kit.util.ProcessRunner;
+
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.condition.EnabledOnOs;
 import org.junit.jupiter.api.condition.OS;
@@ -70,7 +72,7 @@ class ShipRuntimeTest {
         String searchPath = String.join(File.pathSeparator,
                 first.toString(), "", second.toString());
 
-        Optional<Path> found = ShipRuntime.findOnPath(searchPath, "pi");
+        Optional<Path> found = ProcessRunner.findOnPath(searchPath, "pi");
 
         assertEquals(Optional.of(second.resolve("pi")), found);
     }
@@ -83,15 +85,15 @@ class ShipRuntimeTest {
         Files.setPosixFilePermissions(
                 directory.resolve("pi"), 
PosixFilePermissions.fromString("rw-------"));
 
-        assertEquals(Optional.empty(), 
ShipRuntime.findOnPath(directory.toString(), "pi"));
+        assertEquals(Optional.empty(), 
ProcessRunner.findOnPath(directory.toString(), "pi"));
     }
 
     @Test
     void returnsEmptyForMissingOrBlankSearchPaths() {
-        assertEquals(Optional.empty(), ShipRuntime.findOnPath(null, "pi"));
-        assertEquals(Optional.empty(), ShipRuntime.findOnPath("  ", "pi"));
+        assertEquals(Optional.empty(), ProcessRunner.findOnPath(null, "pi"));
+        assertEquals(Optional.empty(), ProcessRunner.findOnPath("  ", "pi"));
         assertEquals(Optional.empty(),
-                ShipRuntime.findOnPath(tempDir.resolve("absent").toString(), 
"pi"));
+                ProcessRunner.findOnPath(tempDir.resolve("absent").toString(), 
"pi"));
     }
 
     @Test
@@ -101,10 +103,10 @@ class ShipRuntimeTest {
         writeExecutable(relative.resolve("pi"));
         String relativeEntry = 
Path.of("").toAbsolutePath().relativize(relative).toString();
 
-        assertEquals(Optional.empty(), ShipRuntime.findOnPath(relativeEntry, 
"pi"),
+        assertEquals(Optional.empty(), ProcessRunner.findOnPath(relativeEntry, 
"pi"),
                 "relative PATH entries must never resolve against the working 
directory");
         assertEquals(Optional.of(relative.resolve("pi")),
-                ShipRuntime.findOnPath(relative.toString(), "pi"),
+                ProcessRunner.findOnPath(relative.toString(), "pi"),
                 "the same directory is discoverable through its absolute 
entry");
     }
 
diff --git 
a/kit/camel-kit-core/src/test/java/org/apache/camel/kit/config/CamelCliTest.java
 
b/kit/camel-kit-core/src/test/java/org/apache/camel/kit/config/CamelCliTest.java
index deb3de9b..76749571 100644
--- 
a/kit/camel-kit-core/src/test/java/org/apache/camel/kit/config/CamelCliTest.java
+++ 
b/kit/camel-kit-core/src/test/java/org/apache/camel/kit/config/CamelCliTest.java
@@ -5,6 +5,8 @@ import java.nio.file.Path;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
 
+import org.apache.camel.kit.util.ProcessRunner;
+
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.condition.EnabledOnOs;
 import org.junit.jupiter.api.condition.OS;
@@ -78,12 +80,14 @@ class CamelCliTest {
     @Test
     @org.junit.jupiter.api.Tag("cli-compat")
     @EnabledOnOs(OS.WINDOWS)
-    void invalidPathEntryDoesNotHideJava() throws Exception {
+    void mixedCaseWindowsPathSkipsInvalidEntriesAndFindsCommandShims() throws 
Exception {
         Path bin = Path.of(System.getProperty("java.home"), "bin");
+        Files.writeString(root.resolve("kit-probe.cmd"), "@echo off\r\necho 
shim-found\r\n");
         var cmd = new ProcessBuilder(
                 bin.resolve("java.exe").toString(), "-cp", 
System.getProperty("java.class.path"),
-                getClass().getName(), 
"--probe-java").redirectErrorStream(true);
-        cmd.environment().put("PATH", "\"bad\";" + bin);
+                getClass().getName(), 
"--probe-shim").redirectErrorStream(true);
+        cmd.environment().keySet().removeIf(key -> 
key.equalsIgnoreCase("PATH"));
+        cmd.environment().put("Path", "\"bad\";.;" + root);
         var process = cmd.start();
         assertTrue(process.waitFor(30, TimeUnit.SECONDS));
         assertEquals(0, process.exitValue());
@@ -111,8 +115,9 @@ class CamelCliTest {
     }
 
     public static void main(String[] args) throws Exception {
-        if ("--probe-java".equals(args[0])) {
-            System.exit(CamelCli.sourceLauncherAvailable() ? 0 : 1);
+        if ("--probe-shim".equals(args[0])) {
+            var result = ProcessRunner.run(java.time.Duration.ofSeconds(5), 
"kit-probe");
+            System.exit(result.succeeded() && 
"shim-found".equals(result.output()) ? 0 : 1);
         }
         System.out.println(CamelCli.select(Path.of(args[0]), args.length > 1 ? 
args[1] : null, "camel-kit").mode());
     }

Reply via email to