davsclaus opened a new pull request, #28185: URL: https://github.com/apache/camel/pull/28185
Stacked on #28178, which adds the body types to the route-structure console that this reads. Review that one first; this PR's own change is the last commit. This is part 2 of [CAMEL-25750](https://issues.apache.org/jira/browse/CAMEL-25750), the part the issue is named after. The YAML validator walks the body through the steps of each route, and stays quiet where the file does not say what the body is: after a consumer other than the file consumer, or after a `to:` it cannot follow. When an integration runs routes of the file, with the message history on as `camel run --dev` does, those gaps are now filled with what the integration saw: ``` route orders: simple reads a field of the body (${body.qty}), but the body here is still text, not parsed data - in the running app, from: platform-http:/orders gave a ByteArrayInputStreamCache: unmarshal it first with the data format of the payload (json, jacksonXml, csv, ...) to read its fields ``` So the next version of a file is checked against what the integration does with the current one. In dev mode a reload makes the registry forget the old route, so the facts always describe the version that runs. The checks reach `camel validate source` and the AI and MCP tools that validate before they write. ## How - **Validator:** - `ProjectFacts.observed`, keyed `from:<uri>` / `to:<uri>` without the query, as `RouteGraph.normalize` keys the routes; - `TextBodyFlow` uses it where its walk would not know the body, at the start of a route and after a `to:`. The walk's own knowledge comes first: the file consumer still gives the file as read. - A single kind sets the state: `payload` is text, `data` and `collection` are parsed data. More than one kind stays unknown, so nothing is said. - Observed data has no data format, so the marshal advice becomes "add marshal with the data format to write (such as marshal: json)" instead of `add marshal: null`. - **camel-jbang:** `ValidatorFacts.read` gets the file name, and `ObservedBodies` does the work: - it lists `~/.camel` for status files first, and stops there when no integration runs, which is most validations; - it finds the integration whose status has a route from the file, by path, or by name for a classpath source; - it asks that integration for its route structure, with a 3 second timeout; any failure means no facts; - it keeps the answer for 2 seconds, as a write validates the file before and after the change. - **Deriving the facts** (`fromRouteStructure`): - what a consumer gave is what the first step was reached with; - what a producer returned is what the next step of its block was reached with. A `to` that ends its block gives nothing, because the step after its block is reached by other paths too, and a `toD` has no endpoint of its own. - **Docs:** "What a running integration saw" on the Camel CLI validation page, and a pointer from the Message History section. ## Tests - **`TextBodyFlowTest`:** - an HTTP consumer observed giving a stream cache; - a sql call observed returning a List before a file write; - mixed kinds say nothing; - the file consumer wins over an observation. The whole validator module (272) passes. - **`ObservedBodiesTest`:** the derivation, on the JSON shape a real route-structure console returns, captured from a test run; merging across routes; and matching a route's source to a file. - **`ValidateWithObservedBodiesTest`**, end to end against a fake running integration (status file and answered action): - `SourceValidator` reports from what the integration saw; - an integration of another file is not asked. - The whole camel-jbang-core suite passes (2,374 + 237). _Claude Code on behalf of davsclaus_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- 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]
