davsclaus opened a new pull request, #28791:
URL: https://github.com/apache/camel/pull/28791

   [CAMEL-23810](https://issues.apache.org/jira/browse/CAMEL-23810)
   
   The first step of the plan in CAMEL-23810: a test that pins what the Camel 
CLI parses from a command line, so that a change of the command-line parser (a 
trial port from picocli to aesh is next) shows every command line it parses 
differently. Test-only.
   
   ## The test
   
   `CliParseGoldenTest` parses command lines (it does not run them) and records 
the values of the fields of the commands in 
`src/test/resources/golden/cli-parse.txt`, 2207 cases:
   
   - **every command** of camel-jbang-core (by the name it is added with, as 
`camel completion` and `camel get group` differ from the names of their 
classes), first with no options and the values it requires: all its fields, 
which are the defaults;
   - **every option** of it: a boolean as `--x` and `--x=false`, an option with 
an optional value without and with one, any other with a value (two for an 
option of several values). These cases list only the fields that differ from 
the defaults;
   - **cases of hand**: the parameter consumers (files, `--jvm-debug`, 
`--background-wait`), several values, a name after a flag, errors, and the user 
configuration (`camel config set`, also for one command, and not for `camel 
plugin`).
   
   Only the parsing (one method) uses picocli. The fields are read from the 
command objects by the simple names of their annotations, picocli's and aesh's, 
and by the fields that the parameter consumers set. So a port changes that 
method and keeps the file. With `-Dcamel.golden.update=true` the test writes 
the cases again from the picocli model.
   
   To keep it from failing on unrelated changes:
   - a field the file does not list (a new option or command) is not compared, 
so a PR that adds an option does not have to update the file. A field that is 
gone, or a value that changed, fails;
   - the versions that the build sets (`RuntimeType.SPRING_BOOT_VERSION`, 
`HawtioVersion.HAWTIO_VERSION`) are written by name, so a dependency upgrade 
does not change the file;
   - error messages are kept as comments, and are not compared;
   - every case gets new command objects;
   - the test is skipped when the colors of the logging are on (`FORCE_COLOR`), 
because the default of `--logging-color` of `camel run` comes from the 
environment.
   
   A failure lists each command line with the expected and the actual fields, 
for example (with `fallbackValue = "true"` taken off `--maven-wrapper`):
   
   ```
   [] export --maven-wrapper
     expected: [(defaults)]
     actual:   [mavenWrapper=false]
   ```
   
   ## Seen on the way, not changed here
   
   picocli does not reset an option of an `@ArgGroup` without a `defaultValue` 
when the same command line parses again: `--jfr-profile` of `camel debug` kept 
its value for the next command lines. Only a command line that is used more 
than once is affected: `camel shell` keeps its command line, while `CliRunner` 
(camel ask, the monitor) takes a new one for every run.
   
   ## Tests
   
   - Ran `CliParseGoldenTest` (about 35 s), `BooleanOptionsTest` and 
`UserConfigDefaultsTest`.
   - The file is the same when written twice. The test passes with `CI=true`, 
and with a Turkish locale and another time zone in the test JVM.
   - It fails on a changed fallback (above), and passes with a new option added 
to `camel export`.
   - The plugins (kubernetes, generate, validate, test, tui, edit, mcp) are not 
in this test; it can be repeated per plugin when the port gets to them.
   
   _Claude Code on behalf of davsclaus (Claus Ibsen)_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   
   https://claude.ai/code/session_0128ThHB3iQdrvSRLVBGRrdP
   


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