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 193030b3069121ea533107452196c07dd0ed332d
Author: Luigi De Masi <[email protected]>
AuthorDate: Mon Nov 23 17:21:42 2026 +0100

    Fix #193: Report actionable workspace configuration errors
    
    Identify denied reads of properties, legacy YAML and the ownership ledger.
    When Doctor cannot load the configuration, report that failure once and
    continue the checks that can run independently. Preserve the published
    upgrade link when the section heading changes.
    
    Co-authored-by: OpenAI Codex <[email protected]>
---
 docs/modules/ROOT/pages/getting-started.adoc       |  4 ++
 .../InvalidAgentConfigurationException.java        |  7 +++
 .../apache/camel/kit/generator/ManagedFiles.java   |  2 +-
 .../camel/kit/generator/ReleasedCatalog.java       |  2 +-
 .../apache/camel/kit/service/DoctorService.java    | 54 ++++++++++++++--------
 .../camel/kit/command/DoctorCommandTest.java       | 34 +++++++++++++-
 .../camel/kit/service/InitSafeAdoptionTest.java    | 28 +++++++++++
 7 files changed, 108 insertions(+), 23 deletions(-)

diff --git a/docs/modules/ROOT/pages/getting-started.adoc 
b/docs/modules/ROOT/pages/getting-started.adoc
index df4e18bd..edc1eff9 100644
--- a/docs/modules/ROOT/pages/getting-started.adoc
+++ b/docs/modules/ROOT/pages/getting-started.adoc
@@ -263,12 +263,14 @@ regular file. On reinitialization, properties you added 
to `.camel-kit/config.pr
 Camel Kit records the hash of each tracked file it wrote in 
`.camel-kit/managed-files.properties`; commit it with
 the project.
 
+[[_upgrading_from_0_4_1_and_earlier]]
 ==== Upgrading from 0.4.1 and earlier
 
 If the workspace has lost its Kit configuration, restore the original from 
version control or a backup *before*
 the first upgrade. Releases 0.4.x used `.camel-kit/config.properties`. Earlier 
releases used `.camel-kit/config.yaml`.
 When both files exist, Kit reads the properties file. If the active file is 
malformed, both `--dry-run` and `init`
 report the path before writing anything. Repair or restore that file and retry.
+If Kit reports a permission error reading the configuration or the ledger, 
restore read access to the named file and retry.
 
 From the project root, run `camel-kit init --here --ai claude --force`, 
substituting your assistant's name.
 In a shared workspace, run this command once for each assistant, in any order.
@@ -382,6 +384,8 @@ camel-kit doctor --json   # for automation
 permission fields, the project graph, the command prefix, the prerequisites 
and common stale generated references. It
 prints `PASS`, `WARN` and `FAIL` findings with remediation text. Missing 
external tools such as JBang are warnings;
 broken generated workspace files are failures.
+If Doctor cannot load the workspace configuration, it reports the cause and 
still checks the graph, prerequisites
+and stale references in project-level instructions.
 
 [[first-command]]
 == Run the first command
diff --git 
a/kit/camel-kit-core/src/main/java/org/apache/camel/kit/generator/InvalidAgentConfigurationException.java
 
b/kit/camel-kit-core/src/main/java/org/apache/camel/kit/generator/InvalidAgentConfigurationException.java
index 72b31091..9c07b4ae 100644
--- 
a/kit/camel-kit-core/src/main/java/org/apache/camel/kit/generator/InvalidAgentConfigurationException.java
+++ 
b/kit/camel-kit-core/src/main/java/org/apache/camel/kit/generator/InvalidAgentConfigurationException.java
@@ -19,6 +19,13 @@ public final class InvalidAgentConfigurationException 
extends IOException {
         super(message, cause);
     }
 
+    static InvalidAgentConfigurationException cannotRead(Path file, Exception 
cause) {
+        String message = cause instanceof AccessDeniedException
+                ? "Permission denied reading " + file + ". Restore read access 
and retry."
+                : "Cannot read " + file + ": " + cause.getMessage();
+        return new InvalidAgentConfigurationException(message, cause);
+    }
+
     public static InvalidAgentConfigurationException 
unreadableDirectory(AccessDeniedException cause) {
         String path = cause.getFile();
         Path parent = path == null ? null : Path.of(path).getParent();
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 301adca2..9f8666fe 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
@@ -196,7 +196,7 @@ public final class ManagedFiles {
                 }
             }
         } catch (IOException | IllegalArgumentException e) {
-            throw new InvalidAgentConfigurationException("Cannot read " + 
ledgerFile + ": " + e.getMessage(), e);
+            throw InvalidAgentConfigurationException.cannotRead(ledgerFile, e);
         }
         // Validate the configuration before any writes, even when the ledger 
already records first adoption.
         boolean configured = agentName != null && 
ReleasedCatalog.hasWorkspaceConfiguration(root);
diff --git 
a/kit/camel-kit-core/src/main/java/org/apache/camel/kit/generator/ReleasedCatalog.java
 
b/kit/camel-kit-core/src/main/java/org/apache/camel/kit/generator/ReleasedCatalog.java
index 4249b6e0..fc83879d 100644
--- 
a/kit/camel-kit-core/src/main/java/org/apache/camel/kit/generator/ReleasedCatalog.java
+++ 
b/kit/camel-kit-core/src/main/java/org/apache/camel/kit/generator/ReleasedCatalog.java
@@ -52,7 +52,7 @@ final class ReleasedCatalog {
                 return configuredAgent != null && !configuredAgent.isBlank();
             }
         } catch (IOException | IllegalArgumentException e) {
-            throw new InvalidAgentConfigurationException("Cannot read " + 
config + ": " + e.getMessage(), e);
+            throw InvalidAgentConfigurationException.cannotRead(config, e);
         }
     }
 
diff --git 
a/kit/camel-kit-core/src/main/java/org/apache/camel/kit/service/DoctorService.java
 
b/kit/camel-kit-core/src/main/java/org/apache/camel/kit/service/DoctorService.java
index ede9ab2b..073bc35d 100644
--- 
a/kit/camel-kit-core/src/main/java/org/apache/camel/kit/service/DoctorService.java
+++ 
b/kit/camel-kit-core/src/main/java/org/apache/camel/kit/service/DoctorService.java
@@ -3,8 +3,11 @@ package org.apache.camel.kit.service;
 import java.io.IOException;
 import java.io.InputStream;
 import java.nio.charset.StandardCharsets;
+import java.nio.file.AccessDeniedException;
 import java.nio.file.Files;
+import java.nio.file.NoSuchFileException;
 import java.nio.file.Path;
+import java.nio.file.attribute.BasicFileAttributes;
 import java.time.Duration;
 import java.util.ArrayList;
 import java.util.LinkedHashMap;
@@ -74,11 +77,16 @@ public class DoctorService {
         List<DoctorFinding> findings = new ArrayList<>();
 
         Properties config = checkConfig(root, findings);
-        AgentConfig agent = checkAgentConfig(config, findings);
-        checkGeneratedWorkspace(root, agent, findings);
-        checkMcp(root, config, findings);
+        AgentConfig agent = null;
+        if (config != null) {
+            agent = checkAgentConfig(config, findings);
+            checkGeneratedWorkspace(root, agent, findings);
+            checkMcp(root, config, findings);
+        }
         checkGraph(root, findings);
-        checkCommandPrefix(config, findings);
+        if (config != null) {
+            checkCommandPrefix(config, findings);
+        }
         checkPrerequisites(root, findings);
         checkStaleReferences(root, agent, findings);
 
@@ -86,34 +94,40 @@ public class DoctorService {
     }
 
     private Properties checkConfig(Path root, List<DoctorFinding> findings) {
-        Path configFile = root.resolve(".camel-kit/config.properties");
-        if (!Files.isRegularFile(configFile)) {
-            findings.add(DoctorFinding.fail("config", relativize(root, 
configFile),
-                    ".camel-kit/config.properties is missing",
-                    "Restore any lost Kit configuration before upgrading an 
existing workspace. "
-                                                               + "Run 
camel-kit init --here --ai <agent> from the workspace root."));
-            return new Properties();
-        }
-
+        String path = ".camel-kit/config.properties";
+        Path configFile = root.resolve(path);
         Properties config = new Properties();
-        try (InputStream in = Files.newInputStream(configFile)) {
-            config.load(in);
+        try {
+            if (!Files.readAttributes(configFile, 
BasicFileAttributes.class).isRegularFile()) {
+                throw new IOException("Expected a regular file");
+            }
+            try (InputStream in = Files.newInputStream(configFile)) {
+                config.load(in);
+            }
+        } catch (NoSuchFileException e) {
+            findings.add(DoctorFinding.fail("config", path, path + " is 
missing",
+                    "Restore any lost Kit configuration before upgrading an 
existing workspace. "
+                                                                               
   + "Run camel-kit init --here --ai <agent> from the workspace root."));
+            return null;
+        } catch (AccessDeniedException e) {
+            findings.add(DoctorFinding.fail("config", path, "Permission denied 
reading " + path,
+                    "Restore read access and re-run camel-kit doctor."));
+            return null;
         } catch (IOException | IllegalArgumentException e) {
-            findings.add(DoctorFinding.fail("config", relativize(root, 
configFile),
-                    "Could not read .camel-kit/config.properties: " + 
e.getMessage(),
+            findings.add(DoctorFinding.fail("config", path, "Could not read " 
+ path + ": " + e.getMessage(),
                     "Repair the file or restore it from source control before 
running init."));
-            return new Properties();
+            return null;
         }
 
         List<String> missing = REQUIRED_CONFIG_KEYS.stream()
                 .filter(key -> config.getProperty(key, "").isBlank())
                 .toList();
         if (missing.isEmpty()) {
-            findings.add(DoctorFinding.pass("config", relativize(root, 
configFile),
+            findings.add(DoctorFinding.pass("config", path,
                     ".camel-kit/config.properties contains the required keys",
                     "No action required."));
         } else {
-            findings.add(DoctorFinding.fail("config", relativize(root, 
configFile),
+            findings.add(DoctorFinding.fail("config", path,
                     ".camel-kit/config.properties is missing keys: " + 
String.join(", ", missing),
                     "Restore the missing keys or re-run camel-kit init --here 
--ai <agent> --force."));
         }
diff --git 
a/kit/camel-kit-core/src/test/java/org/apache/camel/kit/command/DoctorCommandTest.java
 
b/kit/camel-kit-core/src/test/java/org/apache/camel/kit/command/DoctorCommandTest.java
index 871d57f7..7921d3c9 100644
--- 
a/kit/camel-kit-core/src/test/java/org/apache/camel/kit/command/DoctorCommandTest.java
+++ 
b/kit/camel-kit-core/src/test/java/org/apache/camel/kit/command/DoctorCommandTest.java
@@ -5,6 +5,7 @@ import java.nio.file.Path;
 import java.util.Collection;
 import java.util.List;
 import java.util.Locale;
+import java.util.Set;
 
 import org.apache.camel.kit.CamelKitMain;
 import org.apache.camel.kit.CommandRunner;
@@ -17,10 +18,13 @@ import org.apache.camel.kit.service.DoctorExpectations;
 
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.jupiter.api.Tag;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.io.TempDir;
 
 import static org.junit.jupiter.api.Assertions.*;
+import static org.junit.jupiter.api.Assumptions.assumeFalse;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
 
 class DoctorCommandTest {
 
@@ -78,7 +82,7 @@ class DoctorCommandTest {
         assertNotEquals(0, result.exitCode());
         JsonNode json = MAPPER.readTree(result.output());
         assertEquals("FAIL", json.get("status").asText());
-        assertTrue(json.get("summary").get("fail").asInt() > 0);
+        assertEquals(1, json.get("summary").get("fail").asInt(), 
result.output());
         assertTrue(hasFinding(json, "FAIL", "config",
                 ".camel-kit/config.properties is missing",
                 "Run camel-kit init --here --ai <agent>"), result.output());
@@ -91,14 +95,42 @@ class DoctorCommandTest {
     }
 
     @Test
+    @Tag("cli-compat")
     void malformedPropertiesProduceAnActionableJsonFinding() throws Exception {
         writeConfig("agent.name=bob2\nextra=\\u12x4\n");
+        Files.writeString(tempDir.resolve(".camel-kit/project-graph.json"), 
"{}");
         RunResult result = runDoctor("--project-dir", tempDir.toString(), 
"--json");
 
         assertEquals(1, result.exitCode());
         JsonNode json = MAPPER.readTree(result.output());
         assertTrue(hasFinding(json, "FAIL", "config", "Could not read 
.camel-kit/config.properties",
                 "restore it from source control"), result.output());
+        assertEquals(1, json.get("summary").get("fail").asInt(), 
result.output());
+        assertFalse(hasFinding(json, "WARN", "config", 
"project.command-prefix"), result.output());
+        assertTrue(hasFinding(json, "PASS", "graph"), result.output());
+        assertTrue(hasFinding(json, "PASS", "workspace", "stale resource 
references"), result.output());
+        
assertTrue(json.path("findings").findValuesAsText("category").contains("prerequisites"),
 result.output());
+    }
+
+    @Test
+    @Tag("cli-compat")
+    void unreadablePropertiesReportThePermissionAndRemedy() throws Exception {
+        
assumeTrue(Files.getFileStore(tempDir).supportsFileAttributeView("posix"));
+        writeConfig("agent.name=bob2\n");
+        Path config = tempDir.resolve(".camel-kit/config.properties");
+        var permissions = Files.getPosixFilePermissions(config);
+        try {
+            Files.setPosixFilePermissions(config, Set.of());
+            assumeFalse(Files.isReadable(config), "The current user can bypass 
read permissions");
+            RunResult result = runDoctor("--project-dir", tempDir.toString(), 
"--json");
+            assertEquals(1, result.exitCode());
+            JsonNode json = MAPPER.readTree(result.output());
+            assertEquals(1, json.get("summary").get("fail").asInt(), 
result.output());
+            assertTrue(hasFinding(json, "FAIL", "config", "Permission denied 
reading .camel-kit/config.properties",
+                    "Restore read access"), result.output());
+        } finally {
+            Files.setPosixFilePermissions(config, permissions);
+        }
     }
 
     @Test
diff --git 
a/kit/camel-kit-core/src/test/java/org/apache/camel/kit/service/InitSafeAdoptionTest.java
 
b/kit/camel-kit-core/src/test/java/org/apache/camel/kit/service/InitSafeAdoptionTest.java
index ebb9c6d3..f2900463 100644
--- 
a/kit/camel-kit-core/src/test/java/org/apache/camel/kit/service/InitSafeAdoptionTest.java
+++ 
b/kit/camel-kit-core/src/test/java/org/apache/camel/kit/service/InitSafeAdoptionTest.java
@@ -29,6 +29,8 @@ import org.junit.jupiter.params.provider.NullAndEmptySource;
 import org.junit.jupiter.params.provider.ValueSource;
 
 import static org.junit.jupiter.api.Assertions.*;
+import static org.junit.jupiter.api.Assumptions.assumeFalse;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
 
 /**
  * Initialization inside an existing application must not replace files the 
application already owns, and
@@ -213,6 +215,32 @@ class InitSafeAdoptionTest {
         assertEquals("André", settings.getProperty("team.owner"));
     }
 
+    @ParameterizedTest
+    @ValueSource(strings = {".camel-kit/config.properties", 
".camel-kit/config.yaml", ManagedFiles.LEDGER})
+    @Tag("cli-compat")
+    void 
deniedWorkspaceFileReadsExplainHowToRetryWithoutChangingTheProject(String 
relativePath) throws Exception {
+        
assumeTrue(Files.getFileStore(tempDir).supportsFileAttributeView("posix"));
+        Path file = tempDir.resolve(relativePath);
+        Files.createDirectories(file.getParent());
+        Files.createFile(file);
+        var original = snapshot(tempDir);
+        var permissions = Files.getPosixFilePermissions(file);
+        var service = new InitService();
+        var init = request(tempDir, "claude");
+        try {
+            Files.setPosixFilePermissions(file, Set.of());
+            assumeFalse(Files.isReadable(file), "The current user can bypass 
read permissions");
+            String expected = "Permission denied reading " + file + ". Restore 
read access and retry.";
+            assertEquals(expected, 
assertThrows(InvalidAgentConfigurationException.class,
+                    () -> service.preview(init)).getMessage());
+            assertEquals(expected, 
assertThrows(InvalidAgentConfigurationException.class,
+                    () -> service.initialize(init)).getMessage());
+        } finally {
+            Files.setPosixFilePermissions(file, permissions);
+        }
+        assertEquals(original, snapshot(tempDir));
+    }
+
     @ParameterizedTest
     @CsvSource({"config.properties, false", "config.yaml, false", 
"config.properties, true", "config.yaml, true"})
     @Tag("cli-compat")

Reply via email to