|
| 1 | +require "rails_helper" |
| 2 | + |
| 3 | +RSpec.describe "Admin::ClassificationRuns", type: :request do |
| 4 | + let(:group) { create(:feature_group, name: "FOR PORTION OF") } |
| 5 | + let(:linked) { create(:topic, title: "Earlier temporal thread") } |
| 6 | + let(:result) do |
| 7 | + { "kind" => "feature", "size" => "major", "enhancement" => false, "not_a_bug" => false, |
| 8 | + "group" => { "id" => group.id, "new_name" => nil, "new_summary" => nil }, "join_linked" => [ linked.id ], |
| 9 | + "feature_name" => "UPDATE/DELETE FOR PORTION OF", "evidence" => [ "[001] adds FOR PORTION OF" ], "confidence" => "high" } |
| 10 | + end |
| 11 | + |
| 12 | + before { create(:release_tag, name: Classify::Scope::WINDOW_TAG, released_at: 3.years.ago) } |
| 13 | + |
| 14 | + it "redirects non-admins" do |
| 15 | + sign_in_as(create(:user, admin: false)) |
| 16 | + get admin_classification_runs_path |
| 17 | + expect(response).to redirect_to(root_path) |
| 18 | + end |
| 19 | + |
| 20 | + describe "as admin" do |
| 21 | + before { sign_in_as(create(:user, admin: true)) } |
| 22 | + |
| 23 | + let!(:done) do |
| 24 | + create(:classification_run, topic: create(:topic, title: "Temporal update"), phase: "backfill", kind: "feature", size: "major", |
| 25 | + enhancement: false, feature_group: group, model: "gpt-6.2-sol", effort: "medium", |
| 26 | + input_tokens: 4321, cached_input_tokens: 100, output_tokens: 50, duration_s: 12.0, result:) |
| 27 | + end |
| 28 | + let!(:failed) do |
| 29 | + create(:classification_run, topic: create(:topic, title: "Broken run"), status: "failed", failure_kind: "schema", |
| 30 | + error: "schema: missing kind", input_tokens: 10) |
| 31 | + end |
| 32 | + |
| 33 | + it "lists runs with queue and status counts" do |
| 34 | + get admin_classification_runs_path(sort: "tokens") |
| 35 | + expect(response).to have_http_status(:ok) |
| 36 | + expect(response.body).to include("Temporal update", "Broken run", "4321", "FOR PORTION OF", "major", "schema") |
| 37 | + expect(response.body).to include("backfill:", "remaining", "done: 1", "failed: 1") |
| 38 | + expect(response.body.index("Temporal update")).to be < response.body.index("Broken run") |
| 39 | + end |
| 40 | + |
| 41 | + it "filters by status" do |
| 42 | + get admin_classification_runs_path(status: "failed") |
| 43 | + expect(response.body).to include("Broken run") |
| 44 | + expect(response.body).not_to include("Temporal update") |
| 45 | + end |
| 46 | + |
| 47 | + it "shows the answer of a run" do |
| 48 | + get admin_classification_run_path(done) |
| 49 | + expect(response).to have_http_status(:ok) |
| 50 | + expect(response.body).to include("UPDATE/DELETE FOR PORTION OF", "[001] adds FOR PORTION OF", "Earlier temporal thread", "gpt-6.2-sol / medium") |
| 51 | + expect(response.body).not_to include("Requeue") |
| 52 | + end |
| 53 | + |
| 54 | + it "shows the error and requeues a failed run" do |
| 55 | + get admin_classification_run_path(failed) |
| 56 | + expect(response.body).to include("schema: missing kind", "Requeue") |
| 57 | + post requeue_admin_classification_run_path(failed) |
| 58 | + expect(ClassificationRun.exists?(failed.id)).to be(false) |
| 59 | + expect(flash[:notice]).to be_present |
| 60 | + end |
| 61 | + |
| 62 | + it "does not requeue a done run" do |
| 63 | + post requeue_admin_classification_run_path(done) |
| 64 | + expect(ClassificationRun.exists?(done.id)).to be(true) |
| 65 | + expect(flash[:alert]).to be_present |
| 66 | + end |
| 67 | + end |
| 68 | +end |
0 commit comments