Skip to content
Open
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
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Updated links to refer to new documentation website (#8049)
- Added a submissions table filter option that lets graders with manage submissions permission view either all submissions or only their assigned submissions (#8047)
- Added a submission scope filter to the grading view so TAs with manage submissions permission can navigate either all submissions or only their assigned submissions (#8046)
- Forward the test batch id to the autotester so AI grading telemetry can attribute mass-grading runs (#7991)
- Removed Graders Subcomponent and added a Graders column in the Assignment Grades tab (#7967)
- Added GET /test_runs API route (#8055)

Expand Down
20 changes: 6 additions & 14 deletions app/helpers/automated_tests_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,11 @@ def test_data(test_run_ids)
.each { |h| h[:test_categories] = [h['user_type'].downcase] }
end

# Get the current URL for this MarkUs instance, with the relative url root appended if it exists.
# +MARKUS_URL+ overrides +host_with_port+ to give the autotester an address it can reach.
def get_markus_address(host_with_port)
if Rails.application.config.relative_url_root.nil?
host_with_port
else
host_with_port + Rails.application.config.relative_url_root
end
base = ENV['MARKUS_URL'].presence || host_with_port
"#{base}#{Rails.application.config.relative_url_root}"
end

# Sends RESTful api requests to the autotester
Expand Down Expand Up @@ -209,6 +208,8 @@ def run_tests(assignment, host_with_port, group_ids, role, collected: true, batc
req.body = {
test_data: test_data,
categories: role.student? ? ['student'] : ['instructor'],
# Maps to TestBatch.id for telemetry attribution; null for solo runs.
batch_id: batch&.id,
request_high_priority: batch.nil? && role.student?
}.to_json
res = send_request!(req, uri)
Expand Down Expand Up @@ -305,15 +306,6 @@ def set_headers(req, api_key)
req['Content-Type'] = 'application/json'
end

# Get the current URL for this MarkUs instance (adds the relative url root to +host_with_port+) if it exists.
def get_markus_address(host_with_port)
if Rails.application.config.relative_url_root.nil?
host_with_port
else
host_with_port + Rails.application.config.relative_url_root
end
end

# Gets the feedback file data from the autotester for the TestRun with autotest_test_id = +test_id+
# and adds it to the +results+ hash.
def add_feedback_data(results, settings_id, test_id, autotest_setting)
Expand Down
47 changes: 47 additions & 0 deletions spec/jobs/autotest_run_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
let(:role) { create(:instructor) }

before do
# MARKUS_URL overrides host_with_port when set, so unset it here to keep these
# expectations independent of the developer's environment.
stub_const('ENV', ENV.to_h.except('MARKUS_URL'))
allow_any_instance_of(AutotestSetting).to(
receive(:send_request!).and_return(OpenStruct.new(body: { api_key: 'someapikey' }.to_json))
)
Expand Down Expand Up @@ -287,6 +290,50 @@
end
end
end

context 'batch_id attribution' do
it 'forwards the batch id for a multi-group run' do
expect_any_instance_of(AutotestRunJob).to receive(:send_request!) do |_j, net_obj|
expect(JSON.parse(net_obj.body)['batch_id']).to eq TestBatch.first.id
dummy_return
end
subject
end

context 'when there is a single group' do
let(:n_groups) { 1 }

it 'forwards a null batch id for a solo run' do
expect_any_instance_of(AutotestRunJob).to receive(:send_request!) do |_j, net_obj|
expect(JSON.parse(net_obj.body)).to include('batch_id' => nil)
dummy_return
end
subject
end
end
end

context 'file_url host' do
it 'uses MARKUS_URL when set, since the autotester may not reach the browser-facing host' do
stub_const('ENV', ENV.to_h.merge('MARKUS_URL' => 'http://autotest-reachable:3000'))
expect_any_instance_of(AutotestRunJob).to receive(:send_request!) do |_j, net_obj|
urls = JSON.parse(net_obj.body)['test_data'].pluck('file_url')
expect(urls).to all(start_with('http://autotest-reachable:3000/'))
dummy_return
end
subject
end

it 'falls back to host_with_port when MARKUS_URL is set but empty' do
stub_const('ENV', ENV.to_h.merge('MARKUS_URL' => ''))
expect_any_instance_of(AutotestRunJob).to receive(:send_request!) do |_j, net_obj|
urls = JSON.parse(net_obj.body)['test_data'].pluck('file_url')
expect(urls).to all(start_with("#{host_with_port}/"))
dummy_return
end
subject
end
end
end

context 'tests are not set up' do
Expand Down