gnodet-bot commented on code in PR #27995:
URL: https://github.com/apache/camel/pull/27995#discussion_r4301706991


##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Init.java:
##########
@@ -232,10 +236,42 @@ private int execute() throws Exception {
                 Files.createDirectories(parentPath);
             }
         }
+        if (existsAlready(targetPath)) {

Review Comment:
   ⚠️ **Behavioral gap:** This `existsAlready()` check now gates `execute()`, 
but the interactive template picker (pre-existing, around line 386) calls 
`execute()` without any mechanism to set `--force`. Interactive users who 
encounter an existing file will get a `FAILURE` exit with no escape hatch in 
the same session. Consider prompting (`overwrite? [y/N]`) or threading `force` 
through the interactive path.



##########
dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/InitTest.java:
##########
@@ -196,6 +196,32 @@ void initPipe() throws Exception {
         
assertTrue(Files.readString(workingDir.resolve("my.yaml")).contains("kind: 
Pipe"));
     }
 
+    @Test
+    void initFailsWhenTheFileExists() throws Exception {
+        Path existing = Files.writeString(workingDir.resolve("my.camel.yaml"), 
"- route: {}");
+        StringPrinter printer = new StringPrinter();
+        Init initCommand = new Init(new CamelJBangMain().withPrinter(printer));
+        CommandLine.populateCommand(initCommand, "my.camel.yaml", "--dir=" + 
workingDir);
+
+        int exit = initCommand.doCall();
+
+        assertEquals(1, exit);
+        assertEquals("ERROR: File already exists: " + existing + " (use 
--force to overwrite it)", printer.getStderr());
+        assertEquals("- route: {}", Files.readString(existing), "the file is 
kept as it was");
+    }
+
+    @Test
+    void initForceOverwritesTheFile() throws Exception {

Review Comment:
   ⚠️ **Incomplete test:** This test would pass identically on the pre-PR 
codebase, because `execute()` previously had no guard and always called 
`Files.writeString()` unconditionally. The test does not prove that `--force` 
is specifically what enables the overwrite — it only proves the happy path 
works. Pair it with an assertion (or a sub-case) that running *without* 
`--force` on an existing file returns `1` and leaves the file unchanged — which 
is what `initFailsWhenTheFileExists` already covers. At minimum, document the 
pairing explicitly.



-- 
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]

Reply via email to