diff --git a/app/controllers/test_runs_controller.rb b/app/controllers/test_runs_controller.rb index cb353c9..5b7d77f 100644 --- a/app/controllers/test_runs_controller.rb +++ b/app/controllers/test_runs_controller.rb @@ -32,7 +32,7 @@ def create respond_to do |format| if @test_run.save - TestRunJob.perform_later(@test_run.id) + TestRunJob.perform_later(@test_run.id) unless @test_run.manual_execution? format.html { redirect_to test_run_url(@test_run), notice: 'Test model version run was successfully created.' } format.json { render :show, status: :created, location: @test_run } else @@ -51,7 +51,7 @@ def set_test_run # Only allow a list of trusted parameters through. def test_run_params - params.require(:test_run).permit(:name, :prompt_id, :calls, :passing_threshold, assertion_ids: []).tap do |permited| + params.require(:test_run).permit(:name, :prompt_id, :calls, :passing_threshold, :manual_execution, assertion_ids: []).tap do |permited| model_version_ids = params[:test_run][:model_version_ids]&.select(&:present?) if model_version_ids.present? permited[:test_model_version_runs_attributes] = model_version_ids.map do |model_version_id| diff --git a/app/views/test_runs/_form.html.erb b/app/views/test_runs/_form.html.erb index 3e2cb4b..a3596ef 100644 --- a/app/views/test_runs/_form.html.erb +++ b/app/views/test_runs/_form.html.erb @@ -37,6 +37,10 @@ <%= form.label 'Passing threshold in %' %> <%= form.number_field :passing_threshold, step: '0.01', max: 100, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %> +
+ <%= form.check_box :manual_execution %> + <%= form.label :manual_execution %> +
<%= form.submit class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %> diff --git a/db/migrate/20240819134918_add_manual_execution_to_test_run.rb b/db/migrate/20240819134918_add_manual_execution_to_test_run.rb new file mode 100644 index 0000000..b14d025 --- /dev/null +++ b/db/migrate/20240819134918_add_manual_execution_to_test_run.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddManualExecutionToTestRun < ActiveRecord::Migration[7.1] + def change + add_column :test_runs, :manual_execution, :boolean, null: false, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 8a1fb0e..ca8d538 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -12,7 +12,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 20_240_812_150_858) do +ActiveRecord::Schema[7.1].define(version: 20_240_819_134_918) do # These are extensions that must be enabled in order to support this database enable_extension 'plpgsql' @@ -235,6 +235,7 @@ t.datetime 'updated_at', null: false t.float 'passing_threshold', default: 0.0 t.string 'name' + t.boolean 'manual_execution', default: false, null: false t.index ['prompt_id'], name: 'index_test_runs_on_prompt_id' end diff --git a/spec/controllers/test_runs_controller_spec.rb b/spec/controllers/test_runs_controller_spec.rb index 8d6fb0b..e1e8706 100644 --- a/spec/controllers/test_runs_controller_spec.rb +++ b/spec/controllers/test_runs_controller_spec.rb @@ -86,6 +86,18 @@ expect(response.content_type).to eq('application/json; charset=utf-8') expect(response.location).to eq(test_run_url(TestRun.reorder(:created_at).last)) end + + context 'with manual_execution param' do + before do + valid_attributes[:manual_execution] = '1' + allow(SolidQueue::Job).to receive(:enqueue) + end + + it 'does not enqueue a TestRunJob' do + post :create, params: { test_run: valid_attributes } + expect(SolidQueue::Job).not_to have_received(:enqueue) + end + end end end end