diff --git a/lib/trailblazer/workflow/advance.rb b/lib/trailblazer/workflow/advance.rb index 3f99cce..81fca59 100644 --- a/lib/trailblazer/workflow/advance.rb +++ b/lib/trailblazer/workflow/advance.rb @@ -10,9 +10,12 @@ class Advance < Trailblazer::Activity::Railway terminus :invalid_event step task: :compute_catch_event_tuple, Output(:failure) => Track(:invalid_event) - step task: :find_position_options + step task: :find_position_options, Output(:failure) => Track(:invalid_event) step task: :advance + # DISCUSS: what we actually want here is a "catch_event tuple", the event we want to trigger. + # currently, we receive an {event_label}, find that in the iteration_set and thus + # get the catch event. def compute_catch_event_tuple((ctx, flow_options), **) iteration_set, event_label = flow_options[:iteration_set], flow_options[:event_label] @@ -46,9 +49,11 @@ def position_options_from_iteration(iteration) def find_position_options((ctx, flow_options), **) state_resolver = flow_options[:state_guards] - _, state_options = state_resolver.(*flow_options[:catch_event_tuple], [ctx], **ctx.to_hash) - - # raise unless state_options # FIXME. + (_, state_options), possible_states = state_resolver.(*flow_options[:catch_event_tuple], [ctx], **ctx.to_hash) + unless state_options + flow_options[:errors] = "No state configuration found for #{possible_states.inspect}" + return Activity::Left, [ctx, flow_options] # FIXME: make this nicer. + end lanes_cfg = flow_options[:lanes] fixme_tuples = state_options[:suspend_tuples].collect { |tuple| {"tuple" => tuple} } diff --git a/lib/trailblazer/workflow/collaboration/state.rb b/lib/trailblazer/workflow/collaboration/state.rb index f054012..6afd56c 100644 --- a/lib/trailblazer/workflow/collaboration/state.rb +++ b/lib/trailblazer/workflow/collaboration/state.rb @@ -15,13 +15,10 @@ def call(lane_label, catch_id, args, **kws) # First, find all state guards that "point to" this catch event. possible_states = @table.find_all { |state_name, cfg| cfg[:catch_tuples].include?([lane_label, catch_id]) } - # Execute those, the first returning true indicates the configuration. target_state = possible_states.find { |state_name, cfg| @guards.(state_name, args, **kws) } - raise "No state configuration found for #{possible_states.inspect}" if target_state.nil? - - target_state + return target_state, possible_states end end end diff --git a/test/advance_test.rb b/test/advance_test.rb index c7e05e0..f0de08a 100644 --- a/test/advance_test.rb +++ b/test/advance_test.rb @@ -26,12 +26,22 @@ class AdvanceTest < Minitest::Spec assert_equal signal.inspect, %(#) - #@ unknown event label + #@ unknown event label flow_options = flow_options.merge!(event_label: "XXX unknown ~~~") signal, (ctx, flow_options) = Trailblazer::Workflow::Advance.([ctx_for_advance, flow_options]) assert_equal signal.inspect, %(#) + + #@ no state guard matches + # DISCUSS: should we stop on a different terminus here to indicate that we found matching guards, but they were all unmet? + flow_options = flow_options.merge!(event_label: "☝ ⏵︎Update") + ctx_for_advance = {model: Posting.new(state: "~~~undefined~~~")} + + signal, (ctx, flow_options) = Trailblazer::Workflow::Advance.([ctx_for_advance, flow_options]) + + assert_equal signal.inspect, %(#) + assert_equal flow_options[:errors], %(No state configuration found for [[\"⏸︎ Update [00u]\", {:suspend_tuples=>[[\"lifecycle\", \"suspend-Gateway_0fnbg3r\"], [\"UI\", \"suspend-Gateway_0nxerxv\"], [\"approver\", \"~suspend~\"]], :catch_tuples=>[[\"UI\", \"catch-before-Activity_0j78uzd\"]]}]]) end end