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 ecb707670ee3f5b5e0581dac4dceadc89504bb80
Author: Luigi De Masi <[email protected]>
AuthorDate: Tue Nov 24 09:47:16 2026 +0100

    Fix #196: Place the shared protocol after the last hook command
    
    Keep the protocol adjacent to the last hook at each contribution point
    while preserving the order of interleaved and trailing guidance. Cover
    the installed instruction order with the two-hook catalog fixture.
    
    Co-authored-by: OpenAI Codex <[email protected]>
---
 .../apache/camel/kit/workflow/SkillPackCompiler.java    | 17 +++++++++--------
 .../camel/kit/workflow/SkillPackCompilerTest.java       | 11 ++++++++---
 2 files changed, 17 insertions(+), 11 deletions(-)

diff --git 
a/kit/camel-kit-core/src/main/java/org/apache/camel/kit/workflow/SkillPackCompiler.java
 
b/kit/camel-kit-core/src/main/java/org/apache/camel/kit/workflow/SkillPackCompiler.java
index b97bd7e1..657b289d 100644
--- 
a/kit/camel-kit-core/src/main/java/org/apache/camel/kit/workflow/SkillPackCompiler.java
+++ 
b/kit/camel-kit-core/src/main/java/org/apache/camel/kit/workflow/SkillPackCompiler.java
@@ -92,7 +92,7 @@ public final class SkillPackCompiler {
         Map<String, byte[]> files = new TreeMap<>();
         Map<String, SkillCatalog.Binding> bindings = new TreeMap<>();
         Map<String, List<String>> steps = new TreeMap<>();
-        var hookPoints = new TreeSet<String>();
+        Map<String, Integer> protocolPositions = new HashMap<>();
         Map<String, String> stageSkills = new HashMap<>();
         workflow.stages().forEach(stage -> stageSkills.put(stage.id(), 
stage.skill()));
         for (Declaration d : entries.values()) {
@@ -110,13 +110,14 @@ public final class SkillPackCompiler {
                     }
                     path = skill + "/SKILL.md";
                     String point = parts[0] + "/" + parts[1];
-                    if (d.entry().hook() != null) {
-                        hookPoints.add(point);
+                    List<String> instructions = steps.computeIfAbsent(point, 
unused -> new ArrayList<>());
+                    WorkflowHook hook = d.entry().hook();
+                    if (hook == null) {
+                        instructions.add(new String(resources.get(d), 
StandardCharsets.UTF_8).strip());
+                    } else {
+                        instructions.add(hook.instructions(d.key()));
+                        protocolPositions.put(point, instructions.size());
                     }
-                    steps.computeIfAbsent(point, unused -> new ArrayList<>())
-                            .add(d.entry().hook() == null
-                                    ? new String(resources.get(d), 
StandardCharsets.UTF_8).strip()
-                                    : d.entry().hook().instructions(d.key()));
                 }
                 case "provider" -> path = null;
                 default -> throw d.error("unknown contribution kind");
@@ -138,7 +139,7 @@ public final class SkillPackCompiler {
                             d.entry().handles()));
         }
         WorkflowManifest effective = composeWorkflow(workflow, entries, 
definitions, steps);
-        hookPoints.forEach(point -> 
steps.get(point).add(WorkflowHook.PROTOCOL));
+        protocolPositions.forEach((point, position) -> 
steps.get(point).add(position, WorkflowHook.PROTOCOL));
         bindSteps(stageSkills, files, steps, entries);
         var manifest = new SkillCatalog.Manifest(1, 
List.copyOf(packs.keySet()), effective, bindings);
         return archive(new SkillCatalog(manifest, files, null));
diff --git 
a/kit/camel-kit-core/src/test/java/org/apache/camel/kit/workflow/SkillPackCompilerTest.java
 
b/kit/camel-kit-core/src/test/java/org/apache/camel/kit/workflow/SkillPackCompilerTest.java
index 9c1500e0..d7d337b3 100644
--- 
a/kit/camel-kit-core/src/test/java/org/apache/camel/kit/workflow/SkillPackCompilerTest.java
+++ 
b/kit/camel-kit-core/src/test/java/org/apache/camel/kit/workflow/SkillPackCompilerTest.java
@@ -1084,7 +1084,7 @@ class SkillPackCompilerTest {
     }
 
     @Test
-    void twoHooksAtOnePointShareTheInvocationProtocol() throws Exception {
+    void sharedProtocolImmediatelyFollowsTheLastHookAtThePoint() throws 
Exception {
         String second = "step/validate/report/second";
         Path addon = pack("more", """
                 requires: [report-review]
@@ -1106,8 +1106,13 @@ class SkillPackCompilerTest {
         }
         try (var loader = loader(temp)) {
             String stage = content(SkillCatalog.load(loader), 
"camel-validate/SKILL.md");
-            assertTrue(stage.contains("hook --id " + COVERAGE));
-            assertTrue(stage.contains("hook --id " + second));
+            var paragraphs = List.of(stage.split("\n\n"));
+            int protocol = paragraphs.indexOf(WorkflowHook.PROTOCOL);
+            assertTrue(protocol >= 3 && protocol + 1 < paragraphs.size(), 
"Missing protocol or surrounding steps");
+            assertTrue(paragraphs.get(protocol - 3).contains("hook --id " + 
COVERAGE));
+            assertTrue(paragraphs.get(protocol - 2).startsWith(REVIEW));
+            assertTrue(paragraphs.get(protocol - 1).contains("hook --id " + 
second));
+            assertTrue(paragraphs.get(protocol + 1).startsWith("Use the 
current date and time"));
             String pathHelp = "open `request.implementation` relative to the 
host's installed skills directory";
             assertTrue(stage.contains(pathHelp));
             assertEquals(stage.indexOf(pathHelp), stage.lastIndexOf(pathHelp));

Reply via email to