Build Duo Agent Platform session URLs with Gitlab::UrlBuilder
Fixes https://new-sentry.gitlab.net/organizations/gitlab/issues/3973765/
What does this MR do and why?
GraphQL queries for webUrl on a DuoWorkflow were raising
NotImplementedError: No URL builder defined for #<Ai::DuoWorkflows::Workflow ...>:
Types::Ai::DuoWorkflows::WorkflowType implements Types::TodoableInterface (which
declares field :web_url) and presents through WorkflowPresenter, so the field
resolved via Gitlab::View::Presenter::Base#web_url → Gitlab::UrlBuilder.build,
which had no case for a workflow.
While this MR was open, !248587 (merged)
added an explicit WorkflowPresenter#web_url that delegates to the model, which stops
the exception. So the crash is already fixed on master.
What is left here is the underlying gap: Gitlab::UrlBuilder still does not know how to
build a URL for a session, so the presenter needs its own override, and every other
caller builds the URL by hand. This MR adds the workflow case to the EE URL builder and
makes Ai::DuoWorkflows::Workflow#web_url delegate to it. The builder uses the named
project_automate_agent_session route instead of appending the ID to the index route,
and returns nil for namespace-level sessions, matching the model's previous behaviour.
The generated URL is byte-identical to the previous string concatenation, so nothing user-facing changes.
How to set up and validate locally
In a Rails console, with a project-level session:
workflow = Ai::DuoWorkflows::Workflow.last
Gitlab::UrlBuilder.build(workflow)
# => "http://gdk.test:3000/<project_full_path>/-/automate/agent-sessions/<id>"
Gitlab::UrlBuilder.build(workflow, only_path: true)
# => "/<project_full_path>/-/automate/agent-sessions/<id>"On master, the first call raises NotImplementedError.
MR acceptance checklist
- Tested locally:
ee/spec/lib/ee/gitlab/url_builder_spec.rb(72 examples), the#web_urlblock inee/spec/models/ai/duo_workflows/workflow_spec.rb,ee/spec/presenters/ai/duo_workflows/workflow_presenter_spec.rb,ee/spec/graphql/types/ai/duo_workflows/workflow_type_spec.rb, and the specs of the remainingworkflow.web_urlcallers (start_workflow_service, Slack and GitLab Duo note messaging adapters) — all pass.