Read the workplan readiness score from GraphQL

What does this MR do?

Reads the workplan confidence score from WorkItemWidgetAgentPlan.readinessScore and removes the Math.random() mock.

The field is requested behind @include(if: $includeReadinessScore), driven by the default-off workplan_score flag. The API returns 0-100, so the component and its thresholds move to that scale. First commit move the agent plan query into work_item_ai_widget.vue so the score component (a sibling of the work plan) can read it; no behaviour change.

Note: We discussed the score to actually live on the work item instead of the plan, so if the plan field ever moved out of the Agent Plan, it would require a separate query, but I still believe the right place for it would be on the ai widget itself and not have the component for scoring self-fetch.

Related to #608260 (closed)

Steps to reproduce

Nothing writes readiness_score yet, so the widget shows no score until one is seeded.

  1. Save the script below as fake_readiness_score.rb at the repo root. It is a throwaway script for local testing, not part of this MR's diff.
  2. Run bundle exec rails runner fake_readiness_score.rb. It enables workplan and workplan_score for the work item's root namespace and seeds a fake readiness score.
  3. Open the work item the script targets (project gitlab-duo/test, IID 64 by default).
  4. Confirm the confidence score is stable across reloads instead of changing every time.
  5. Edit and save the workplan content, then confirm the score does not blank out.
  6. Disable the workplan_score flag, reload, and confirm readinessScore is absent from the GraphQL request payload.

Set SCORE to test different component thresholds (default 72, 0-100). Target a different work item with WORK_ITEM_IID (the number in the work item URL), setting PROJECT if it's outside gitlab-duo/test. Example: SCORE=35 WORK_ITEM_IID=42 bundle exec rails runner fake_readiness_score.rb.

fake_readiness_score.rb (throwaway script, not part of this MR)
# Seeds a fake readiness score on a work item's agent plan so the confidence
# score UI has something to render locally.
#
#   bundle exec rails runner fake_readiness_score.rb
#
# Env vars (defaults: PROJECT=gitlab-duo/test, WORK_ITEM_IID=64, SCORE=72):
#   SCORE=35 bundle exec rails runner fake_readiness_score.rb
#   WORK_ITEM_IID=42 bundle exec rails runner fake_readiness_score.rb
#   PROJECT=path/to/project WORK_ITEM_IID=42 bundle exec rails runner fake_readiness_score.rb
#
# WORK_ITEM_IID is the number in the work item URL.
# Set PROJECT when the work item lives outside gitlab-duo/test.

project = Project.find_by_full_path(ENV.fetch('PROJECT', 'gitlab-duo/test'))
abort 'Project not found. Set PROJECT=<full/path>.' unless project

work_item = WorkItem.find_by(project_id: project.id, iid: ENV.fetch('WORK_ITEM_IID', '64'))
abort 'Work item not found. Set WORK_ITEM_IID=<iid>.' unless work_item

score = Integer(ENV.fetch('SCORE', '72'))
root = work_item.namespace.root_ancestor

Feature.enable(:workplan, root)
Feature.enable(:workplan_score, root)

plan = work_item.agent_plan || work_item.build_agent_plan
plan.ai_planning_enabled = true
plan.readiness_score = score

if plan.content.blank?
  plan.content = <<~MARKDOWN
    ## Plan

    1. Reproduce the reported behaviour locally.
    1. Add a failing test that captures it.
    1. Ship the fix behind the existing feature flag.
  MARKDOWN
end

plan.readiness_score_feedback = <<~MARKDOWN
  The plan states a clear goal and lists concrete steps, so an agent can start
  without guessing.

  **What would raise the score**

  - Name the files or components the change touches.
  - Say how the fix is verified beyond "add a test".
MARKDOWN

plan.save!

puts "work item ##{work_item.iid} (#{work_item.title})"
puts "readiness_score: #{plan.reload.readiness_score}"
puts "flags workplan/workplan_score enabled for #{root.full_path}"

Video

Edited by Frédéric Caplette

Merge request reports

Loading
Loading