davsclaus commented on code in PR #29514:
URL: https://github.com/apache/camel/pull/29514#discussion_r4518535228


##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/ChaosExperimentRun.java:
##########
@@ -170,13 +187,32 @@ static JsonObject run(
             answer.put("traffic", traffic);
         }
         answer.put("waited", waited);
+        if (warnings != null && !warnings.isEmpty()) {
+            answer.put("warnings", warnings);
+        }
         JsonObject exploration = exploration(integration.status());
         if (exploration != null && exploration.containsKey("timeLeft")) {
             answer.put("timeLeft", exploration.getLong("timeLeft"));
         }
         return answer;
     }
 
+    /** The longest within= of the rules, in millis, or 0 (an expectation 
without it has the time of its rule). */
+    static long longestWithin(String rules) {
+        long answer = 0;
+        Matcher m = WITHIN.matcher(rules);
+        while (m.find()) {
+            try {
+                answer = Math.max(answer, 
TimeUtils.toMilliSeconds(m.group(1)));
+            } catch (RuntimeException e) {
+                // not a time: camel-chaos refuses the rule with the reason
+            }
+        }
+        return answer;
+    }
+
+    private static final Pattern WITHIN = 
Pattern.compile("(?:^|\\s)within=(\\S+)");

Review Comment:
   Right, fixed in 7c656e2c8b2e: the pattern is now 
`(?:^|[\s;])within=([^\s;]+)`, so neither `within=90s;` nor 
`within=3m;route=...` keeps the `;`. The test now covers the case where the 
semicoloned time is the longest (3m before 90s, and without a space).
   
   _Claude Code on behalf of davsclaus_



##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ChaosExplore.java:
##########
@@ -147,20 +160,40 @@ public Integer doCall() throws Exception {
             // the AI may have finished it already; else its rules go now
             ActionClient.execute(process, "chaos", root -> root.put("command", 
"explore-finish"), 10000);
         }
-        JsonObject exploration = 
ChaosExperimentRun.exploration(RuntimeHelper.readStatus(process.pid()));
+        JsonObject status = RuntimeHelper.readStatus(process.pid());
+        JsonObject exploration = ChaosExperimentRun.exploration(status);
         List<String> lines = journal(exploration);
         printer().println();
         lines.forEach(printer()::println);
+        if (save && exploration != null) {
+            Saved saved = save(Path.of("test", "chaos"), LocalDateTime.now(),
+                    new Run(integration, budget, focus, ask.usedModel, 
seed(status)), exploration, ask.lastAnswer,
+                    lines);
+            printer().println();
+            printer().println("Report: " + saved.report());
+            saved.scenarios().forEach(s -> printer().println("Scenario: " + s 
+ " (replay: camel run * --chaos=" + s + ")"));
+        }
         if (failed(exploration)) {
             return CliExitCode.FAILURE;
         }
         return answer;
     }
 
+    /** The name of the integration as camel get chaos has it: its 
CamelContext, else the name of the process. */
+    static String displayName(CamelProcess process) {
+        if (process.status() != null && process.status().get("context") 
instanceof JsonObject context) {

Review Comment:
   Done in 7c656e2c8b2e: the status is read once into a local.
   
   _Claude Code on behalf of davsclaus_



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