trailblazer-operation 0.10.1 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +2 -2
- data/CHANGES.md +10 -0
- data/lib/trailblazer/operation/class_dependencies.rb +1 -1
- data/lib/trailblazer/operation/public_call.rb +24 -14
- data/lib/trailblazer/operation/railway.rb +13 -7
- data/lib/trailblazer/operation/version.rb +1 -1
- data/lib/trailblazer/operation/wtf.rb +11 -0
- data/lib/trailblazer/operation.rb +2 -2
- data/test/call_test.rb +32 -10
- data/test/class_dependencies_test.rb +8 -4
- data/test/docs/autogenerated/activity_basics_test.rb +72 -0
- data/test/docs/autogenerated/composable_variable_mapping_test.rb +880 -0
- data/test/docs/autogenerated/fast_track_layout_test.rb +76 -0
- data/test/docs/autogenerated/mechanics_test.rb +382 -0
- data/test/docs/autogenerated/sequence_options_test.rb +202 -0
- data/test/docs/autogenerated/subprocess_test.rb +257 -0
- data/test/docs/autogenerated/wiring_api_test.rb +435 -0
- data/test/docs/developer_test.rb +27 -0
- data/test/docs/public_call_monkeypatching_test.rb +96 -0
- data/test/docs/result_test.rb +38 -0
- data/test/docs/step_dsl_test.rb +93 -0
- data/test/operation_test.rb +53 -13
- data/test/result_test.rb +1 -1
- data/test/test_helper.rb +17 -5
- data/test/trace_test.rb +3 -43
- data/trailblazer-operation.gemspec +2 -1
- metadata +42 -23
- data/lib/trailblazer/operation/trace.rb +0 -67
- data/test/callable_test.rb +0 -147
- data/test/docs/doormat_test.rb +0 -190
- data/test/docs/macaroni_test.rb +0 -31
- data/test/skill_test.rb +0 -66
- data/test/wire_test.rb +0 -113
- data/test/wiring/defaults_test.rb +0 -193
- data/test/wiring/subprocess_test.rb +0 -70
@@ -1,193 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
# class WireDefaultsTest < Minitest::Spec
|
4
|
-
# class C < Trailblazer::Operation
|
5
|
-
# # here, D has a step interface!
|
6
|
-
# D = ->(options, a:raise, b:raise, **) {
|
7
|
-
# options["D"] = [ a, b, options["c"] ]
|
8
|
-
|
9
|
-
# options["D_return"]
|
10
|
-
# }
|
11
|
-
|
12
|
-
# ExceptionFromD = Class.new(Circuit::Signal) # for steps, return value has to be subclass of Signal to be passed through as a signal and not a boolean.
|
13
|
-
# MyEnd = Class.new(Circuit::End)
|
14
|
-
|
15
|
-
# step ->(options, **) { options["a"] = 1 }, id: "a"
|
16
|
-
# step ->(options, **) { options["b"] = 2 }, id: "b"
|
17
|
-
|
18
|
-
# attach MyEnd.new(:myend), id: "End.myend"
|
19
|
-
|
20
|
-
# # step provides defaults:
|
21
|
-
# step D,
|
22
|
-
# outputs: Merge( ExceptionFromD => { role: :exception } ),
|
23
|
-
# connect_to: Merge( exception: "End.myend" ),
|
24
|
-
# id: "d"
|
25
|
-
|
26
|
-
# fail ->(options, **) { options["f"] = 4 }, id: "f"
|
27
|
-
# step ->(options, **) { options["c"] = 3 }, id: "c"
|
28
|
-
# end
|
29
|
-
|
30
|
-
# # normal flow as D sits on the Right track.
|
31
|
-
# it { C.( "D_return" => Circuit::Right).inspect("a", "b", "c", "D", "f").must_equal %{<Result:true [1, 2, 3, [1, 2, nil], nil] >} }
|
32
|
-
# # ends on MyEnd, without hitting fail.
|
33
|
-
# it { C.( "D_return" => C::ExceptionFromD).inspect("a", "b", "c", "D", "f").must_equal %{<Result:false [1, 2, nil, [1, 2, nil], nil] >} } # todo: HOW TO CHECK End instance?
|
34
|
-
# it { C.( "D_return" => Circuit::Left).inspect("a", "b", "c", "D", "f").must_equal %{<Result:false [1, 2, nil, [1, 2, nil], 4] >} } # todo: HOW TO CHECK End instance?
|
35
|
-
# it do
|
36
|
-
# step1 = C["__sequence__"][0].instructions[0].last[:node][0]
|
37
|
-
# step2 = C["__sequence__"][1].instructions[0].last[:node][0]
|
38
|
-
# step3 = C["__sequence__"][3].instructions[0].last[:node][0] # D
|
39
|
-
# step4 = C["__sequence__"][4].instructions[0].last[:node][0]
|
40
|
-
# step5 = C["__sequence__"][5].instructions[0].last[:node][0]
|
41
|
-
|
42
|
-
# require "trailblazer/activity/schema"
|
43
|
-
|
44
|
-
# Output = Trailblazer::Activity::Schema::Output
|
45
|
-
|
46
|
-
# steps = [
|
47
|
-
# [ [:success], step1, [Output.new(Circuit::Right, :success), Output.new(Circuit::Left, :failure)] ],
|
48
|
-
# [ [:success], step2, [Output.new(Circuit::Right, :success), Output.new(Circuit::Left, :failure)] ],
|
49
|
-
|
50
|
-
# [ [:success], step3, [Output.new(Circuit::Right, :success), Output.new(Circuit::Left, :failure), Output.new(C::ExceptionFromD, :exception)] ],
|
51
|
-
# [ [:exception], C::MyEnd.new(:myend), [] ],
|
52
|
-
|
53
|
-
# [ [:failure], step4, [Output.new(Circuit::Right, :failure), Output.new(Circuit::Left, :failure)] ],
|
54
|
-
# [ [:success], step5, [Output.new(Circuit::Right, :success), Output.new(Circuit::Left, :failure)] ],
|
55
|
-
# ]
|
56
|
-
|
57
|
-
# ends = [
|
58
|
-
# [ [:success], Trailblazer::Operation::Railway::End::Success.new(:success), [] ],
|
59
|
-
# [ [:failure], Trailblazer::Operation::Railway::End::Failure.new(:failure), [] ],
|
60
|
-
# ]
|
61
|
-
|
62
|
-
# graph = Trailblazer::Activity::Schema.bla(steps + ends)
|
63
|
-
# circuit = Trailblazer::Activity.new(graph)
|
64
|
-
# # pp schema
|
65
|
-
|
66
|
-
# C["__activity__"] = circuit # this is so wrong
|
67
|
-
# C.( "D_return" => Circuit::Right).inspect("a", "b", "c", "D", "f").must_equal %{<Result:true [1, 2, 3, [1, 2, nil], nil] >}
|
68
|
-
|
69
|
-
# end
|
70
|
-
# end
|
71
|
-
|
72
|
-
# # step :a
|
73
|
-
# # fail :b, connect_to: { Circuit::Right => "End.success" }
|
74
|
-
# # fail :c, connect_to: { Circuit::Right => "End.success" }
|
75
|
-
|
76
|
-
# Connect failure steps to right track, allowing to append steps after.
|
77
|
-
# @see https://github.com/trailblazer/trailblazer/issues/190#issuecomment-326992255
|
78
|
-
class WireDefaultsEarlyExitSuccessTest < Minitest::Spec
|
79
|
-
class Create < Trailblazer::Operation
|
80
|
-
step :a
|
81
|
-
fail :b, Output(:success) => Track(:success) # {}"End.success"
|
82
|
-
fail :c, Output(:success) => Track(:success)
|
83
|
-
|
84
|
-
Test.step(self, :a, :b, :c)
|
85
|
-
end
|
86
|
-
|
87
|
-
# a => true
|
88
|
-
it { Create.(a_return: true, data: []).inspect(:data).must_equal %{<Result:true [[:a]] >} }
|
89
|
-
# b => true
|
90
|
-
it { Create.(a_return: false, b_return: true, data: []).inspect(:data).must_equal %{<Result:true [[:a, :b]] >} }
|
91
|
-
# c => true
|
92
|
-
it { Create.(a_return: false, b_return: false, c_return: true, data: []).inspect(:data).must_equal %{<Result:true [[:a, :b, :c]] >} }
|
93
|
-
# a => b => c => false
|
94
|
-
it { Create.(a_return: false, b_return: false, c_return: false, data: []).inspect(:data).must_equal %{<Result:false [[:a, :b, :c]] >} }
|
95
|
-
|
96
|
-
# # require "trailblazer/developer"
|
97
|
-
# # it { Trailblazer::Developer::Client.push( operation: Create, name: "ushi" ) }
|
98
|
-
|
99
|
-
# #---
|
100
|
-
# # with => Track(:success), steps can still be added before End.success and they will be executed.
|
101
|
-
class Update < Create
|
102
|
-
pass :d
|
103
|
-
|
104
|
-
def d(_options, data:, **)
|
105
|
-
data << :d
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
# a => true
|
110
|
-
it { Update.(a_return: true, data: []).inspect(:data).must_equal %{<Result:true [[:a, :d]] >} }
|
111
|
-
# b => true
|
112
|
-
it { Update.(a_return: false, b_return: true, data: []).inspect(:data).must_equal %{<Result:true [[:a, :b, :d]] >} }
|
113
|
-
# c => true
|
114
|
-
it { Update.(a_return: false, b_return: false, c_return: true, data: []).inspect(:data).must_equal %{<Result:true [[:a, :b, :c, :d]] >} }
|
115
|
-
# a => b => c => false
|
116
|
-
it { Update.(a_return: false, b_return: false, c_return: false, data: []).inspect(:data).must_equal %{<Result:false [[:a, :b, :c]] >} }
|
117
|
-
|
118
|
-
#---
|
119
|
-
# failure steps reference End.success and not just the polarization. This won't call #d in failure=>success case.
|
120
|
-
class Delete < Trailblazer::Operation
|
121
|
-
step :a
|
122
|
-
fail :b, Output(:success) => Id("End.success")
|
123
|
-
fail :c, Output(:success) => Id("End.success")
|
124
|
-
pass :d
|
125
|
-
|
126
|
-
Test.step(self, :a, :b, :c, :d)
|
127
|
-
|
128
|
-
def d(_options, data:, **)
|
129
|
-
data << :d
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
# a => true
|
134
|
-
it { Delete.(a_return: true, data: []).inspect(:data).must_equal %{<Result:true [[:a, :d]] >} }
|
135
|
-
# b => true
|
136
|
-
it { Delete.(a_return: false, b_return: true, data: []).inspect(:data).must_equal %{<Result:true [[:a, :b]] >} }
|
137
|
-
# c => true
|
138
|
-
it { Delete.(a_return: false, b_return: false, c_return: true, data: []).inspect(:data).must_equal %{<Result:true [[:a, :b, :c]] >} }
|
139
|
-
# a => b => c => false
|
140
|
-
it { Delete.(a_return: false, b_return: false, c_return: false, data: []).inspect(:data).must_equal %{<Result:false [[:a, :b, :c]] >} }
|
141
|
-
|
142
|
-
#---
|
143
|
-
# |----|
|
144
|
-
# a --> b c--d --> E.s
|
145
|
-
# |_____|_|_______ E.f
|
146
|
-
class Connect < Trailblazer::Operation
|
147
|
-
step :a
|
148
|
-
step :b, Output(:success) => Id("d")
|
149
|
-
step :c, magnetic_to: [] # otherwise :success will be an open input!
|
150
|
-
pass :d, id: "d"
|
151
|
-
|
152
|
-
Test.step(self, :a, :b, :c)
|
153
|
-
|
154
|
-
def d(_options, data:, **)
|
155
|
-
data << :d
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
# it { puts Trailblazer::Activity::Magnetic::Introspect.seq( Connect.decompose.first ) }
|
160
|
-
|
161
|
-
# a => true
|
162
|
-
it { Connect.(a_return: true, b_return: true, data: []).inspect(:data).must_equal %{<Result:true [[:a, :b, :d]] >} }
|
163
|
-
# a => false
|
164
|
-
it { Connect.(a_return: false, data: []).inspect(:data).must_equal %{<Result:false [[:a]] >} }
|
165
|
-
# b => false
|
166
|
-
it { Connect.(a_return: true, b_return: false, data: []).inspect(:data).must_equal %{<Result:false [[:a, :b]] >} }
|
167
|
-
|
168
|
-
#---
|
169
|
-
# |---------|
|
170
|
-
# | V
|
171
|
-
# a c----d --
|
172
|
-
# |\ ^\ \
|
173
|
-
# | \ / V
|
174
|
-
# |__f____g----E.f
|
175
|
-
class Post < Trailblazer::Operation
|
176
|
-
step :a, Output(:success) => Id("d"), id: "a"
|
177
|
-
fail :f, Output(:success) => Id("c")
|
178
|
-
step :c, magnetic_to: [], id: "c" # otherwise :success will be an open input!
|
179
|
-
fail :g
|
180
|
-
step :d, id: "d"
|
181
|
-
|
182
|
-
Test.step(self, :a, :f, :c, :g, :d)
|
183
|
-
end
|
184
|
-
|
185
|
-
# a => true
|
186
|
-
it { Post.(a_return: true, d_return: true, data: []).inspect(:data).must_equal %{<Result:true [[:a, :d]] >} }
|
187
|
-
# a => false
|
188
|
-
it { Post.(a_return: false, f_return: false, g_return: nil, data: []).inspect(:data).must_equal %{<Result:false [[:a, :f, :g]] >} }
|
189
|
-
# a => false, f => true
|
190
|
-
it { Post.(a_return: false, f_return: true, c_return: true, d_return: true, data: []).inspect(:data).must_equal %{<Result:true [[:a, :f, :c, :d]] >} }
|
191
|
-
# a => false, f => true, c => false
|
192
|
-
it { Post.(a_return: false, f_return: true, c_return: false, g_return: true, data: []).inspect(:data).must_equal %{<Result:false [[:a, :f, :c, :g]] >} }
|
193
|
-
end
|
@@ -1,70 +0,0 @@
|
|
1
|
-
# require "test_helper"
|
2
|
-
|
3
|
-
# class WiringWithNestedTest < Minitest::Spec
|
4
|
-
# MyEnd = Class.new(Trailblazer::Circuit::End)
|
5
|
-
|
6
|
-
# class Create < Trailblazer::Operation
|
7
|
-
# class Edit < Trailblazer::Operation
|
8
|
-
# step :a
|
9
|
-
|
10
|
-
# def a(options, a_return:, **)
|
11
|
-
# options["a"] = 1
|
12
|
-
# a_return
|
13
|
-
# end
|
14
|
-
|
15
|
-
# # operations should expose their outputs with proper naming.
|
16
|
-
# #
|
17
|
-
# # {#<Trailblazer::Operation::Railway::End::Success:0x00000001b22310
|
18
|
-
# # @name=:success,
|
19
|
-
# # @options={}>=>{:role=>:success},
|
20
|
-
# # #<Trailblazer::Operation::Railway::End::Failure:0x00000001b222c0
|
21
|
-
# # @name=:failure,
|
22
|
-
# # @options={}>=>{:role=>:unauthorized}}
|
23
|
-
# def self.outputs
|
24
|
-
# # Outputs::Only(super, :success, :failure)
|
25
|
-
# # Outputs::Update( outputs, failure: { role: :unauthorized} )
|
26
|
-
|
27
|
-
# outs = super.to_a
|
28
|
-
|
29
|
-
# outs = Hash[*(outs[0]+outs[1])]
|
30
|
-
|
31
|
-
# outs.merge( outs.keys[1] => { role: :unauthorized } )
|
32
|
-
# end
|
33
|
-
# end
|
34
|
-
|
35
|
-
# attach MyEnd.new(:myend), id: "End.unauthorized"
|
36
|
-
|
37
|
-
# step ( { task: Trailblazer::Activity::Subprocess( Edit, call: :__call__ ),
|
38
|
-
# node_data: { id: "Nested/" },
|
39
|
-
# outputs: Edit.outputs, # THIS SHOULD OVERRIDE.
|
40
|
-
# connect_to: Merge({ unauthorized: "End.unauthorized" }) # connects :success automatically.
|
41
|
-
# }), fast_track: true
|
42
|
-
|
43
|
-
# step :b
|
44
|
-
# fail :f
|
45
|
-
|
46
|
-
# def b(options, a:, **)
|
47
|
-
# options["b"] = a+1
|
48
|
-
# end
|
49
|
-
|
50
|
-
# def f(options, a:, **)
|
51
|
-
# options["f"] = a+2
|
52
|
-
# end
|
53
|
-
# end
|
54
|
-
|
55
|
-
# # Edit ==> true, will run :b
|
56
|
-
# it do
|
57
|
-
# result = Create.({}, a_return: true )
|
58
|
-
# result.inspect("a", "b", "f").must_equal %{<Result:true [1, 2, nil] >}
|
59
|
-
# result.event.must_be_instance_of Trailblazer::Operation::Railway::End::Success
|
60
|
-
# end
|
61
|
-
|
62
|
-
# # Edit ==> false, will end on End.unauthorized.
|
63
|
-
# it do
|
64
|
-
# result = Create.({}, a_return: false )
|
65
|
-
# result.inspect("a", "b", "f").must_equal %{<Result:false [1, nil, nil] >}
|
66
|
-
# result.event.must_be_instance_of MyEnd
|
67
|
-
|
68
|
-
# # Create.trace({}, a_return: false ).wtf
|
69
|
-
# end
|
70
|
-
# end
|