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

Fallback to textdiffer when csv parsing fails #5876

Merged
merged 4 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
30 changes: 21 additions & 9 deletions app/helpers/renderers/feedback_table_renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -319,17 +319,27 @@
end
end

def differ(t)
if t[:format] == 'csv' && CsvDiffer.limited_columns?(t[:generated]) && CsvDiffer.limited_columns?(t[:expected])
CsvDiffer
def with_differ_class(t)
if t[:format] == 'csv'
begin
if CsvDiffer.limited_columns?(t[:generated]) && CsvDiffer.limited_columns?(t[:expected])
yield(CsvDiffer)
else
yield(TextDiffer)

Check warning on line 328 in app/helpers/renderers/feedback_table_renderer.rb

View check run for this annotation

Codecov / codecov/patch

app/helpers/renderers/feedback_table_renderer.rb#L328

Added line #L328 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add tests to cover fallback when CSV column limits are exceeded

The else branch in the with_differ_class method, where yield(TextDiffer) is called due to column limits being exceeded, is not currently covered by tests as indicated by the static analysis tool. Adding tests for this scenario will ensure that the fallback to TextDiffer functions correctly when CSV inputs exceed column limitations.

Would you like assistance in creating test cases to cover this condition?

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 328-328: app/helpers/renderers/feedback_table_renderer.rb#L328
Added line #L328 was not covered by tests

end
rescue CSV::MalformedCSVError
yield(TextDiffer)
end
else
TextDiffer
yield(TextDiffer)
end
end

def test_accepted(t)
@builder.div(class: 'test-accepted') do
differ(t).render_accepted(@builder, t[:generated])
with_differ_class(t) do |differ_class|
differ_class.render_accepted(@builder, t[:expected])
end
end
end

Expand All @@ -340,10 +350,12 @@
end

def diff(t)
differ = differ(t).new(t[:generated], t[:expected])
@builder.div(class: "diffs show-#{@diff_type}") do
@builder << differ.split
@builder << differ.unified
with_differ_class(t) do |differ_class|
differ = differ_class.new(t[:generated], t[:expected])
@builder.div(class: "diffs show-#{@diff_type}") do
@builder << differ.split
@builder << differ.unified
end
end
end

Expand Down
9 changes: 9 additions & 0 deletions test/controllers/submissions_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -477,4 +477,13 @@ def expected_score_string(*args)

assert_response :ok
end

test 'Should be able to render submission with malformed csv' do
submission = create :wrong_submission, code: 'select * from track where trackid = 1610',
result: '{"accepted":false,"status":"wrong","description":"Test failed","annotations":[{"text":"An SQL query should end with a semicolon","type":"info","row":1,"rows":1,"column":null,"columns":null,"externalUrl":null}],"groups":[{"description":"Result Validation","badgeCount":2,"groups":[{"accepted":false,"groups":[{"description":"Compare results","accepted":false,"tests":[{"expected":"\"title\"\\n\"Grace\"\\n\"Monster\"\\n\"The Greatest Hits\"\\n\"Throwing Copper\"\\n\"Toward the Within\"\\n\"Troublegum\"\\n\"Worst Case Scenario\"","format":"csv","messages":[{"format":"callout-danger","description":"Incorrect row count"}],"generated":"\"title\",\"trackid\",\"genre\",\"albumid\",\"artistid\",\"tracknumber\"\\n\"\"So Fast, So Numb\"\",\"1610\",\"Rock\",\"523\",\"229\",\"12\"","accepted":false}]}]},{"accepted":true,"groups":[{"description":"Column Types","accepted":true,"tests":[{"expected":"\"column\",\"type\"\\n\"title\",\"STRING\"","format":"csv","generated":"\"column\",\"type\"\\n\"title\",\"STRING\"\\n\"trackid\",\"INTEGER\"\\n\"genre\",\"STRING\"\\n\"albumid\",\"INTEGER\"\\n\"artistid\",\"INTEGER\"\\n\"tracknumber\",\"INTEGER\"","accepted":true}]}]},{"accepted":false,"groups":[{"description":"Order By","accepted":false,"tests":[{"expected":"correct order","generated":"incorrect order","accepted":false}]}]}]},{"description":"Query Result","badgeCount":0,"groups":[{"accepted":true,"groups":[{"description":"Full result","accepted":true,"tests":[{"expected":"","format":"csv","generated":"\"title\",\"trackid\",\"genre\",\"albumid\",\"artistid\",\"tracknumber\"\\n\"\"So Fast, So Numb\"\",\"1610\",\"Rock\",\"523\",\"229\",\"12\"","accepted":true}]}]}]}],"messages":[{"format":"html","description":"\\u003cstrong\\u003eWorker:\\u003c/strong\\u003e ixion","permission":"zeus"},{"format":"html","description":"\\u003cstrong\\u003eMemory usage:\\u003c/strong\\u003e 40.61 MiB","permission":"zeus"},{"format":"html","description":"\\u003cstrong\\u003ePrepare:\\u003c/strong\\u003e 0.13 seconds","permission":"zeus"},{"format":"html","description":"\\u003cstrong\\u003eRuntime:\\u003c/strong\\u003e 0.92 seconds","permission":"zeus"},{"format":"html","description":"\\u003cstrong\\u003eResult construction:\\u003c/strong\\u003e 0.02 seconds","permission":"zeus"},{"format":"html","description":"\\u003cstrong\\u003eFinalize:\\u003c/strong\\u003e 0.01 seconds","permission":"zeus"},{"format":"html","description":"\\u003cstrong\\u003eTotal time:\\u003c/strong\\u003e 1.14 seconds","permission":"zeus"}]}'
sign_in submission.user
get submission_path(submission)

assert_response :ok
end
end