Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken pythia submission if data is not present in group #5235

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions app/helpers/renderers/pythia_renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@ def parse
def show_code_tab
return true unless @result[:groups]

@result[:groups].none? { |t| t[:data][:source_annotations] }
@result[:groups].none? { |t| t[:data] && t[:data][:source_annotations] }
end

def tab_content(t, i)
if t[:data][:source_annotations]
if t[:data] && t[:data][:source_annotations]
linting(t[:data][:source_annotations], @code)
else
super
end
end

def diff(t)
if t[:data][:diff]
if t[:data] && t[:data][:diff]
pythia_diff(t[:data][:diff])
else
super
end
end

def test_accepted(t)
if t[:data][:diff]
if t[:data] && t[:data][:diff]
@builder.div(class: 'test-accepted') do
@builder.span(class: 'output') do
html = t[:data][:diff].map do |l|
Expand Down Expand Up @@ -227,7 +227,7 @@ def convert_lint_message(message)
end

def determine_diff_type(test)
if test[:data][:diff]
if test[:data] && test[:data][:diff]
test[:data][:diff].each do |diff_line|
# Not perfect, since there might be html in the diff_line items
return 'unified' if !diff_line[2].nil? && strip_outer_html(diff_line[2]).length >= 55
Expand Down
24 changes: 24 additions & 0 deletions test/controllers/submissions_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -436,4 +436,28 @@ def expected_score_string(*args)
assert_equal least_recent.id, response.parsed_body.first['id']
assert_equal most_recent.id, response.parsed_body.second['id']
end

test 'rendering pythia submission should not crash' do
stub_git(Judge.any_instance)
judge = create :judge, name: 'pythia', renderer: PythiaRenderer
exercise = create :exercise, judge: judge
submission = create :submission, :wrong, exercise: exercise
submission.result = '{
"accepted": false,
"status": "wrong",
"description": "Onverwachte uitvoer",
"annotations": [],
"groups": [
{
"description": "maximum",
"badgeCount": 6,
"groups": []
}
],
"messages": []
}'
get submission_path(submission)

assert_response :ok
end
end