-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Input/Output handling for Pass, Choice, Succeed states #225
Fix Input/Output handling for Pass, Choice, Succeed states #225
Conversation
6913e36
to
7ce3028
Compare
I will put together a test with a combination of result, input path, result path, output path. see how the values go. I'm wondering if I screwed up and the input path IS processed for the output Also noticed that Success has input/output path and we do not handle. |
7ce3028
to
223d24c
Compare
4f89a3b
to
c17b774
Compare
Note: Merge #214 before merging this |
c17b774
to
2b57551
Compare
2b57551
to
7eecf93
Compare
Checked commits agrare/floe@f7a0d93~...7eecf93 with ruby 3.1.5, rubocop 1.56.3, haml-lint 0.51.0, and yamllint |
Clarifying question - In the OP I see
but then the comment right after said
I think this is supposed to be that we should be getting |
|
||
it "Uses InputPath to select color" do | ||
workflow.run_nonblock | ||
expect(ctx.output).to eq("red") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I think this is wrong? I think this should be
expect(ctx.output).to eq("red") | |
expect(ctx.output).to eq("\"red\"") |
or should it be "red"
here, and then if that goes through JSON output, then it's "\"red\""
?
I'm confused haha
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I think you're right and that matches what the asl sim outputs from the description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a slightly different issue than the one I'm trying to fix here though. The core issue for this PR is we were completely ignoring InputPath, the issue you describe is around JSON and workflow/state input/output. Think that is probably better solved in #222
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel ctx.output
is still in ruby, and therefore when asked, it should display a ruby class.
Now if we are printing it as output in the product (e.g. via CLI
), then maybe we want the jsonified values..
soap box:
The transitions from the outside world to the inside world are the only models that do any json parsing. So that would be CLI
(converting params to input/...), Task
(converting command output to our Result
), and provider-workflows (handles ruby <-> db).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The states-language spec is pretty clear that input/output to the State Machine and in between States is JSON [ref]
When a state machine is started, the caller can provide an initial JSON text as input, which is passed to the machine's start state as input. If no input is provided, the default is an empty JSON object, {}. As each state is executed, it receives a JSON text as input and can produce arbitrary output, which MUST be a JSON text.
We do need to parse that JSON to handle JsonPath.on
for Path#value
so maybe we JSON.parse() the input and .to_json the output?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeha I was conflicted on whether context.output was in Ruby still or should already be converted to a JSON string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Fryguy I think b7377a8#diff-c4b20f6026d80247d4c5645a2811f66f0bd918ebb4763da5fb0d19c8a7d092fa covers your concern here, still very WIP but throw 🍅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I thought about it a bit more and I agree with @kbrock here, context is "internal" where workflow.output is defining the "user interface". As long as the states get the right input/output and the workflow handles input/output properly everything is up to us.
I changed #228 to have workflow.output as JSON
Added - Set Floe.logger.level if DEBUG env var set (#234) - Add InstrinsicFunction foundation + States.Array, States.UUID (#194) - Evaluate IntrinsicFunctions from PayloadTemplate (#236) - Add more intrinsic functions (#242) - Add State#cause_path, error_path (#249) - Validate Catcher Next (#250) - Add spec/supports (#248) Fixed - Handle non-hash input/output values (#214) - Fix Input/Output handling for Pass, Choice, Succeed states (#225) - Wrap Parslet::ParseFailed errors as Floe::InvalidWorkflowError (#235) - Fix edge cases with States.Array (#237) - Fix sporadic test failure with Wait state (#243) - Fix invalid container names after normalizing (#252) Changed - Extract ErrorMatcherMixin from Catch and Retry (#186) - Output should be JSON (#230) - Normalize functions to all take arguments (#238) - Pass full path name to State.new for better errors (#229) - Validate that state machine input is valid JSON (#227) - Move the Parslet parse into initialize so that invalid function definition will fail on workflow load (#245)
Introduced by https://github.com/ManageIQ/floe/pull/191/files#diff-04416988853398624310337389715edeb1fed6c963a0a2a41ef882df8166dd6e
We're missing proper input processing for the Pass state if there is no Result attribute:
We should be getting
"red"
as the output, but currently we return the entire input payload: