diff --git a/lib/trailblazer/workflow/collaboration.rb b/lib/trailblazer/workflow/collaboration.rb index 13399d3..f351acd 100644 --- a/lib/trailblazer/workflow/collaboration.rb +++ b/lib/trailblazer/workflow/collaboration.rb @@ -127,42 +127,42 @@ def initial_lane_positions(lanes) # Triggers the {start_task} event and runs the entire collaboration until message is sent and # the throwing activity stops in a suspend or End terminus. # @private - def advance(collaboration, (ctx, flow), circuit_options, lane_positions:, start_position:, message_flow:) + def advance(collaboration, (ctx, flow), circuit_options, lane_positions:, start_task_position:, message_flow:) signal = nil # start_task, activity, loop do - start_position = start_position.to_h + start_task_position = start_task_position.to_h - Synchronous.validate_targeted_position(lane_positions, **start_position) + Synchronous.validate_targeted_position(lane_positions, **start_task_position) - circuit_options = circuit_options.merge(start_task: start_position[:task]) + circuit_options = circuit_options.merge(start_task: start_task_position[:task]) - # signal, (ctx, flow) = Activity::TaskWrap.invoke(start_position[:activity], [ctx, flow], **circuit_options) - signal, (ctx, flow) = Trailblazer::Developer.wtf?(start_position[:activity], [ctx, flow], **circuit_options) + # signal, (ctx, flow) = Activity::TaskWrap.invoke(start_task_position[:activity], [ctx, flow], **circuit_options) + signal, (ctx, flow) = Trailblazer::Developer.wtf?(start_task_position[:activity], [ctx, flow], **circuit_options) # now we have :throw, or not # @returns Event::Throw::Queued # now, "log" the collaboration's state. - lane_positions = advance_position(lane_positions, start_position[:activity], signal) + lane_positions = advance_position(lane_positions, start_task_position[:activity], signal) break unless flow[:throw].any? # break if (@options[:skip_message_from] || []).include?(flow[:throw][-1][0]) # FIXME: untested! - debug_points_to = start_position[:activity].to_h[:circuit].to_h[:map][start_position[:task]] - Trailblazer::Activity::Introspect.Nodes(start_position[:activity], task: start_position[:task]).data + debug_points_to = start_task_position[:activity].to_h[:circuit].to_h[:map][start_task_position[:task]] + Trailblazer::Activity::Introspect.Nodes(start_task_position[:activity], task: start_task_position[:task]).data puts " >>>>>>>>> FROM \033[1msuspend ---> #{debug_points_to}\033[0m" - flow, start_position = receiver_task(flow, message_flow) + flow, start_task_position = receiver_task(flow, message_flow) # every time we "deliver" a message, we should check if it's allowed (meaning the receiving activity is actually in the targeted catch event) end return Configuration.new( lane_positions: lane_positions, signal: signal, - last_lane: start_position[:activity], # DISCUSS: do we need that, or should we infer that using {signal}? + last_lane: start_task_position[:activity], # DISCUSS: do we need that, or should we infer that using {signal}? ), [ctx, flow] end diff --git a/lib/trailblazer/workflow/discovery.rb b/lib/trailblazer/workflow/discovery.rb index a2d79f9..8331a5b 100644 --- a/lib/trailblazer/workflow/discovery.rb +++ b/lib/trailblazer/workflow/discovery.rb @@ -6,7 +6,7 @@ module Discovery # Find all possible configurations for a {collaboration} by replacing # its tasks with mocks, and run through all possible paths. - def call(collaboration, start_position:, run_multiple_times: {}, initial_lane_positions: Collaboration::Synchronous.initial_lane_positions(collaboration), message_flow:) + def call(collaboration, start_task_position:, run_multiple_times: {}, initial_lane_positions: Collaboration::Synchronous.initial_lane_positions(collaboration), message_flow:) # State discovery: # The idea is that we collect suspend events and follow up on all their resumes (catch) events. # We can't see into {Collaboration.call}, meaning we can really only collect public entry points, @@ -22,7 +22,7 @@ def call(collaboration, start_position:, run_multiple_times: {}, initial_lane_po original_lanes = collaboration.to_h[:lanes] # this dictates the order within created Positions. - collaboration, message_flow, start_position, initial_lane_positions, activity_2_stub, original_task_2_stub_task = stub_tasks_for(collaboration, message_flow: message_flow, start_position: start_position, initial_lane_positions: initial_lane_positions) + collaboration, message_flow, start_task_position, initial_lane_positions, activity_2_stub, original_task_2_stub_task = stub_tasks_for(collaboration, message_flow: message_flow, start_task_position: start_task_position, initial_lane_positions: initial_lane_positions) # pp collaboration.to_h[:lanes][:ui].to_h # raise @@ -30,7 +30,7 @@ def call(collaboration, start_position:, run_multiple_times: {}, initial_lane_po resumes_to_invoke = [ [ - start_position, + start_task_position, initial_lane_positions, {}, # ctx_merge {outcome: :success} # config_payload @@ -44,15 +44,15 @@ def call(collaboration, start_position:, run_multiple_times: {}, initial_lane_po while resumes_to_invoke.any? - (start_position, lane_positions, ctx_merge, config_payload) = resumes_to_invoke.shift + (start_task_position, lane_positions, ctx_merge, config_payload) = resumes_to_invoke.shift puts "~~~~~~~~~" ctx = {seq: []}.merge(ctx_merge) - start_task = start_position.to_h[:task] + start_task = start_task_position.to_h[:task] if (do_again_config = run_multiple_times[start_task]) && !already_visited_catch_events_again[start_task] # TODO: do this by keying by resume event and ctx variable(s). resumes_to_invoke << [ - start_position, + start_task_position, lane_positions, # same positions as the original situation. do_again_config[:ctx_merge], do_again_config[:config_payload] @@ -66,8 +66,8 @@ def call(collaboration, start_position:, run_multiple_times: {}, initial_lane_po discovered_state = {} discovered_state = discovered_state.merge( - stubbed_positions_before: [lane_positions, start_position], - positions_before: [unstub_positions(activity_2_stub, original_task_2_stub_task, lane_positions, lanes: original_lanes), *unstub_positions(activity_2_stub, original_task_2_stub_task, [start_position], lanes: Hash.new(0))] + stubbed_positions_before: [lane_positions, start_task_position], + positions_before: [unstub_positions(activity_2_stub, original_task_2_stub_task, lane_positions, lanes: original_lanes), *unstub_positions(activity_2_stub, original_task_2_stub_task, [start_task_position], lanes: Hash.new(0))] ) discovered_state = discovered_state.merge(ctx_before: [ctx.inspect]) @@ -77,7 +77,7 @@ def call(collaboration, start_position:, run_multiple_times: {}, initial_lane_po [ctx, {throw: []}], {}, # circuit_options - start_position: start_position, + start_task_position: start_task_position, lane_positions: lane_positions, # current position/"state" message_flow: message_flow, @@ -127,7 +127,7 @@ def call(collaboration, start_position:, run_multiple_times: {}, initial_lane_po return discovered_states end - def stub_tasks_for(collaboration, ignore_class: Trailblazer::Activity::End, message_flow:, start_position:, initial_lane_positions:) + def stub_tasks_for(collaboration, ignore_class: Trailblazer::Activity::End, message_flow:, start_task_position:, initial_lane_positions:) collected = collaboration.to_h[:lanes].collect do |lane_id, activity| circuit = activity.to_h[:circuit] lane_map = circuit.to_h[:map].clone @@ -190,7 +190,7 @@ def stub_tasks_for(collaboration, ignore_class: Trailblazer::Activity::End, mess new_message_flow = message_flow.collect { |throw_evt, (activity, catch_evt)| [throw_evt, [activity_2_stub[activity], catch_evt]] }.to_h - new_start_position = Collaboration::Position.new(activity_2_stub.fetch(start_position.activity), start_position.task) + new_start_task_position = Collaboration::Position.new(activity_2_stub.fetch(start_task_position.activity), start_task_position.task) new_initial_lane_positions = initial_lane_positions.collect do |position| # TODO: make lane_positions {Position} instances, too. @@ -199,7 +199,7 @@ def stub_tasks_for(collaboration, ignore_class: Trailblazer::Activity::End, mess new_initial_lane_positions = Collaboration::Positions.new(new_initial_lane_positions) - return Collaboration::Schema.new(lanes: stubbed_lanes, message_flow: new_message_flow), new_message_flow, new_start_position, new_initial_lane_positions, activity_2_stub, original_task_2_stub_task + return Collaboration::Schema.new(lanes: stubbed_lanes, message_flow: new_message_flow), new_message_flow, new_start_task_position, new_initial_lane_positions, activity_2_stub, original_task_2_stub_task end # Get the original lane activity and tasks for a {Positions} set from the stubbed ones. diff --git a/lib/trailblazer/workflow/test/assertions.rb b/lib/trailblazer/workflow/test/assertions.rb index ffdef38..9198caf 100644 --- a/lib/trailblazer/workflow/test/assertions.rb +++ b/lib/trailblazer/workflow/test/assertions.rb @@ -32,7 +32,7 @@ def self.error_message_for(position, expected_position, lanes_cfg:) # TODO: test def assert_advance(event_label, test_plan:, lanes_cfg:, schema:, message_flow:, expected_ctx:, ctx: {seq: []}, **) # TODO: allow {ctx} iteration = test_plan.to_a.find { |iteration| iteration.event_label == event_label } or raise - start_position = iteration.start_task_position + start_task_position = iteration.start_task_position # current position. #DISCUSS: here, we could also ask the State layer for the start configuration, on a different level. @@ -45,7 +45,7 @@ def assert_advance(event_label, test_plan:, lanes_cfg:, schema:, message_flow:, [ctx_for_advance, {throw: []}], {}, # circuit_options - start_position: start_position, + start_task_position: start_task_position, lane_positions: lane_positions, # current position/"state" message_flow: message_flow, diff --git a/test/test_helper.rb b/test/test_helper.rb index 45bd9ff..dd1fbd4 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -187,13 +187,13 @@ def states # TODO: do this in the State layer. start_task = Trailblazer::Activity::Introspect.Nodes(lane_activity_ui, id: "catch-before-#{ui_create_form}").task # catch-before-Activity_0wc2mcq - start_position = Trailblazer::Workflow::Collaboration::Position.new(lane_activity_ui, start_task) + start_task_position = Trailblazer::Workflow::Collaboration::Position.new(lane_activity_ui, start_task) states = Trailblazer::Workflow::Discovery.( schema, initial_lane_positions: initial_lane_positions, - start_position: start_position, + start_task_position: start_task_position, message_flow: message_flow, # TODO: allow translating the original "id" (?) to the stubbed.