Extract additional context builder into its own service

What does this MR do and why?

The additional-context envelope building logic in StartWorkflowService (the code that assembles DUO_WORKFLOW_ADDITIONAL_CONTEXT_CONTENT) had grown large enough to warrant its own class, so this pulls it out into Ai::DuoWorkflows::BuildAdditionalContextService.

The extraction itself had a few loose ends that needed tying up before it could ship: the call site referenced the wrong module (Ai::DuoWorkflow instead of Ai::DuoWorkflows), it called the new service with no arguments even though project: and current_user: are required, and the new service changed the wire format (Content as a raw hash instead of the JSON-encoded string the Duo Workflow Service expects) and the envelope ordering. This MR wires the call site up correctly and keeps the new service's output identical to the original inline implementation.

References

None.

Screenshots or screen recordings

N/A - backend-only service refactor, no UI changes.

How to set up and validate locally

  1. Run the service specs covering this behavior:
    bundle exec rspec ee/spec/services/ai/duo_workflows/start_workflow_service_spec.rb ee/spec/services/ai/duo_workflows/build_additional_context_service_spec.rb
  2. All 162 examples should pass (148 pre-existing + 14 new, added to cover BuildAdditionalContextService directly).

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Merge request reports

Loading
Loading