Skip to content

Commit

Permalink
start working on a JSON renderer for expected configurations.
Browse files Browse the repository at this point in the history
this will simplify testing.
  • Loading branch information
apotonick committed Jan 10, 2024
1 parent 51ff425 commit 9f77546
Show file tree
Hide file tree
Showing 4 changed files with 475 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lib/trailblazer/workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ module Workflow
require "trailblazer/workflow/collaboration/lane"
require "trailblazer/workflow/collaboration/messages"
require "trailblazer/workflow/event"
require "trailblazer/workflow/state/discovery"
require "trailblazer/workflow/state/discovery/testing"
require "trailblazer/workflow/state/table"
4 changes: 4 additions & 0 deletions lib/trailblazer/workflow/state/discovery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ class State
# {states} are lane positions: [activity, suspend] tuples.
module Discovery
module Present
# Maintains the following fields
# start_position: where we started
# lane_positions: where the workflow stopped, for each lane.
State = Struct.new(:start_position, :lane_states, :state_from_discovery_fixme) do # FIXME: state_from_discovery_fixme is the "runtime Discovery state"
# def to_a
# return start_position, lane_states
# end
end
end

# Enrich each Discovery state with the possible resume events
def self.generate_from(states)
rows = states.collect do |state|

Expand Down
66 changes: 66 additions & 0 deletions lib/trailblazer/workflow/state/discovery/testing.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
module Trailblazer
module Workflow
class State
module Discovery
module Testing
def self.id_tuple_for(lanes, activity, task)
activity_id = lanes[activity]
task_id = Trailblazer::Activity::Introspect.Nodes(activity, task: task).id

return activity_id, task_id
end

def self.render_json(states, lanes:, additional_state_data:, initial_lane_positions:, task_map:)
present_states = Trailblazer::Workflow::State::Discovery.generate_from(states) # returns rows with [{activity, suspend, resumes}]

rows = present_states.collect do |state| # state = {start_position, lane_states: [{activity, suspend, resumes}]}
# raise state.inspect

start_position, lane_positions, discovery_state_fixme = state.to_a

# "serialize" start task
activity_id, triggered_catch_event_id = id_tuple_for(lanes, start_position.activity, start_position.task)



# Go through each lane and define the expected positions after running from the start position.
expected_lane_positions = lane_positions.collect do |lane_position|
next if lane_position.nil? # FIXME: why do we have that?

# puts lane_position[:suspend] # DISCUSS: introduce State::Position? this comes from {#generate_from}.



if initial_lane_positions.invert[lane_position[:suspend]]
{
tuple: [lanes[lane_position[:activity]], nil], # FIXME: to indicate this is a virtual "task".
}
else
position_tuple = id_tuple_for(lanes, lane_position[:activity], lane_position[:suspend])
_, task_id = position_tuple

comment = nil
task_map.invert.each do |id, label|
if task_id =~ /#{id}$/
comment = "--> #{label}" and break
end
end

{tuple: position_tuple, comment: comment}
end

end


{
start_position: [activity_id, triggered_catch_event_id],
expected_lane_positions: expected_lane_positions,
}
end

end
end
end
end
end
end
Loading

0 comments on commit 9f77546

Please sign in to comment.