Skip to content

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)

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

Graphql mutation to trigger /refactor:

Screenshot_2024-11-26_at_10.04.05_AM

Change content: "/fix" and content: "/tests" to verify the other slash commands.

Rails logs with xray_data in prompt_options on the monolith side

/refactor

Screenshot_2024-12-05_at_10.16.55_AM

/fix

Screenshot_2024-12-05_at_9.58.11_AM

/tests

Screenshot_2024-12-05_at_10.13.03_AM

AIGW logs with xray_data in the prompt_request

/refactor

refactoraigw

/fix

fixaigw

/tests

testsaigw

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

  1. 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)
  2. 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 the xray_data is included in the prompt_options that are passed to the aigw
  3. Run gdk and in terminal gdk tail rails to view rails related logs
  4. Go to the graphql explorer: http://gdk.test:3000/-/graphql-explorer
  5. 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 report
    mutation {
      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
      }
    }
  6. Look in terminal for the prompt_options that were puts'ed and verify the xray libraries are included for each slash command!
  7. 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.
Edited by Missy Davies

Merge request reports

Loading