class Tryouts::CLI::TestRunState

def update_from_event(event_type, *args, **_kwargs)

Update state based on formatter events using pattern matching
def update_from_event(event_type, *args, **_kwargs)
  case event_type
  in :phase_header
    _, file_count, level = args
    if level == 0 && file_count
      with(total_files: file_count, start_time: Time.now)
    else
      self
    end
  in :file_start
    file_path   = args[0]
    pretty_path = Console.pretty_path(file_path)
    with(current_file: pretty_path)
  in :file_end
    with(
      files_completed: files_completed + 1,
      current_file: nil,
    )
  in :test_start
    test_case = args[0]
    desc      = test_case.description.to_s
    desc      = "test #{args[1]}" if desc.empty?
    with(current_test: desc)
  in :test_end
    with(current_test: nil)
  in :test_result
    result_packet = args[0]
    updated_state = with(total_tests: total_tests + 1)
    case result_packet.status
    when :passed
      updated_state.with(passed: passed + 1)
    when :failed
      updated_state.with(failed: failed + 1)
    when :error
      updated_state.with(errors: errors + 1)
    else
      updated_state
    end
  else
    # Unknown event, return unchanged state
    self
  end
end