diff --git a/lib/trailblazer/pro/debugger.rb b/lib/trailblazer/pro/debugger.rb index 168741b..45822f0 100644 --- a/lib/trailblazer/pro/debugger.rb +++ b/lib/trailblazer/pro/debugger.rb @@ -6,7 +6,7 @@ module Pro def self.invoke_debugger(**kws) _, (ctx, _) = Activity::TaskWrap.invoke(Debugger, [{now: DateTime.now, **kws, output: []}, {}]) - return ctx[:output], [ctx[:session], ctx[:id], ctx[:debugger_url], ctx[:data_to_store], ctx[:session_updated]] + return ctx[:output], ctx#[:session], ctx[:id], ctx[:debugger_url], ctx[:data_to_store], ctx[:session_updated]] end # This is the {:render_method} implementation (for Trace::Present) diff --git a/lib/trailblazer/pro/trace/wtf.rb b/lib/trailblazer/pro/trace/wtf.rb index a084a64..86f0e5c 100644 --- a/lib/trailblazer/pro/trace/wtf.rb +++ b/lib/trailblazer/pro/trace/wtf.rb @@ -21,7 +21,9 @@ def call(*args, present_options: {}, **options) **options ) - (session, _trace_id, _debugger_url, _trace_envelope, session_updated) = returned[-1] + returned_ctx = returned[-1] + + session, session_updated = returned_ctx[:session], returned_ctx[:session_updated] update_session!(session) if session_updated # DISCUSS: this is a hook for pro-rails, not a massive fan. diff --git a/test/debugger_test.rb b/test/debugger_test.rb index a708291..75adb4d 100644 --- a/test/debugger_test.rb +++ b/test/debugger_test.rb @@ -115,7 +115,7 @@ def self.call(ctx, **) assert_equal ctx[:session].trailblazer_pro_host, "https://testbackend-pro.trb.to" end - it "what" do + it "{Pro.invoke_debugger}" do class Create < Trailblazer::Activity::Railway step :model @@ -138,8 +138,9 @@ def model(ctx, **) debugger_trace = returned_args # NOTE: this tests private internals and hence looks a bit clumsy (especially retrieving the {debugger_trace}). - signal, (ctx, _) = Trailblazer::Developer.wtf?(Trailblazer::Pro::Debugger, [ - { + # signal, (ctx, _) = Trailblazer::Developer.wtf?(Trailblazer::Pro::Debugger, [ + output, ctx = Trailblazer::Pro.invoke_debugger( + **{ debugger_trace: debugger_trace, activity: Create, renderer: Trailblazer::Developer::Trace::Present.method(:default_renderer), @@ -149,7 +150,10 @@ def model(ctx, **) # http: stubbed_http, # data_to_store: {fields: {a: 1}}, # firestore_fields_template: session_static_options[:firestore_fields_template], - }, {}]) + } + ) + + assert_equal output.split(".to")[0], %(\e[1m[TRB PRO] view trace (DebuggerAPITest::Create) at \e[22mhttps://ide.trailblazer) assert_equal ctx[:session].class, Trailblazer::Pro::Session # initialized session. assert_equal ctx[:session_updated], true diff --git a/test/present_options_test.rb b/test/present_options_test.rb index ea5c55d..3652e27 100644 --- a/test/present_options_test.rb +++ b/test/present_options_test.rb @@ -14,7 +14,7 @@ def model(ctx, **) it "with {render_wtf: true}" do ctx = {} - signal, (ctx, _), _, output, (token, trace_id, debugger_url, trace_envelope) = Trailblazer::Developer.wtf?( + signal, (ctx, _), _, output, returned_ctx = Trailblazer::Developer.wtf?( Create, [ctx, {}], present_options: {render_method: Trailblazer::Pro.method(:invoke_debugger), session: uninitialized_session, render_wtf: true}, # FIXME: why do we have to pass {:session} here? @@ -24,34 +24,35 @@ def model(ctx, **) |-- \e[32mStart.default\e[0m |-- \e[32mmodel\e[0m `-- End.success -\e[1m[TRB PRO] view trace (PresentOptionsTest::Create) at \e[22mhttps://ide.trailblazer.to/#{trace_id}) +\e[1m[TRB PRO] view trace (PresentOptionsTest::Create) at \e[22mhttps://ide.trailblazer.to/#{returned_ctx[:id]}) end it "with {render_wtf: false}" do ctx = {} - signal, (ctx, _), _, output, (token, trace_id, debugger_url, trace_envelope) = Trailblazer::Developer.wtf?( + signal, (ctx, _), _, output, returned_ctx = Trailblazer::Developer.wtf?( Create, [ctx, {}], present_options: {render_method: Trailblazer::Pro.method(:invoke_debugger), session: uninitialized_session, render_wtf: false}, # FIXME: why do we have to pass {:session} here? ) - assert_equal output, %(\e[1m[TRB PRO] view trace (PresentOptionsTest::Create) at \e[22mhttps://ide.trailblazer.to/#{trace_id}) + assert_equal output, %(\e[1m[TRB PRO] view trace (PresentOptionsTest::Create) at \e[22mhttps://ide.trailblazer.to/#{returned_ctx[:id]}) end # test if trace has expected elements it "returned trace data is correct" do ctx = {} - signal, (ctx, _), _, output, (token, trace_id, debugger_url, trace_envelope) = Trailblazer::Developer.wtf?( + signal, (ctx, _), _, output, returned_ctx = Trailblazer::Developer.wtf?( Create, [ctx, {}], present_options: {render_method: Trailblazer::Pro.method(:invoke_debugger), session: uninitialized_session}, ) - assert_equal trace_id.size, 20 - assert_equal debugger_url, "https://ide.trailblazer.to/#{trace_id}" + assert_equal returned_ctx[:id].size, 20 + assert_equal returned_ctx[:debugger_url], "https://ide.trailblazer.to/#{returned_ctx[:id]}" + trace_envelope = returned_ctx[:data_to_store] assert_equal trace_envelope[:fields].keys, [:activity_name, :trace, :created_at] assert_equal trace_envelope[:fields][:activity_name], {:stringValue=>PresentOptionsTest::Create} assert trace_envelope[:fields][:created_at][:timestampValue] < DateTime.now diff --git a/test/wtf_test.rb b/test/wtf_test.rb index 6207535..6532ce6 100644 --- a/test/wtf_test.rb +++ b/test/wtf_test.rb @@ -28,8 +28,11 @@ def model(ctx, **) # Uninitialized session. assert_equal Trailblazer::Pro::Session.session.to_h, {api_key: api_key, trailblazer_pro_host: trailblazer_pro_host} - signal, (ctx, _), _, output, (session, trace_id, debugger_url, _trace_envelope) = Trailblazer::Pro::Trace::Wtf.call(Create, [{}, {}]) + signal, (ctx, _), _, output, returned_ctx = Trailblazer::Pro::Trace::Wtf.call(Create, [{}, {}]) + trace_id = returned_ctx[:id] + session = returned_ctx[:session] + debugger_url = returned_ctx[:debugger_url] assert_equal trace_id.size, 20 assert_equal debugger_url, "https://ide.trailblazer.to/#{trace_id}" @@ -38,7 +41,11 @@ def model(ctx, **) session_1_hash = assert_session({session: session}, **session_static_options) #@ while session is valid, do another call. - signal, (ctx, _), _, output, (session_2, trace_id_2, debugger_url_2, _trace_envelope) = Trailblazer::Pro::Trace::Wtf.call(Create, [ctx, {}]) + signal, (ctx, _), _, output, returned_ctx_2 = Trailblazer::Pro::Trace::Wtf.call(Create, [ctx, {}]) + + trace_id_2 = returned_ctx_2[:id] + session_2 = returned_ctx_2[:session] + debugger_url_2 = returned_ctx_2[:debugger_url] assert_equal trace_id_2.size, 20 assert_equal debugger_url_2, "https://ide.trailblazer.to/#{trace_id_2}" @@ -50,9 +57,13 @@ def model(ctx, **) assert_equal session_1_hash[:id_token], session_2_hash[:id_token] #@ simulate time out, new token required. - signal, (ctx, _), _, output, (session_3, trace_id_3, debugger_url_3, _trace_envelope) = + signal, (ctx, _), _, output, returned_ctx_3 = Trailblazer::Pro::Trace::Wtf.call(Create, [ctx, {}], present_options: {now: DateTime.now + (60 * 1000)}) + trace_id_3 = returned_ctx_3[:id] + session_3 = returned_ctx_3[:session] + debugger_url_3 = returned_ctx_3[:debugger_url] + assert_equal trace_id_3.size, 20 assert_equal debugger_url_3, "https://ide.trailblazer.to/#{trace_id_3}" assert trace_id != trace_id_3 @@ -73,7 +84,11 @@ def model(ctx, **) Trailblazer::Pro.initialize!(**session_4) - signal, (ctx, _), _, output, (session_5, trace_id_5, debugger_url_5, _trace_envelope) = Trailblazer::Pro::Trace::Wtf.call(Create, [ctx, {}]) + signal, (ctx, _), _, output, returned_ctx_5 = Trailblazer::Pro::Trace::Wtf.call(Create, [ctx, {}]) + + trace_id_5 = returned_ctx_5[:id] + session_5 = returned_ctx_5[:session] + debugger_url_5 = returned_ctx_5[:debugger_url] assert_equal trace_id_5.size, 20 assert_equal debugger_url_5, "https://ide.trailblazer.to/#{trace_id_5}" @@ -91,7 +106,11 @@ def model(ctx, **) render_wtf: false, ) - signal, (ctx, _), _, output, (session, trace_id, debugger_url, _trace_envelope) = Trailblazer::Pro::Trace::Wtf.call(Create, [{}, {}]) + signal, (ctx, _), _, output, returned_ctx = Trailblazer::Pro::Trace::Wtf.call(Create, [{}, {}]) + + trace_id = returned_ctx[:id] + session = returned_ctx[:session] + debugger_url = returned_ctx[:debugger_url] assert_equal output, %(\e[1m[TRB PRO] view trace (WtfTest::Create) at \e[22mhttps://ide.trailblazer.to/#{trace_id}) assert_equal trace_id.size, 20 @@ -105,7 +124,11 @@ def model(ctx, **) render_wtf: true, ) - signal, (ctx, _), _, output, (session, trace_id, debugger_url, _trace_envelope) = Trailblazer::Pro::Trace::Wtf.call(Create, [{}, {}]) + signal, (ctx, _), _, output, returned_ctx = Trailblazer::Pro::Trace::Wtf.call(Create, [{}, {}]) + + trace_id = returned_ctx[:id] + session = returned_ctx[:session] + debugger_url = returned_ctx[:debugger_url] assert_equal output, %(WtfTest::Create |-- \e[32mStart.default\e[0m @@ -124,7 +147,7 @@ def model(ctx, **) # render_wtf: false, ) - signal, (ctx, _), _, output, (session, trace_id, debugger_url, _trace_envelope) = Trailblazer::Pro::Trace::Wtf.call(Create, [{}, {}]) + signal, (ctx, _), _, output, _returned_ctx = Trailblazer::Pro::Trace::Wtf.call(Create, [{}, {}]) assert_equal output, %(WtfTest::Create |-- \e[32mStart.default\e[0m