fix: wrap non-map action results to satisfy Jido.Exec output validation#12
Conversation
ae0a9c2 to
53b4661
Compare
|
Wrapping in Thanks! |
53b4661 to
93c133e
Compare
You're welcome! I've updated the PR description, title and contents to correctly wrap results in a map (unless it's a list, as there are tests asserting that this format is also okay). |
|
I validated this against current Good news: the change does fix the default scalar case under However, it does not fully fix the execution-path bug it describes:
Local repro after cherry-picking this PR onto current
The relevant Jido path is So this PR is a useful partial fix for the default scalar case, but it is not a complete fix for non-map outputs through
|
4736089 to
9eed748
Compare
Good catch. I've updated the PR to address this by adding tests that exercise |
Ash generic actions (type :action) can return non-map types like strings
or integers. Jido.Exec's output validation pipeline calls Map.split/2
on the result, which raises BadMapError for non-map values.
Fix by adding ensure_map_output/1 function that wraps non-map, non-list
primitives in %{result: value} after convert_to_maps/1 completes. This
ensures generated Jido Actions always return {:ok, map()} as required
by the Jido.Action contract, while preserving correct behavior for
nested resource conversions.
Changes:
- Add ensure_map_output/1 to wrap primitives at top level only
- Preserve existing behavior for Ash resources, lists, and structs
- Add comprehensive tests for string, integer, boolean, atom, and nil results
Extends the initial scalar-wrapping fix to fully handle all non-map
output paths through Jido.Exec.run/3:
- Lists (including lists of maps) are now wrapped as %{result: list}
- output_map?: false path now applies ensure_map_output, wrapping
non-map values while still skipping struct-to-map conversion
- Removes the list passthrough in ensure_map_output
The output_map? flag controls whether Ash structs are converted to
plain maps, but ALL outputs must be maps to satisfy Jido.Action's
do_validate_output/1 which calls Map.split/2.
Adds Jido.Exec.run/3 integration tests covering scalar, list, map,
and void action results for both output_map?: true and false.
9eed748 to
7846b29
Compare
Ash generic actions (type :action) can return non-map types like strings
or integers. Jido.Exec's output validation pipeline calls Map.split/2
on the result, which raises BadMapError for non-map values.
Fix by adding ensure_map_output/1 function that wraps non-map, non-list
primitives in %{result: value} after convert_to_maps/1 completes. This
ensures generated Jido Actions always return {:ok, map()} as required
by the Jido.Action contract, while preserving correct behavior for
nested resource conversions.
Changes: