diff --git a/app/models/testrun.rb b/app/models/testrun.rb index 18a9b393..be3df12d 100644 --- a/app/models/testrun.rb +++ b/app/models/testrun.rb @@ -17,4 +17,8 @@ class Testrun < ApplicationRecord validates :exit_code, numericality: {only_integer: true, min: 0, max: 255}, allow_nil: true validates :status, presence: true + + def log + testrun_messages.output.select(:log).map(&:log).join.presence + end end diff --git a/app/models/testrun_message.rb b/app/models/testrun_message.rb index eff0b68c..831d9fd2 100644 --- a/app/models/testrun_message.rb +++ b/app/models/testrun_message.rb @@ -33,6 +33,9 @@ class TestrunMessage < ApplicationRecord validates :log, length: {minimum: 0, allow_nil: false}, if: -> { cmd_write? } validate :either_data_or_log + default_scope { order(timestamp: :asc) } + scope :output, -> { where(cmd: 1, stream: %i[stdout stderr]) } + def self.create_for(testrun, messages) # We don't want to store anything if the testrun passed return if testrun.passed? diff --git a/app/views/exercises/external_users/statistics.html.slim b/app/views/exercises/external_users/statistics.html.slim index dc603ab3..e37622fd 100644 --- a/app/views/exercises/external_users/statistics.html.slim +++ b/app/views/exercises/external_users/statistics.html.slim @@ -65,9 +65,9 @@ h1 td.align-middle -this.testruns.includes(:file).order("files.name").each do |run| - if run.passed - .unit-test-result.positive-result title=[run.file&.filepath, run.output].join("\n").strip + .unit-test-result.positive-result title=[run.file&.filepath, run.log].join.strip - else - .unit-test-result.unknown-result title=[run.file&.filepath, run.output].join("\n").strip + .unit-test-result.unknown-result title=[run.file&.filepath, run.log].join.strip td = @working_times_until[index] if index > 0 if policy(@exercise).detailed_statistics? - elsif this.is_a? UserExerciseIntervention td = this.created_at.strftime("%F %T") diff --git a/app/views/request_for_comments/show.html.slim b/app/views/request_for_comments/show.html.slim index 8ab242f9..d6ae99f4 100644 --- a/app/views/request_for_comments/show.html.slim +++ b/app/views/request_for_comments/show.html.slim @@ -38,20 +38,7 @@ .collapsed.testrun-output.text span.fa.fa-chevron-down.collapse-button - output_runs.each do |testrun| - - output = testrun.try(:output) - - if output - - Sentry.set_extras(output: output) - - begin - - Timeout::timeout(2) do - // (?:\\"|.) is required to correctly identify " within the output. - // The outer (?: |\d+?) is used to correctly identify integers within the JSON - - messages = output.scan(/{(?:(?:"(?:\\"|.)+?":(?:"(?:\\"|.)*?"|-?\d+?|\[.*?\]|null))+?,?)+}/) - - messages.map! {|el| JSON.parse(el)} - - messages.keep_if {|message| message['cmd'] == 'write'} - - messages.map! {|message| message['data']} - - output = messages.join '' - - rescue Timeout::Error - pre= output or t('request_for_comments.no_output') + pre= testrun.log or t('request_for_comments.no_output') - assess_runs = testruns.select {|run| run.cause == 'assess' } - unless @current_user.admin? @@ -64,7 +51,7 @@ div class=("result #{testrun.passed ? 'passed' : 'failed'}") .collapsed.testrun-output.text span.fa.fa-chevron-down.collapse-button - pre= testrun.output or t('request_for_comments.no_output') + pre= testrun.log or t('request_for_comments.no_output') - if @current_user.admin? && user.is_a?(ExternalUser) = render('admin_menu')