From d29bf6617821084b2f281c9b4b6040f83dba9d28 Mon Sep 17 00:00:00 2001 From: Tyler Jang Date: Fri, 17 Apr 2026 04:42:54 +0000 Subject: [PATCH 1/2] working in capybara --- proto/proto/test_context.proto | 2 ++ rspec-trunk-flaky-tests/lib/trunk_spec_helper.rb | 15 ++++++++++++--- test_report/src/report.rs | 11 ++++++----- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/proto/proto/test_context.proto b/proto/proto/test_context.proto index 539e930e..4d9e19b3 100644 --- a/proto/proto/test_context.proto +++ b/proto/proto/test_context.proto @@ -24,7 +24,9 @@ message LineNumber { } message TestOutput { + // Typically the full message, including backtrace if applicable string text = 1; + // Typically the short failure message string message = 2; string system_out = 3; string system_err = 4; diff --git a/rspec-trunk-flaky-tests/lib/trunk_spec_helper.rb b/rspec-trunk-flaky-tests/lib/trunk_spec_helper.rb index bf09c574..e8cd212c 100644 --- a/rspec-trunk-flaky-tests/lib/trunk_spec_helper.rb +++ b/rspec-trunk-flaky-tests/lib/trunk_spec_helper.rb @@ -189,6 +189,8 @@ def run # TrunkAnalyticsListener is a class that is used to listen to the execution of the Example class # it generates and submits the final test reports class TrunkAnalyticsListener + MAX_TEXT_FIELD_SIZE = 8_000 + def initialize @testreport = $test_report end @@ -221,8 +223,15 @@ def close(_notification) # trunk-ignore(rubocop/Metrics/CyclomaticComplexity,rubocop/Metrics/AbcSize,rubocop/Metrics/MethodLength) def add_test_case(example) - failure_message = example.exception.to_s if example.exception - failure_message = example.metadata[:quarantined_exception].to_s if example.metadata[:quarantined_exception] + exception = example.exception || example.metadata[:quarantined_exception] + failure_message = '' + backtrace = '' + if exception + failure_message = exception.to_s + backtrace = exception.backtrace.join("\n") if exception.backtrace && !exception.backtrace.empty? + end + failure_message = failure_message[0...MAX_TEXT_FIELD_SIZE] if failure_message.length > MAX_TEXT_FIELD_SIZE + backtrace = backtrace[0...MAX_TEXT_FIELD_SIZE] if backtrace.length > MAX_TEXT_FIELD_SIZE # TODO: should we use concatenated string or alias when auto-generated description? name = example.full_description file = escape(example.metadata[:file_path]) @@ -247,7 +256,7 @@ def add_test_case(example) parent_name = example.example_group.metadata[:description] parent_name = parent_name.empty? ? 'rspec' : parent_name @testreport.add_test(id, name, classname, file, parent_name, line, status, attempt_number, - started_at, finished_at, failure_message || '', is_quarantined) + started_at, finished_at, failure_message || '', backtrace || '', is_quarantined) end end diff --git a/test_report/src/report.rs b/test_report/src/report.rs index d59312b2..a3254d4b 100644 --- a/test_report/src/report.rs +++ b/test_report/src/report.rs @@ -727,7 +727,8 @@ impl MutTestReport { attempt_number: i32, started_at: i64, finished_at: i64, - output: String, + failure_text: String, + backtrace: String, is_quarantined: bool, ) { let mut test = TestCaseRun::default(); @@ -779,11 +780,11 @@ impl MutTestReport { }; test.finished_at = Some(test_finished_at); // trunk-ignore(clippy/deprecated) - test.status_output_message = output.clone(); + test.status_output_message = failure_text.clone(); if status != Status::Success { test.test_output = Some(TestOutput { - text: output, - message: "".into(), + text: backtrace, + message: failure_text, system_out: "".into(), system_err: "".into(), }); @@ -828,7 +829,7 @@ pub fn ruby_init(ruby: &magnus::Ruby) -> Result<(), magnus::Error> { test_report.define_singleton_method("new", magnus::function!(MutTestReport::new, 3))?; test_report.define_method("to_s", magnus::method!(MutTestReport::to_string, 0))?; test_report.define_method("publish", magnus::method!(MutTestReport::publish, 0))?; - test_report.define_method("add_test", magnus::method!(MutTestReport::add_test, 12))?; + test_report.define_method("add_test", magnus::method!(MutTestReport::add_test, 13))?; test_report.define_method("try_save", magnus::method!(MutTestReport::try_save, 1))?; test_report.define_method( "is_quarantined", From 4d5f80ef523f528c9fb13441dad482be087f4044 Mon Sep 17 00:00:00 2001 From: Tyler Jang Date: Fri, 17 Apr 2026 14:48:25 +0000 Subject: [PATCH 2/2] fix tests --- test_report/tests/report.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test_report/tests/report.rs b/test_report/tests/report.rs index 6318f15f..1622dd56 100644 --- a/test_report/tests/report.rs +++ b/test_report/tests/report.rs @@ -100,6 +100,7 @@ async fn publish_test_report() { 1000, 1001, "test-message".into(), + "test-backtrace".into(), false, ); // call this twice to later validate we only send one request @@ -129,6 +130,7 @@ async fn publish_test_report() { 1000, 1001, "test-message".into(), + "test-backtrace".into(), true, ); let result = test_report.publish(); @@ -270,8 +272,8 @@ async fn publish_test_report() { assert_eq!( test_case_run.test_output, Some(TestOutput { - text: "test-message".into(), - message: "".into(), + text: "test-backtrace".into(), + message: "test-message".into(), system_out: "".into(), system_err: "".into(), }) @@ -369,6 +371,7 @@ async fn test_environment_variable_overrides() { 1000, 1001, "test-message".into(), + "test-backtrace".into(), false, ); let result = test_report.publish(); @@ -500,6 +503,7 @@ async fn test_variant_priority_constructor_over_env() { 1000, 1001, "test-message".into(), + "test-backtrace".into(), false, ); let result = test_report.publish();