davsclaus opened a new pull request, #27963: URL: https://github.com/apache/camel/pull/27963
Second batch of [CAMEL-23688](https://issues.apache.org/jira/browse/CAMEL-23688) (test coverage of the CLI commands): the commands that show the messages and logs of a running integration, picked from a JaCoCo run of camel-jbang-core (line coverage before: `cmd receive` 9%, `trace` 17%, `transform message` 14%, `cmd memory-leak` 6%). ### Tests - `CamelReceiveActionTest` (now AssertJ, 17 tests): start, stop, clear, a failure to start, `--endpoint` with the dump after it, the status of the endpoints (`--mask`), the dump (`--only-body`, `--tail`, `--grep`, `--output=json`), and a name that matches nothing. - `CamelTraceActionTest`: the dump of an exchange (`--source`, `--depth=0`, `--grep`, `--tail`, colors), an unknown `--sort`, and a name that matches nothing. - `CamelMemoryLeakTest`: start, `--status` during, after and without a recording, `--stop`, `--query` with stack traces and `--min-size`, `--top`, the comparison of two recordings, and the failures. - `TransformMessageActionTest` (new): what the command asks the Camel it started, the output file, a failed transformation, and the input errors. - `CamelLogActionTest`, `CamelSendActionResultTest`: a name that matches nothing, colored lines, and a failed action. - `ActionCommandTestSupport` runs one step of a command (`callWithResponse(Callable, JsonObject)`), for a command that starts a Camel of its own first. ### Bugs the tests found - **Not found**: `camel log`, `camel trace --action=dump` and `camel cmd receive --action=dump` exited with `0` (and printed nothing) for a name that matches no running integration, when they do not follow. Now `3`, as [the exit codes](https://github.com/apache/camel/blob/main/docs/user-manual/modules/ROOT/pages/camel-jbang-exit-codes.adoc) say; a command that follows still waits for the integration. - **`camel cmd receive`**: `--action=dump` without a name showed nothing (it read pid 0). `--output=json` printed the whole batch of messages of a line of the received file once for each message in it; it now prints each message once (JSON per line, with its `exchangeId`), and `--since`, `--grep` and `--mask` apply. - **`--sort`**: `camel trace` and `camel cmd receive` still had their own sort, which ignored an unknown key; they use `RowSort` now (exit `2`), and `SortOptionsTest` checks them. - **Colored output lost in the embedded CLI**: `camel trace`, `camel cmd send` and `camel transform message` printed the colored parts of a line (timestamp, pid, node, elapsed) with `AnsiConsole.out()`, and `camel log` its colored lines unless in the shell, so a CLI that runs the command in its JVM (`camel ask`'s `cli_exec`, the AI panel of the monitor) lost them, and they were drawn over the screen of the monitor. `CamelCommand.printColored` prints with the console only when the command prints to the console (as before: it leaves the colors out when the output is redirected), else with the printer of the command. `StringPrinter` strips instead of trims, which also removed the escape character that starts a colored line. - **Failed actions**: `camel cmd send` and `camel transform message` failed with a `NullPointerException` (exit `70`) when the integration failed the action itself (the answer has no timestamp nor elapsed time); they print its error and exit with `1`. - **`camel cmd memory-leak`**: an action the integration failed (status `failed`), and an integration without the `jfr-memory-leak` dev console (the connector answers `{}`), printed nothing and exited with `0`; now `1`. `--status` during a recording said that it had started, and after it that no samples were captured (the branches that read those answers were never reached). The duration ratio used the decimal comma of the locale (`2,0x`). - **`camel trace --tail`** showed the end of the last exchange as "Returning from route1" when the tail cut its start; now "Completed". - The elapsed time of the status line of `trace`, `cmd send` and `transform message` without colors had no space before it (`Processed(5ms)`). The user-visible changes are in the 4.24 upgrade guide. ### Not in this PR - The next batch: `cmd history`, `get error`, `restart`, `doc`, `init`, `update run` and `dependency copy` (the latter deletes the whole `--output-directory` before it copies). - `--grep` and `--find` highlight with colors also with `--logging-color=false` (as before). `mvn test` of camel-jbang-core: all tests pass. _Claude Code on behalf of davsclaus_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01DDRLJAyf8cDXSg8iX785My -- 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]
