luigidemasi commented on code in PR #238:
URL: https://github.com/apache/camel-kit/pull/238#discussion_r4799067986


##########
kit/camel-kit-graph/src/test/java/org/apache/camel/kit/graph/GraphBuilderTest.java:
##########
@@ -237,6 +237,72 @@ void 
migrationParserReceivesOnlyMatchingFilesAndKeepsPartialDiagnostics(@TempDir
         assertEquals(0, empty.graph().nodeCount());
     }
 
+    @Test
+    void muleParserRegistrationWorksWhenMovedIntoPack() {
+        // Issue #200: Verify Mule parser works when registered through 
pack.yaml descriptor
+        // GraphBuilder loads parsers from the installed pack catalog 
(mule-migration-pack/pack.yaml)
+        // Test validates graph structure with real Mule 3.x and 4.x fixtures
+
+        // Test Mule 3.x fixture
+        GraphBuildResult mule3Result = new 
GraphBuilder().buildWithDiagnostics(TEST_PROJECT.resolve("mule3"));
+        assertTrue(mule3Result.successful(), mule3Result::failureSummary);
+        assertTrue(mule3Result.graph().hasNode("mule-flow:legacy-order-flow"),
+                "Mule 3 graph should contain legacy-order-flow");
+
+        ParserDiagnostic mule3Diagnostic = findDiagnostic(mule3Result, 
"MuleXmlFlowParser");
+        assertFalse(mule3Diagnostic.scannedFiles().isEmpty(),
+                "Parser diagnostic should identify scanned XML files");
+        assertTrue(mule3Diagnostic.scannedFiles().stream()
+                .anyMatch(f -> f.contains("legacy-flow.xml")),
+                "Parser diagnostic should identify legacy-flow.xml");
+
+        // Test Mule 4.x fixture
+        GraphBuildResult mule4Result = new 
GraphBuilder().buildWithDiagnostics(TEST_PROJECT.resolve("mule4"));
+        assertTrue(mule4Result.successful(), mule4Result::failureSummary);
+        
assertTrue(mule4Result.graph().hasNode("mule-subflow:enrich-order-subflow"),
+                "Mule 4 graph should contain enrich-order-subflow");
+        
assertTrue(mule4Result.graph().hasNode("mule-subflow:validate-order-subflow"),
+                "Mule 4 graph should contain validate-order-subflow");
+
+        // Verify that enrich-order-subflow calls validate-order-subflow
+        List<GraphEdge> refs = mule4Result.graph()
+                .getOutgoingEdges("mule-subflow:enrich-order-subflow").stream()
+                .filter(e -> 
e.to().equals("mule-subflow:validate-order-subflow"))
+                .toList();
+        assertFalse(refs.isEmpty(),
+                "enrich-order-subflow should call validate-order-subflow");
+
+        ParserDiagnostic mule4Diagnostic = findDiagnostic(mule4Result, 
"MuleXmlFlowParser");
+        assertFalse(mule4Diagnostic.scannedFiles().isEmpty(),
+                "Parser diagnostic should identify scanned XML files");
+        assertTrue(mule4Diagnostic.scannedFiles().stream()
+                .anyMatch(f -> f.contains("order-processing.xml")),
+                "Parser diagnostic should identify order-processing.xml");
+    }
+
+    @Test
+    void packYamlLoadingFailsWhenParserNotRegistered() {
+        // Per review feedback: Validate that parsers MUST come from pack.yaml 
registration.
+        // If you create a GraphBuilder without the Mule parser registered (no 
pack.yaml),
+        // then Mule files won't be parsed — proving parsers come from pack 
descriptors, not fallback.
+
+        // Build with an EMPTY parser map (bypassing pack.yaml auto-loading)
+        GraphBuilder emptyBuilder = new GraphBuilder(Map.of());

Review Comment:
   I removed `provider/mule-xml-parser` from the pack descriptor. All 301 graph 
tests passed with and without that entry, including this test. `new 
GraphBuilder(Map.of())` exercises an explicitly empty map and never reads the 
descriptor. Please also run a real Mule fixture through packaged `graph 
generate --require-parser` using the pack’s registered ID. That test should 
pass with the registration present and fail when it is removed.
   
   _AI-generated by Codex on behalf of @luigidemasi._



##########
kit/camel-kit-graph/src/main/java/org/apache/camel/kit/packs/MigrationPackSelector.java:
##########
@@ -0,0 +1,167 @@
+package org.apache.camel.kit.packs;
+
+import java.util.*;
+import java.util.Locale;
+import java.util.stream.Collectors;
+
+import org.apache.camel.kit.graph.ProjectGraph;
+
+/**
+ * Handles scope selection when multiple migration packs detect the same 
project.
+ *
+ * Per Issue #200: "Only one migration and source scope per run." When testing 
mixed projects (e.g., Mule/BizTalk
+ * directory or Fuse with Camel dependencies), the system should request user 
choice when evidence is ambiguous.
+ *
+ * Both guided and direct migration modes must be preserved.
+ */
+public class MigrationPackSelector {
+
+    private final List<MigrationPack> availablePacks;
+    private final double CONFIDENCE_THRESHOLD = 0.3;
+    private final double AMBIGUOUS_THRESHOLD = 0.2; // If two packs are within 
this range, ask user
+
+    public MigrationPackSelector(List<MigrationPack> availablePacks) {
+        this.availablePacks = availablePacks;
+    }
+
+    /**
+     * Detect and select the appropriate migration pack for the given project.
+     *
+     * @param  graph             Project graph to analyze
+     * @param  userSpecifiedPack User-specified pack ID (from 
--source-platform), or null for auto-detect
+     * @return                   Selected migration pack, or empty if none 
applicable
+     */
+    public Optional<MigrationPack> selectPack(ProjectGraph graph, String 
userSpecifiedPack) {
+        // Direct mode: user specified a pack explicitly
+        if (userSpecifiedPack != null && !userSpecifiedPack.equals("auto")) {
+            return availablePacks.stream()
+                    .filter(pack -> pack.packId().equals(userSpecifiedPack))
+                    .findFirst();
+        }
+
+        // Guided mode: auto-detect
+        Map<MigrationPack, Double> confidenceScores = detectAll(graph);
+
+        // Filter out packs below threshold
+        List<Map.Entry<MigrationPack, Double>> candidates = 
confidenceScores.entrySet().stream()
+                .filter(entry -> entry.getValue() >= CONFIDENCE_THRESHOLD)
+                .sorted(Map.Entry.<MigrationPack, 
Double>comparingByValue().reversed())
+                .collect(Collectors.toList());
+
+        if (candidates.isEmpty()) {
+            return Optional.empty();
+        }
+
+        // Single clear candidate
+        if (candidates.size() == 1) {
+            return Optional.of(candidates.get(0).getKey());
+        }
+
+        // Multiple candidates - check if ambiguous
+        double topScore = candidates.get(0).getValue();
+        double secondScore = candidates.get(1).getValue();
+
+        if (Math.abs(topScore - secondScore) <= AMBIGUOUS_THRESHOLD) {
+            // Ambiguous - would need to prompt user
+            // For now, return the highest scoring pack but mark as ambiguous
+            MigrationPack selected = candidates.get(0).getKey();
+            System.err.println("WARN: Multiple migration sources detected:");
+            for (Map.Entry<MigrationPack, Double> entry : candidates) {
+                System.err.println(String.format(Locale.ROOT, "  - %s 
(confidence: %.2f)",
+                        entry.getKey().displayName(), entry.getValue()));
+            }
+            System.err.println(String.format(Locale.ROOT, "Selected: %s", 
selected.displayName()));
+            System.err.println("To explicitly choose, use --source-platform=" 
+ selected.packId());
+            return Optional.of(selected);
+        }
+
+        // Clear winner
+        return Optional.of(candidates.get(0).getKey());
+    }
+
+    /**
+     * Detect all packs and their confidence scores.
+     *
+     * @param  graph Project graph
+     * @return       Map of packs to confidence scores (0.0-1.0)
+     */
+    public Map<MigrationPack, Double> detectAll(ProjectGraph graph) {
+        Map<MigrationPack, Double> scores = new LinkedHashMap<>();
+        for (MigrationPack pack : availablePacks) {
+            double confidence = pack.detectSource(graph);
+            scores.put(pack, confidence);
+        }
+        return scores;
+    }
+
+    /**
+     * Check if the project contains evidence of multiple migration sources.
+     *
+     * @param  graph Project graph
+     * @return       true if multiple packs have confidence > threshold
+     */
+    public boolean isMixedProject(ProjectGraph graph) {
+        long count = detectAll(graph).values().stream()
+                .filter(confidence -> confidence >= CONFIDENCE_THRESHOLD)
+                .count();
+        return count > 1;
+    }
+
+    /**
+     * Get user-friendly prompt for ambiguous projects with source path.
+     *
+     * @param  graph      Project graph
+     * @param  sourcePath Path to the source directory being analyzed
+     * @return            List of detected packs with confidence scores
+     */
+    public List<PackDetectionResult> getDetectionResults(ProjectGraph graph, 
java.nio.file.Path sourcePath) {
+        return detectAll(graph).entrySet().stream()
+                .filter(entry -> entry.getValue() >= CONFIDENCE_THRESHOLD)
+                .sorted(Map.Entry.<MigrationPack, 
Double>comparingByValue().reversed())
+                .map(entry -> new PackDetectionResult(
+                        entry.getKey().packId(),
+                        entry.getKey().displayName(),
+                        entry.getValue(),
+                        entry.getKey().detectVersion(graph).orElse("unknown"),
+                        sourcePath))

Review Comment:
   With fixtures under `mixed/mule/` and `mixed/biztalk/`, both candidates 
returned `mixed/` here. `selectPack` then picked Mule at 0.50 over BizTalk at 
0.40. Please carry the directory that supplied each candidate’s evidence and 
return both choices to the workflow before selecting either one. An installed 
test should be able to choose `mixed/biztalk/` and see only that source 
analyzed.
   
   _AI-generated by Codex on behalf of @luigidemasi._



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