Skip to content

Commit

Permalink
add a test for making sure we can monkey-patch `Operation.call_with_p…
Browse files Browse the repository at this point in the history
…ublic_interface`

in order to inject "global" taskWrap extensions.
I hate this technique, but as long as we don't have endpoints, this is a "convenient"
way.
  • Loading branch information
apotonick committed Jun 4, 2024
1 parent 67573d4 commit b75c122
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions test/call_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,55 @@ def self.add_1(wrap_ctx, original_args)
assert_equal signal.to_h[:semantic], :success
assert_equal ctx[:seq], [1, :a, 1, 1]
end

#@ test overriding {Operation.call_with_public_interface}
#@
module AfterCall
def self.add_task_name(wrap_ctx, original_args)
(ctx, _flow_options), circuit_options = original_args

activity = circuit_options[:activity] # currently running Activity.
task = wrap_ctx[:task] # the current "step".
task_id = Trailblazer::Activity::Introspect.Nodes(activity, task: task).id

ctx[:seq] << task_id

return wrap_ctx, original_args # yay to mutable state. not.
end
end

it "overrides {call_with_public_interface} and allows injecting {circuit_options} and {flow_options} from the override" do
mod = Module.new do
def call_with_public_interface(ctx, flow_options, **circuit_options)
my_extension = Trailblazer::Activity::TaskWrap::Extension(
[AfterCall.method(:add_task_name), id: "my.add_1", append: "task_wrap.call_task"]
)

super(
ctx,
flow_options.merge({}),
**circuit_options.merge(
wrap_runtime: Hash.new(my_extension),
runner: Trailblazer::Activity::TaskWrap::Runner
)
)
end
end

operation = Class.new(Trailblazer::Operation) do
step :a

include Trailblazer::Activity::Testing.def_steps(:a)
end
operation.extend mod # monkey-patch the "global" Operation.


# circuit interface invocation using call
result = operation.call(
seq: []
)

assert_equal result.success?, true
assert_equal result[:seq], ["Start.default", :a, :a, "End.success", nil] # {nil} because we don't have an ID for the actual operation.
end
end

0 comments on commit b75c122

Please sign in to comment.