Skip to content

Commit

Permalink
all tests passing.
Browse files Browse the repository at this point in the history
  • Loading branch information
apotonick committed Apr 1, 2024
1 parent c1c83e6 commit 01a555d
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 84 deletions.
2 changes: 1 addition & 1 deletion lib/trailblazer/workflow/collaboration/state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def call(lane_label, catch_id, args, **kws)
# 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 #{state_name.inspect}" if target_state.nil?
raise "No state configuration found for #{possible_states.inspect}" if target_state.nil?

target_state
end
Expand Down
2 changes: 1 addition & 1 deletion lib/trailblazer/workflow/task/discover.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ module TestPlan
module_function

def call(iteration_set, lanes_cfg:, test_filename:, namespace:, input: {}, iteration_set_filename:)
test_plan_comment_header = Trailblazer::Workflow::Test::Plan.render_comment_header(iteration_set, lanes_cfg: lanes_cfg)
test_plan_comment_header = Trailblazer::Workflow::Test::Plan::Introspect.(iteration_set, lanes_cfg: lanes_cfg)

assertions = Trailblazer::Workflow::Test::Plan.for(iteration_set, lanes_cfg: lanes_cfg, input: input)

Expand Down
5 changes: 3 additions & 2 deletions lib/trailblazer/workflow/test/assertions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def assert_positions(asserted_positions, expected_positions, lanes:, test_plan:,
# Compile error message when the expected lane position doesn't match the actual one.
def self.error_message_for(position, expected_position, **options) # TODO: test me.
# TODO: make the labels use UTF8 icons etc, as in the CLI rendering code.
expected_label = Introspect::Present.readable_name_for_suspend_or_terminus(*position.to_a, **options)
actual_label = Introspect::Present.readable_name_for_suspend_or_terminus(*expected_position.to_a, **options)
actual_label = Introspect::Present.readable_name_for_suspend_or_terminus(*position.to_a, **options)
expected_label = Introspect::Present.readable_name_for_suspend_or_terminus(*expected_position.to_a, **options)

lane_label = Introspect::Present.lane_options_for_position(position, **options)[:label]

Expand Down Expand Up @@ -52,6 +52,7 @@ def assert_advance(event_label, test_plan:, schema:, ctx: {seq: []}, flow_option
return ctx # FIXME: test this!
end

puts "finding #{event_label}"
iteration = test_plan.to_a.find { |iteration| iteration.event_label == event_label }

assert_positions configuration[:lane_positions], iteration.suspend_positions, test_plan: test_plan, **schema.to_h
Expand Down
46 changes: 2 additions & 44 deletions test/advance_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,7 @@ class AdvanceTest < Minitest::Spec
serialized_iteration_set = JSON.dump(Trailblazer::Workflow::Introspect::Iteration::Set::Serialize.(iteration_set, lanes_cfg: lanes_cfg))
iteration_set = Trailblazer::Workflow::Introspect::Iteration::Set::Deserialize.(JSON.parse(serialized_iteration_set), lanes_cfg: lanes_cfg)

state_guards_from_user = {state_guards: {
"⏸︎ Archive [10u]" => {guard: ->(ctx, model:, **) { model.state == "⏸︎ Archive [10u]" }},
"⏸︎ Create [01u]" => {guard: ->(ctx, model: nil, **) { model.nil? }},
"⏸︎ Create form [00u]" => {guard: ->(ctx, model:, **) { model.state == "⏸︎ Create form [00u]" }},
"⏸︎ Delete♦Cancel [11u]" => {guard: ->(ctx, model:, **) { model.state == "⏸︎ Delete♦Cancel [11u]" }},
"⏸︎ Revise [01u]" => {guard: ->(ctx, model:, **) { model.state == "⏸︎ Revise [01u]" }},
"⏸︎ Revise form [00u]" => {guard: ->(ctx, model:, **) { model.state == "⏸︎ Revise form [00u]" }},
"⏸︎ Revise form♦Notify approver [10u]" => {guard: ->(ctx, model:, **) { model.state == "⏸︎ Revise form♦Notify approver [10u]" }},
"⏸︎ Update [00u]" => {guard: ->(ctx, model:, **) { model.id == 1 }},
"⏸︎ Update form♦Delete? form♦Publish [11u]" => {guard: ->(ctx, model:, **) { model.state == "⏸︎ Update form♦Delete? form♦Publish [11u]" }},
"⏸︎ Update form♦Notify approver [00u]" => {guard: ->(ctx, model:, **) { model.state == "⏸︎ Update form♦Notify approver [00u]" }},
"⏸︎ Update form♦Notify approver [11u]" => {guard: ->(ctx, model:, **) { model.state == "⏸︎ Update form♦Notify approver [11u]" }},
}}[:state_guards]

# auto-generated. this structure could also hold alternative state names, etc.
state_table = {
"⏸︎ Archive [10u]" => {suspend_tuples: [["lifecycle", "suspend-gw-to-catch-before-Activity_1hgscu3"], ["UI", "suspend-gw-to-catch-before-Activity_0fy41qq"], ["approver", "~suspend~"]], catch_tuples: [["UI", "catch-before-Activity_0fy41qq"]]},
"⏸︎ Create [01u]" => {suspend_tuples: [["lifecycle", "suspend-gw-to-catch-before-Activity_0wwfenp"], ["UI", "suspend-Gateway_14h0q7a"], ["approver", "~suspend~"]], catch_tuples: [["UI", "catch-before-Activity_1psp91r"]]},
"⏸︎ Create form [00u]" => {suspend_tuples: [["lifecycle", "suspend-gw-to-catch-before-Activity_0wwfenp"], ["UI", "suspend-gw-to-catch-before-Activity_0wc2mcq"], ["approver", "~suspend~"]], catch_tuples: [["UI", "catch-before-Activity_0wc2mcq"]]},
"⏸︎ Delete♦Cancel [11u]" => {suspend_tuples: [["lifecycle", "suspend-Gateway_1hp2ssj"], ["UI", "suspend-Gateway_100g9dn"], ["approver", "~suspend~"]], catch_tuples: [["UI", "catch-before-Activity_15nnysv"], ["UI", "catch-before-Activity_1uhozy1"]]},
"⏸︎ Revise [01u]" => {suspend_tuples: [["lifecycle", "suspend-Gateway_01p7uj7"], ["UI", "suspend-Gateway_1xs96ik"], ["approver", "~suspend~"]], catch_tuples: [["UI", "catch-before-Activity_1wiumzv"]]},
"⏸︎ Revise form [00u]" => {suspend_tuples: [["lifecycle", "suspend-Gateway_01p7uj7"], ["UI", "suspend-gw-to-catch-before-Activity_0zsock2"], ["approver", "~suspend~"]], catch_tuples: [["UI", "catch-before-Activity_0zsock2"]]},
"⏸︎ Revise form♦Notify approver [10u]" => {suspend_tuples: [["lifecycle", "suspend-Gateway_1kl7pnm"], ["UI", "suspend-Gateway_00n4dsm"], ["approver", "~suspend~"]], catch_tuples: [["UI", "catch-before-Activity_0zsock2"], ["UI", "catch-before-Activity_1dt5di5"]]},
"⏸︎ Update [00u]" => {suspend_tuples: [["lifecycle", "suspend-Gateway_0fnbg3r"], ["UI", "suspend-Gateway_0nxerxv"], ["approver", "~suspend~"]], catch_tuples: [["UI", "catch-before-Activity_0j78uzd"]]},
"⏸︎ Update form♦Delete? form♦Publish [11u]" => {suspend_tuples: [["lifecycle", "suspend-Gateway_1hp2ssj"], ["UI", "suspend-Gateway_1sq41iq"], ["approver", "~suspend~"]], catch_tuples: [["UI", "catch-before-Activity_1165bw9"], ["UI", "catch-before-Activity_0ha7224"], ["UI", "catch-before-Activity_0bsjggk"]]},
"⏸︎ Update form♦Notify approver [00u]" => {suspend_tuples: [["lifecycle", "suspend-Gateway_0fnbg3r"], ["UI", "suspend-Gateway_0kknfje"], ["approver", "~suspend~"]], catch_tuples: [["UI", "catch-before-Activity_1165bw9"], ["UI", "catch-before-Activity_1dt5di5"]]},
"⏸︎ Update form♦Notify approver [11u]" => {suspend_tuples: [["lifecycle", "suspend-Gateway_1wzosup"], ["UI", "suspend-Gateway_1g3fhu2"], ["approver", "~suspend~"]], catch_tuples: [["UI", "catch-before-Activity_1165bw9"], ["UI", "catch-before-Activity_1dt5di5"]]},
}

state_guards = Trailblazer::Workflow::Collaboration::StateGuards.from_user_hash( # TODO: unify naming, DSL.state_guards_from_user or something like that.
state_guards_from_user,
# iteration_set: iteration_set,
state_table: state_table,
)



state_guards = state_guards()


=begin
Expand Down Expand Up @@ -81,12 +45,6 @@ class AdvanceTest < Minitest::Spec
assert_equal signal.inspect, %(Trailblazer::Activity::Left)
=end
Posting = Struct.new(:id) do
def self.find_by(id:)
new(id)
end
end

require "trailblazer/endpoint"
require "trailblazer/macro/model/find"

Expand Down Expand Up @@ -162,7 +120,7 @@ def render(text)
# Update is invalid
flow_options = original_flow_options.merge(event_label: "☝ ⏵︎Update",)
Trailblazer::Endpoint::Runtime.({params: {id: 1}, seq: [], update: false}, adapter: action_adapter_with_model, default_matcher: default_matcher, matcher_context: self, flow_options: flow_options, &matcher_block)
assert_equal @render, %(failed: #<struct AdvanceTest::Posting id=1>)
assert_equal @render, %(failed: #<struct Minitest::Spec::Posting id=1, state="⏸︎ Update [00u]">)


# {flow_options} is passed correctly through the entire run.
Expand Down
46 changes: 24 additions & 22 deletions test/discover_task_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def build_schema()
end

#@ We serialized the discovered iterations, so we don't need to run discovery on every startup.
assert_equal (serialized_iteration_set = File.read("#{TEST_ROOT}/app/concepts/posting/collaboration/generated/iteration_set.json")).size, 20925
assert_equal (serialized_iteration_set = File.read("#{TEST_ROOT}/app/concepts/posting/collaboration/generated/iteration_set.json")).size, 28706

# raise
# iteration_set = Trailblazer::Workflow::Introspect::Iteration::Set.from_discovered_states(states, lanes_cfg: lanes_cfg)
Expand All @@ -91,7 +91,7 @@ def build_schema()
iteration_set_from_json = Trailblazer::Workflow::Introspect::Iteration::Set::Deserialize.(JSON.parse(serialized_iteration_set), lanes_cfg: schema.to_h[:lanes])

# TODO: test {Set#to_a}
assert_equal iteration_set_from_json.to_a.size, 14
assert_equal iteration_set_from_json.to_a.size, 17

#@ Assert test plan

Expand All @@ -101,16 +101,17 @@ def build_schema()
module StateGuards
Decider = Trailblazer::Workflow::Collaboration::StateGuards.from_user_hash(
{
"⏸︎ Create form" => {guard: ->(ctx, process_model:, **) { raise "implement me!" }},
"⏸︎ Create" => {guard: ->(ctx, process_model:, **) { raise "implement me!" }},
"⏸︎ Update form♦Notify approver" => {guard: ->(ctx, process_model:, **) { raise "implement me!" }},
"⏸︎ Update" => {guard: ->(ctx, process_model:, **) { raise "implement me!" }},
"⏸︎ Approve♦Reject" => {guard: ->(ctx, process_model:, **) { raise "implement me!" }},
"⏸︎ Delete? form♦Publish" => {guard: ->(ctx, process_model:, **) { raise "implement me!" }},
"⏸︎ Revise form" => {guard: ->(ctx, process_model:, **) { raise "implement me!" }},
"⏸︎ Delete♦Cancel" => {guard: ->(ctx, process_model:, **) { raise "implement me!" }},
"⏸︎ Archive" => {guard: ->(ctx, process_model:, **) { raise "implement me!" }},
"⏸︎ Revise" => {guard: ->(ctx, process_model:, **) { raise "implement me!" }},
"⏸︎ Approve♦Reject [000]" => {guard: ->(ctx, model:, **) { model.state == "⏸︎ Approve♦Reject [000]" }},
"⏸︎ Archive [100]" => {guard: ->(ctx, model:, **) { model.state == "⏸︎ Archive [100]" }},
"⏸︎ Create [010]" => {guard: ->(ctx, model:, **) { model.state == "⏸︎ Create [010]" }},
"⏸︎ Create form [000]" => {guard: ->(ctx, model:, **) { model.state == "⏸︎ Create form [000]" }},
"⏸︎ Delete♦Cancel [110]" => {guard: ->(ctx, model:, **) { model.state == "⏸︎ Delete♦Cancel [110]" }},
"⏸︎ Revise [010]" => {guard: ->(ctx, model:, **) { model.state == "⏸︎ Revise [010]" }},
"⏸︎ Revise form [000]" => {guard: ->(ctx, model:, **) { model.state == "⏸︎ Revise form [000]" }},
"⏸︎ Update [000]" => {guard: ->(ctx, model:, **) { model.state == "⏸︎ Update [000]" }},
"⏸︎ Update form♦Delete? form♦Publish [110]" => {guard: ->(ctx, model:, **) { model.state == "⏸︎ Update form♦Delete? form♦Publish [110]" }},
"⏸︎ Update form♦Notify approver [000]" => {guard: ->(ctx, model:, **) { model.state == "⏸︎ Update form♦Notify approver [000]" }},
"⏸︎ Update form♦Notify approver [110]" => {guard: ->(ctx, model:, **) { model.state == "⏸︎ Update form♦Notify approver [110]" }},
},
state_table: Generated::StateTable,
)
Expand All @@ -122,16 +123,17 @@ module StateGuards
%(# This file is generated by trailblazer-workflow.
module Posting::Collaboration::Generated
StateTable = {
"⏸︎ Create form" => {id: ["catch-before-Activity_0wc2mcq"]},
"⏸︎ Create" => {id: ["catch-before-Activity_1psp91r"]},
"⏸︎ Update form♦Notify approver" => {id: ["catch-before-Activity_1165bw9", "catch-before-Activity_1dt5di5"]},
"⏸︎ Update" => {id: ["catch-before-Activity_0j78uzd"]},
"⏸︎ Approve♦Reject" => {id: ["catch-before-Activity_13fw5nm", "catch-before-Activity_1j7d8sd"]},
"⏸︎ Delete? form♦Publish" => {id: ["catch-before-Activity_0bsjggk", "catch-before-Activity_0ha7224"]},
"⏸︎ Revise form" => {id: ["catch-before-Activity_0zsock2"]},
"⏸︎ Delete♦Cancel" => {id: ["catch-before-Activity_15nnysv", "catch-before-Activity_1uhozy1"]},
"⏸︎ Archive" => {id: ["catch-before-Activity_0fy41qq"]},
"⏸︎ Revise" => {id: ["catch-before-Activity_1wiumzv"]},
"⏸︎ Approve♦Reject [000]" => {suspend_tuples: [["lifecycle", "suspend-Gateway_0y3f8tz"], ["UI", "suspend-Gateway_063k28q"], ["reviewer", "suspend-Gateway_02veylj"]], catch_tuples: [["reviewer", "catch-before-Activity_13fw5nm"], ["reviewer", "catch-before-Activity_1j7d8sd"]]},
"⏸︎ Archive [100]" => {suspend_tuples: [["lifecycle", "suspend-gw-to-catch-before-Activity_1hgscu3"], ["UI", "suspend-gw-to-catch-before-Activity_0fy41qq"], ["reviewer", "Event_0g5plbq"]], catch_tuples: [["UI", "catch-before-Activity_0fy41qq"]]},
"⏸︎ Create [010]" => {suspend_tuples: [["lifecycle", "suspend-gw-to-catch-before-Activity_0wwfenp"], ["UI", "suspend-Gateway_14h0q7a"], ["reviewer", "suspend-gw-to-catch-before-Activity_05zip3u"]], catch_tuples: [["UI", "catch-before-Activity_1psp91r"]]},
"⏸︎ Create form [000]" => {suspend_tuples: [["lifecycle", "suspend-gw-to-catch-before-Activity_0wwfenp"], ["UI", "suspend-gw-to-catch-before-Activity_0wc2mcq"], ["reviewer", "suspend-gw-to-catch-before-Activity_05zip3u"]], catch_tuples: [["UI", "catch-before-Activity_0wc2mcq"]]},
"⏸︎ Delete♦Cancel [110]" => {suspend_tuples: [["lifecycle", "suspend-Gateway_1hp2ssj"], ["UI", "suspend-Gateway_100g9dn"], ["reviewer", "Event_0g5plbq"]], catch_tuples: [["UI", "catch-before-Activity_15nnysv"], ["UI", "catch-before-Activity_1uhozy1"]]},
"⏸︎ Revise [010]" => {suspend_tuples: [["lifecycle", "suspend-Gateway_01p7uj7"], ["UI", "suspend-Gateway_1xs96ik"], ["reviewer", "Event_0g5plbq"]], catch_tuples: [["UI", "catch-before-Activity_1wiumzv"]]},
"⏸︎ Revise form [000]" => {suspend_tuples: [["lifecycle", "suspend-Gateway_01p7uj7"], ["UI", "suspend-gw-to-catch-before-Activity_0zsock2"], ["reviewer", "Event_0g5plbq"]], catch_tuples: [["UI", "catch-before-Activity_0zsock2"]]},
"⏸︎ Update [000]" => {suspend_tuples: [["lifecycle", "suspend-Gateway_0fnbg3r"], ["UI", "suspend-Gateway_0nxerxv"], ["reviewer", "suspend-gw-to-catch-before-Activity_05zip3u"]], catch_tuples: [["UI", "catch-before-Activity_0j78uzd"]]},
"⏸︎ Update form♦Delete? form♦Publish [110]" => {suspend_tuples: [["lifecycle", "suspend-Gateway_1hp2ssj"], ["UI", "suspend-Gateway_1sq41iq"], ["reviewer", "Event_0g5plbq"]], catch_tuples: [["UI", "catch-before-Activity_1165bw9"], ["UI", "catch-before-Activity_0ha7224"], ["UI", "catch-before-Activity_0bsjggk"]]},
"⏸︎ Update form♦Notify approver [000]" => {suspend_tuples: [["lifecycle", "suspend-Gateway_0fnbg3r"], ["UI", "suspend-Gateway_0kknfje"], ["reviewer", "suspend-gw-to-catch-before-Activity_05zip3u"]], catch_tuples: [["UI", "catch-before-Activity_1165bw9"], ["UI", "catch-before-Activity_1dt5di5"]]},
"⏸︎ Update form♦Notify approver [110]" => {suspend_tuples: [["lifecycle", "suspend-Gateway_1wzosup"], ["UI", "suspend-Gateway_1g3fhu2"], ["reviewer", "suspend-gw-to-catch-before-Activity_05zip3u"]], catch_tuples: [["UI", "catch-before-Activity_1165bw9"], ["UI", "catch-before-Activity_1dt5di5"]]},
}
end
)
Expand Down
Loading

0 comments on commit 01a555d

Please sign in to comment.