From 751c7ea595c8243e46daa990ee001895dcffa91d Mon Sep 17 00:00:00 2001 From: Nick Sutterer Date: Thu, 14 Dec 2023 15:51:33 +0100 Subject: [PATCH] add `:semantic` to our initial "suspend". implement printing a state table that shows all states we reached with the state discovery. --- lib/trailblazer/workflow/collaboration.rb | 2 +- test/collaboration_test.rb | 43 +++++++++++++++++++++-- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/lib/trailblazer/workflow/collaboration.rb b/lib/trailblazer/workflow/collaboration.rb index 18f52cc..1464b49 100644 --- a/lib/trailblazer/workflow/collaboration.rb +++ b/lib/trailblazer/workflow/collaboration.rb @@ -47,7 +47,7 @@ def initial_lane_positions(lanes) [ activity, - {"resumes" => [catch_id]} # We deliberately have *one* position per lane, we're Synchronous. + {"resumes" => [catch_id], semantic: [:suspend, "from initial_lane_positions"]} # We deliberately have *one* position per lane, we're Synchronous. # TODO: use a real {Event::Suspend} here. ] end .to_h diff --git a/test/collaboration_test.rb b/test/collaboration_test.rb index 389252e..e43037f 100644 --- a/test/collaboration_test.rb +++ b/test/collaboration_test.rb @@ -191,6 +191,9 @@ def decider(ctx, decision: true, **) already_visited_catch_events_again[start_task] = true end + # register new state. + states << [lane_positions, start_position] + configuration, (ctx, flow) = Trailblazer::Workflow::Collaboration::Synchronous.advance( schema, [ctx, {throw: []}], @@ -202,8 +205,6 @@ def decider(ctx, decision: true, **) message_flow: extended_message_flow, ) - # register new state. - states << configuration # figure out possible next resumes/catchs: last_lane = configuration.last_lane @@ -230,6 +231,42 @@ def decider(ctx, decision: true, **) end end + # here, we only have the resume/catch events. + # pp states + + def render_states(states, lanes:) + rows = states.collect do |lane_positions, triggered_resume_event| + + # Go through each lane. + row = lane_positions.flat_map do |activity, suspend| + next if suspend.to_h["resumes"].nil? + + resumes = suspend.to_h["resumes"].collect do |catch_event_id| + catch_event = Trailblazer::Activity::Introspect.Nodes(activity, id: catch_event_id).task + task_after_catch = activity.to_h[:circuit].to_h[:map][catch_event][Trailblazer::Activity::Right] + # raise task_after_catch.inspect + + Trailblazer::Activity::Introspect.Nodes(activity, task: task_after_catch).data[:label] || task_after_catch + end + + [ + lanes[activity], + resumes.inspect, + + "#{lanes[activity]} suspend", + suspend.to_h[:semantic][1] + ] + end + + row = Hash[*row.compact] + end + .uniq # remove me if you want to see all reached configurations + + + puts Hirb::Helpers::Table.render(rows, fields: ["UI", "UI suspend", "lifecycle", "lifecycle suspend"], max_width: 999) + end + + render_states(states, lanes: {lane_activity => "lifecycle", lane_activity_ui => "UI", approver_activity => "approver"}) @@ -253,7 +290,7 @@ def decider(ctx, decision: true, **) # TODO: test {:last_lane}. assert_equal configuration.lane_positions.keys, [lane_activity, lane_activity_ui] - assert_equal configuration.lane_positions.values.inspect, %([{"resumes"=>["catch-before-#{create_id}"]}, \ + assert_equal configuration.lane_positions.values.inspect, %([{"resumes"=>["catch-before-#{create_id}"], :semantic=>[:suspend, "from initial_lane_positions"]}, \ #]) assert_equal ctx.inspect, %({:seq=>[:create_form]})