Skip to content

Commit

Permalink
rename start_position to start_task_position as it is more descri…
Browse files Browse the repository at this point in the history
…ptive.
  • Loading branch information
apotonick committed Feb 21, 2024
1 parent c8b3872 commit 9110d8f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
22 changes: 11 additions & 11 deletions lib/trailblazer/workflow/collaboration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 12 additions & 12 deletions lib/trailblazer/workflow/discovery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -22,15 +22,15 @@ 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


resumes_to_invoke = [
[
start_position,
start_task_position,
initial_lane_positions,
{}, # ctx_merge
{outcome: :success} # config_payload
Expand All @@ -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]
Expand All @@ -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])
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions lib/trailblazer/workflow/test/assertions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 9110d8f

Please sign in to comment.