diff --git a/Changelog.md b/Changelog.md index a168e7a906..3c94d82dc0 100644 --- a/Changelog.md +++ b/Changelog.md @@ -8,6 +8,7 @@ ### ✨ New features and improvements - Added a confirm dialog to the Upload Scans form that appears when no template divisions are assigned to the selected exam template (#7993) +- Forward the test batch id to the autotester so AI grading telemetry can attribute mass-grading runs (#7991) - Migrated `MarkingSchemesTable` component to React Table V8 (#7985) - Removed Graders Subcomponent and added a Graders column in the Assignment Grades tab (#7967) - Added GET and PATCH /overall_comment API routes (#7963) diff --git a/app/helpers/automated_tests_helper.rb b/app/helpers/automated_tests_helper.rb index 9666027a84..365ee9ecaf 100644 --- a/app/helpers/automated_tests_helper.rb +++ b/app/helpers/automated_tests_helper.rb @@ -111,10 +111,11 @@ def test_data(test_run_ids) end def get_markus_address(host_with_port) + base = ENV.fetch('MARKUS_URL', host_with_port) if Rails.application.config.relative_url_root.nil? - host_with_port + base else - host_with_port + Rails.application.config.relative_url_root + base + Rails.application.config.relative_url_root end end @@ -209,6 +210,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) @@ -307,10 +310,11 @@ def set_headers(req, api_key) # 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) + base = ENV.fetch('MARKUS_URL', host_with_port) if Rails.application.config.relative_url_root.nil? - host_with_port + base else - host_with_port + Rails.application.config.relative_url_root + base + Rails.application.config.relative_url_root end end diff --git a/spec/jobs/autotest_run_job_spec.rb b/spec/jobs/autotest_run_job_spec.rb index 00512018c7..72a447beae 100644 --- a/spec/jobs/autotest_run_job_spec.rb +++ b/spec/jobs/autotest_run_job_spec.rb @@ -287,6 +287,28 @@ 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 end context 'tests are not set up' do