Prompt Eval: Improve test reliability Apply test reruns for the flaky tests. They both pass ~30% of the time so 1 in 5 passes should be a reasonable starting point. Remove the excessive attempts on host_arch to improve eval runtime. This test should never fail. The assert for host_platform is also failing occasionally due to case sensitivity. The build_target test appears to have changed as well. Update it for now but this will probably require adding a patch or finding a more stable file/target Hopefully after this lands we'll start seeing some green builds again Bug: 443097039 Change-Id: I695bf0f89b3fab2b380d7aafd8efe18f34fc7ce5 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7081776 Reviewed-by: Brian Sheedy <[email protected]> Commit-Queue: Struan Shrimpton <[email protected]> Cr-Commit-Position: refs/heads/main@{#1535214} GitOrigin-RevId: ba116c0df8c116243b20bd177ee85b59925ec999
This directory contains the framework for running prompt evaluation tests on the choromium code base using extensions and prompts under //agents.
Googlers please see also go/chromium-prompt-evaluations.
Existing tests can be run via the //agents/testing/eval_prompts.py script. It should handle everything automatically, although it is advised to commit any changes before running this script. It will automatically retrieve a temporary copy of promptfoo, perform repo setup, run configured tests, and perform teardown.
By default, it will build promptfoo from ToT, but specific behavior can be configured via command line arguments, including use of stable releases via npm which will likely result in faster setup.
If you are running eval_prompts.py on a system without a container runtime like Docker or Podman, you will need to pass the --no-sandbox flag. This is because the script uses sandboxing by default to isolate the test environment.
The prompt eval is intended to be run with Chromium in a btrfs file system. The tests should still run in a normal checkout but will be significantly slower and take up significantly more disk space. These steps can be used to fetch a new Chromium solution in a virtual btrfs file system mounted in your home dir.
The following commands can be used to set up the environment:
# Ensure btrfs is installed sudo apt install btrfs-progs # Create the virtual image file truncate -s 500G ~/btrfs_virtual_disk.img # Format the image with btrfs mkfs.btrfs ~/btrfs_virtual_disk.img # Mount the image mkdir ~/btrfs sudo mount -o loop ~/btrfs_virtual_disk.img ~/btrfs # Update owner sudo chown $(whoami):$(id -ng) ~/btrfs # Create a btrfs subvolume for the checkout btrfs subvolume create ~/btrfs/chromium # Fetch a new Chromium checkout into the subvolume. # This will place the 'src' directory inside '~/btrfs/chromium/'. cd ~/btrfs/chromium fetch chromium # For an existing checkout, you would instead move the contents, e.g.: # mv ~/your_old_chromium/* ~/btrfs/chromium/ # (Optional) To make the mount permanent, add it to /etc/fstab. # It's wise to back up this critical file first. cp /etc/fstab ~/fstab.bak echo "$HOME/btrfs_virtual_disk.img $HOME/btrfs btrfs loop,defaults 0 0" | sudo tee -a /etc/fstab
After Chromium is checked out, agents/testing/eval_prompts.py can then be run from ~/btrfs/chromium/src/.
This checkout should function just like your original so you don't need to maintain both if you prefer.
Each independent test case should have its own promptfoo yaml config file. See the promptfoo documentation for more information on this. If multiple prompts are expected to result in the same behavior, and thus can be tested in the same way, the config file can contain multiple prompts. promptfoo will automatically test each prompt individually.
Config files should be placed in a subdirectory of the relevant prompt or extension directory. The tests will be discovered by the test runner and ran based on any filter or sharding args passed to the runner.
The gemini_provider.py supports several custom options for advanced testing scenarios, such as applying file changes or loading specific templates. Below is an example of a promptfoo.yaml file that demonstrates how to use the changes option to patch and stage files before a test prompt is run.
This example can be used as a template for writing tests that require a specific file state.
test_with_custom_options.promptfoo.yamlprompts: - "What is the staged content of the file `path/to/dummy.txt`?" providers: - id: "python:../../../testing/gemini_provider.py" config: extensions: - depot_tools changes: - apply: "path/to/add_dummy_content.patch" - stage: "path/to/dummy.txt" tests: - description: "Test with custom options" assert: # Check that the agent ran git diff and found the new content. - type: icontains value: "dummy content"
The changes field points to standard .patch files. The test runner will apply them.
add_dummy_content.patchdiff --git a/path/to/dummy.txt b/path/to/dummy.txt index e69de29..27332d3 100644 --- a/path/to/dummy.txt +++ b/path/to/dummy.txt @@ -0,0 +1 @@ +dummy content