Add xray context to /refactor, /fix, and /tests
What does this MR do and why?
The Repository X-Ray is a tool that searches for dependency manager configuration/lock files and then extracts a list of libraries from the content.
This MR adds fetches the latest xray report (if available) for a project and includes this xray_data
in the prompt_options
that are passed to the aigw for slash commands including /refactor
, /fix
, and /tests
. This will allow us to include the xray report into the corresponding prompts. Given this context the refactoring/fixing/test should be more relevant and higher quality code.
References
Please include cross links to any resources that are relevant to this MR. This will give reviewers and future readers helpful context to give an efficient review of the changes introduced.
For #450753 (closed)
- This MR solves the monolith part
- gitlab-org/modelops/applied-ml/code-suggestions/ai-assist!1680 (merged) solves the aigw part
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Screenshots or screen recordings
/refactor
:
Graphql mutation to trigger
Change content: "/fix"
and content: "/tests"
to verify the other slash commands.
xray_data
in prompt_options
on the monolith side
Rails logs with /refactor
/fix
/tests
xray_data
in the prompt_request
AIGW logs with /refactor
/fix
/tests
Video showing end to end the xray data being passed from the monolith to the aigw
Screen_Recording_2024-11-26_at_10.05.28_AM
How to set up and validate locally
- Follow the validation steps in this related MR to trigger creating an xray report for a project in gdk. Make a note of the project id where the xray report was generated: !165391 (merged)
- Inside https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/lib/gitlab/llm/chain/concerns/ai_dependent.rb#L15 after line 14 add a print statement similar to
puts("prompt_options = #{prompt_options}")
. This will allow us to verify thexray_data
is included in theprompt_options
that are passed to the aigw - Run
gdk
and in terminalgdk tail rails
to view rails related logs - Go to the graphql explorer: http://gdk.test:3000/-/graphql-explorer
- Run a mutation to trigger
/refactor
,/fix
, or/tests
and be sure to pass in the correct id for the project where you created an xray reportmutation { aiAction( input: { chat: { content: "/refactor", currentFile: { selectedText: "\n@sold_items = %w( onions garlic potatoes ) \ndef print_report\nputs '*** Sales Report for #{Time.new.strftime('%d/%m/%Y')} ***'\n@sold_items.each { |i| puts i }\nputs '*** End of Sales Report ***'\nend", fileName: "hello.rb" }, resourceId: "gid://gitlab/Project/25" }, } ) { clientMutationId errors } }
- Look in terminal for the
prompt_options
that were puts'ed and verify the xray libraries are included for each slash command! - To ensure the logic verifying the xray libraries are included in the prompt only when the language matches the file being edited, change your mutation file extension to be different from the xray report language and repeat the above steps to ensure libraries aren't included in the
prompt_options
.