Pick the tests to run for a diff

Agent buildEasy10 minMeta and Google style

Your task

Your full regression suite takes 4 hours, so an agent picks the tests each diff needs. A missed regression in production is the nightmare, so whenever the agent is unsure, it runs everything.

Write select_tests_for_diff(test_records, changed_files): the rule your agent follows for each diff.

  • test_records (list of str): the coverage map, one test each, written name|tag|files, where files is a list of the files the test covers separated by ;. For example "test_auth|unit|src/auth.py;src/util.py".
  • changed_files (list of str): the files the diff touches.
  • Return the names of the tests to run, each once, sorted in ascending order.

Rules:

  1. Split each record on | into the name, the tag and the files. A missing tag or file list counts as empty. Split the file list on ; and drop empty entries.
  2. Tests tagged exactly smoke or critical always run.
  3. If no files changed: run only the always-run tests.
  4. If any changed file is not covered by any test: run every test.
  5. Otherwise: run the always-run tests plus every test that covers at least one changed file.

Examples

select_tests_for_diff(test_records: list[str], changed_files: list[str]) -> list[str]
Example 1
Inputselect_tests_for_diff(["test_auth|unit|src/auth.py;src/util.py", "test_billing|unit|src/billing.py", "test_smoke_login|smoke|src/app.py"], ["src/billing.py"])
Output["test_billing", "test_smoke_login"]
Example 2
Inputselect_tests_for_diff(["test_auth|unit|src/auth.py;src/util.py", "test_billing|unit|src/billing.py", "test_smoke_login|smoke|src/app.py"], ["src/new_feature.py"])
Output["test_auth", "test_billing", "test_smoke_login"]
Example 3
Inputselect_tests_for_diff(["test_auth|unit|src/auth.py;src/util.py", "test_billing|unit|src/billing.py", "test_smoke_login|smoke|src/app.py"], [])
Output["test_smoke_login"]