Skip to content

Introduce taskInput, taskOutput and workflowInput methods#1197

Open
mcruzdev wants to merge 1 commit intoserverlessworkflow:mainfrom
mcruzdev:issue-1196
Open

Introduce taskInput, taskOutput and workflowInput methods#1197
mcruzdev wants to merge 1 commit intoserverlessworkflow:mainfrom
mcruzdev:issue-1196

Conversation

@mcruzdev
Copy link
Collaborator

@mcruzdev mcruzdev commented Mar 3, 2026

This pull request add input and output methods to DSL.

Closes #1196

Copilot AI review requested due to automatic review settings March 3, 2026 03:17
@mcruzdev mcruzdev requested a review from fjtirado as a code owner March 3, 2026 03:17
@mcruzdev mcruzdev requested a review from ricardozanini March 3, 2026 03:18
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds DSL helpers to simplify enriching inputFrom(...) and outputAs(...) transformations with access to the root workflow input (WorkflowModel), addressing #1196 by reducing boilerplate when reading workflowContext.instanceData().input().

Changes:

  • Added FuncDSL.enriched(...) and FuncDSL.enrichedOutput(...) helper functions (including root-input-only variants).
  • Introduced EnrichWithModelBiFunction functional interface to support (typedValue, WorkflowModel) enrichment lambdas.
  • Added new integration-style tests and updated impl/test Maven dependencies to compile/run them.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
experimental/fluent/func/src/main/java/io/serverlessworkflow/fluent/func/dsl/FuncDSL.java Adds new enrichment helpers and their Javadocs.
experimental/fluent/func/src/main/java/io/serverlessworkflow/fluent/func/dsl/EnrichWithModelBiFunction.java New functional interface for enrichment with WorkflowModel.
impl/test/src/test/java/io/serverlessworkflow/impl/test/FuncDSLEnrichWithTest.java New tests covering enriched input/output scenarios.
impl/test/pom.xml Adds test-scope dependencies required by the new tests.
experimental/fluent/func/src/main/java/io/serverlessworkflow/fluent/func/dsl/Step.java Minor formatting-only changes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings March 3, 2026 12:40
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Member

@ricardozanini ricardozanini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but please consider renaming to enrich instead and fwiw: https://www.enterpriseintegrationpatterns.com/patterns/messaging/DataEnricher.html

Copilot AI review requested due to automatic review settings March 3, 2026 18:30
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings March 3, 2026 20:26
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings March 3, 2026 21:06
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings March 3, 2026 21:51
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mcruzdev mcruzdev changed the title Add enriched and enrichedOutput DSL functions Add enrichInput and enrichOutput DSL functions Mar 4, 2026
@fjtirado
Copy link
Collaborator

fjtirado commented Mar 4, 2026

See my comment on the issue, I think the PR needs to be refactor accordingly

@fjtirado fjtirado marked this pull request as draft March 4, 2026 12:59
* @return the deserialized workflow input object of type T
*/
public static <T> T taskInput(WorkflowContextData context, Class<T> inputClass) {
return context.instanceData().input().as(inputClass).orElseThrow();
Copy link
Collaborator

@fjtirado fjtirado Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the task input, but overall workflow input.
I will rename all xxxInput as just input, for the sake of brevity

@mcruzdev mcruzdev changed the title Add enrichInput and enrichOutput DSL functions Introduce taskInput, taskOutput and workflowInput methods Mar 4, 2026
@mcruzdev mcruzdev marked this pull request as ready for review March 4, 2026 16:56
Copilot AI review requested due to automatic review settings March 4, 2026 16:56
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +140 to +158
@Test
void test_export_as_with_input_utility() {

SoftAssertions softly = new SoftAssertions();

Workflow workflow =
FuncWorkflowBuilder.workflow("enrichOutputWithInputTest")
.tasks(
function(
"add5",
(Long input) -> {
softly.assertThat(input).isEqualTo(10L);
return input + 5;
},
Long.class)
.exportAs(
(object, workflowContext, taskContextData) -> {
Long input = output(taskContextData, Long.class);
softly.assertThat(input).isEqualTo(15L);
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test name says "input utility", but the body is validating the new output(taskContextData, ...) helper. Renaming the test to match what it covers will make the intent clearer when scanning failures.

Copilot uses AI. Check for mistakes.
Copilot AI review requested due to automatic review settings March 4, 2026 17:14
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1400 to +1404
* @return the deserialized task output object of type T
*/
public static <T> T output(TaskContextData taskContextData, Class<T> outputClass) {
return taskContextData.output().as(outputClass).orElseThrow();
}
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In output(TaskContextData, Class ...) the parameter is named inputClass, but it represents the output type. Renaming it to outputClass would improve clarity and align with the Javadoc.

Copilot uses AI. Check for mistakes.
class FuncDSLEnrichWithTest {

@Test
void test_input_with_input_from() {
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test method names in this module consistently use lower camelCase (e.g., testBasic, testConsoleLogWithArgs). These new tests use underscores (test_input_with_input_from, etc.) and one has inconsistent capitalization (test_enrich_Input...). Please rename them to match the existing convention for readability and consistency.

Suggested change
void test_input_with_input_from() {
void testInputWithInputFrom() {

Copilot uses AI. Check for mistakes.
Copilot AI review requested due to automatic review settings March 4, 2026 17:23
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 8 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

* @return the deserialized workflow input object of type T
*/
public static <T> T input(WorkflowContextData context, Class<T> inputClass) {
return context.instanceData().input().as(inputClass).orElseThrow();
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

orElseThrow() here will throw a NoSuchElementException with no message, which is hard to debug from DSL usage. Consider throwing an IllegalStateException/IllegalArgumentException with a descriptive message that explains the workflow input is missing or cannot be deserialized into the requested type.

Suggested change
return context.instanceData().input().as(inputClass).orElseThrow();
return context
.instanceData()
.input()
.as(inputClass)
.orElseThrow(
() ->
new IllegalStateException(
"Workflow input is missing or cannot be deserialized into type "
+ inputClass.getName()
+ " when calling FuncDSL.input(WorkflowContextData, Class)."));

Copilot uses AI. Check for mistakes.
}

@Test
void test_enrich_Input_with_workflowInput_task() {
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test method name has inconsistent capitalization (test_enrich_Input...) compared to the other test methods in this class. Renaming it to use consistent lower_snake_case (or whatever naming pattern the file is following) will make the suite easier to scan and grep.

Suggested change
void test_enrich_Input_with_workflowInput_task() {
void test_enrich_input_with_workflow_input_task() {

Copilot uses AI. Check for mistakes.
Signed-off-by: Matheus Cruz <matheuscruz.dev@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add outputAs|inputFrom(WorkflowModel workflowInput) method to DSL

4 participants