You are an AI assistant with 10 years of experience writing Chromium unit tests and browser tests. Your task is to start refactoring the C++ test file ${file} from a unit test to an In-Process Browser Test by renaming the file and updating the corresponding BUILD.gn file.
[ ] 1. Review user input [ ] 2. Find the right `BUILD.gn` file [ ] 3. Consider updating the `BUILD.gn` file [ ] 4. Wait for the user to confirm they have updated the `BUILD.gn` file [ ] 5. Rename Test File [ ] 6. Tell the user to format, stage and commit the changes [ ] 7. Tell the user to proceed to refactoring part 2
Review the following information before messaging the user so you can help them effectively.
You are responsible for determining the following variables:
${out_dir}: The build directory (e.g., out/debug_x64).
The user may launch this prompt with syntax such as out/debug_x64, if they do you should parse the input into the above variables.
The user may have specified ## Developer Prompt Variables. If they have, you should that as the ${out_dir} unless the user respecified it above.
${out_dir} . You can let them know that they can add the following code block to their copilot-instructions.md file to set the default ${out_dir}.## Developer Prompt Variables `${out_dir}` = `debug_x64`
BUILD.gn fileYou will need to find the file that references the test file you are refactoring. You can find this with the following command: gn refs out/{out_dir} ${file}
//chrome/browser/foo:bar, the file will be chrome/browser/foo/BUILD.gn and inside of the ${target} bar. You do not need to search for the BUILD.gn file, you can open it directly since chrome is accessible relative to this file at `../../chrome/.You must use git mv to rename the test file ${file}.
_unittest.cc suffix with _browsertest.cc.${file} is foo_unittest.cc, the command would be git mv foo_unittest.cc foo_browsertest.cc.BUILD.gn fileCheck the file length of the BUILD.gn file you found in the previous step.
(Get-Content ${file}).CountYou should attempt to follow the instructions below to update the BUILD.gn file yourself.
If the file is over 4000 lines, tell the user the file is too long for your context window. Tell the user they need to manually update the BUILD.gn file since its too long for your context window.
BUILD.gn fileWhen refactoring a unit test to a browser test in Chromium, you will need to update the BUILD.gn file. This is a critical step because the build system needs to know that your test file has moved from the unit tests target to the browser tests target.
You will need to explain your chain of thought and follow these step by step:
[ ] 1. Find your original test file in the unit_tests section [ ] 2. Remove the entry from unit_tests [ ] 3. Add to browser_tests [ ] 4. Review modified lines
${target} section${target}, this will likely be a test("unit_tests") or source_set("...unit_tests") section"../browser/path/to/your_unittest.cc"chrome/browser/ui/views/my_feature_unittest.cc, you'd look for "../browser/ui/views/my_feature_unittest.cc" in the sources listsources = [ ... ] list in the ${target} sectionsources = [ ... ] block, just the line with your original test file../browser/ui/views/my_feature_unittest_2.cc,# Before # sources = [ # ..., # "../browser/ui/views/my_feature_unittest_1.cc", # "../browser/ui/views/my_feature_unittest_2.cc", # "../browser/ui/views/my_feature_unittest_3.cc", # ..., # ] # After sources = [ ..., "../browser/ui/views/my_feature_unittest_1.cc", "../browser/ui/views/my_feature_unittest_3.cc", ..., ]
browser_tests section in the same BUILD.gn filetest("browser_tests") or source_set("...browser_tests") sectionbrowser_tests section, you may need to create one and hook it up to chrome/test/BUILD.gn.if statement blocks that might be surrounding your test fileif (is_win) or if (enable_extensions), make sure to add your new browsertest file in the corresponding conditional block in the browser_tests sectionsources = [ ... ] list"../browser/ui/views/my_feature_unittest.cc", you'd add "../browser/ui/views/my_feature_browsertest.cc"BUILD.gn file to ensure they are correctBefore moving on you must wait for the user to confirm that the BUILD.gn file has been code reviewed by the user and updated correctly.
After BUILD.gn file has been updated you must run the following commands in the following step by step order:
[ ] 1. `git cl format ${file} [build.gn file]` [ ] 2. `git add ${file} [build.gn file]` [ ] 3. `git commit -m "[Bedrock]: Refactor ${file} _unittest to _browsertest"` [ ] 4. `git cl upload`
Tell the user they must run git cl upload before continuing to part 2 to upload the changes the code review system before continuing the refactor so that code reviewers can clearly disambiguate the changes made in this part of the refactor compared to the base test. There is a bug in gerrit that causes large diffs of moved files to not show up correctly, so we want to upload the changes in two parts to work around this known issue.
After completing the above steps, provide the user with a clickable link to their new file and tell the user to start a new chat and run /refactor_bedrock_part_2 with the new file path.