Skip to content

Commit d5874b0

Browse files
committed
Re-add ALWAYS_RUN_TESTS to selective test computing
1 parent d6a8f84 commit d5874b0

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

.github/workflows/scripts/compute-sentry-selected-tests.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@
8686
re.compile(r"^tests/(acceptance|apidocs|js|tools)/"),
8787
]
8888

89+
# Tests that should always be run even if not explicitly selected.
90+
ALWAYS_RUN_TESTS: set[str] = {
91+
"tests/sentry/taskworker/test_config.py",
92+
}
93+
8994

9095
def _is_test(path: str) -> bool:
9196
return any(path.startswith(d) for d in TEST_DIRS)
@@ -225,6 +230,9 @@ def main() -> int:
225230
print(f"Including {len(existing_changed)} directly changed test files")
226231
affected_test_files.update(existing_changed)
227232

233+
# Always run these tests
234+
affected_test_files.update(ALWAYS_RUN_TESTS)
235+
228236
# Filter to sentry tests only (drop any getsentry tests from coverage)
229237
affected_test_files = {f for f in affected_test_files if _is_test(f)}
230238

.github/workflows/scripts/test_compute_sentry_selected_tests.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
sys.modules["compute_sentry_selected_tests"] = _mod
2020
_spec.loader.exec_module(_mod)
2121

22-
from compute_sentry_selected_tests import _query_coverage, main
22+
from compute_sentry_selected_tests import ALWAYS_RUN_TESTS, _query_coverage, main
2323

2424

2525
def _create_coverage_db(path: str, file_to_contexts: dict[str, list[str]]) -> None:
@@ -178,8 +178,9 @@ def test_selective_returns_matched_tests(self, tmp_path):
178178

179179
gh = gh_output.read_text()
180180
assert "has-selected-tests=true" in gh
181-
assert "test-count=1" in gh
182-
assert output.read_text().strip() == "tests/sentry/test_org.py"
181+
assert f"test-count={1 + len(ALWAYS_RUN_TESTS)}" in gh
182+
expected_output = sorted({"tests/sentry/test_org.py"} | ALWAYS_RUN_TESTS)
183+
assert output.read_text().splitlines() == expected_output
183184

184185
def test_getsentry_tests_filtered_out(self, tmp_path):
185186
"""Coverage may return getsentry tests — they should be filtered."""
@@ -211,8 +212,9 @@ def test_getsentry_tests_filtered_out(self, tmp_path):
211212
{"GITHUB_OUTPUT": str(gh_output)},
212213
)
213214

214-
assert "test-count=1" in gh_output.read_text()
215-
assert output.read_text().strip() == "tests/sentry/test_org.py"
215+
assert f"test-count={1 + len(ALWAYS_RUN_TESTS)}" in gh_output.read_text()
216+
expected_output = sorted({"tests/sentry/test_org.py"} | ALWAYS_RUN_TESTS)
217+
assert output.read_text().splitlines() == expected_output
216218

217219
def test_changed_test_file_included(self, tmp_path):
218220
db_path = tmp_path / "coverage.db"
@@ -236,7 +238,7 @@ def test_changed_test_file_included(self, tmp_path):
236238

237239
gh = gh_output.read_text()
238240
assert "has-selected-tests=true" in gh
239-
assert "test-count=1" in gh
241+
assert f"test-count={1 + len(ALWAYS_RUN_TESTS)}" in gh
240242

241243
def test_excluded_test_dirs_skipped(self, tmp_path):
242244
"""Tests in acceptance/apidocs/js/tools should not be selected."""
@@ -257,10 +259,10 @@ def test_excluded_test_dirs_skipped(self, tmp_path):
257259
{"GITHUB_OUTPUT": str(gh_output)},
258260
)
259261

260-
assert "test-count=0" in gh_output.read_text()
262+
assert f"test-count={len(ALWAYS_RUN_TESTS)}" in gh_output.read_text()
261263

262-
def test_zero_tests_signals_selective_applied(self, tmp_path):
263-
"""0 tests after filtering should signal 'run nothing', not full suite."""
264+
def test_zero_coverage_matches_still_runs_always_run_tests(self, tmp_path):
265+
"""No coverage matches should still run ALWAYS_RUN_TESTS, not the full suite."""
264266
db_path = tmp_path / "coverage.db"
265267
_create_coverage_db(str(db_path), {})
266268
output = tmp_path / "output.txt"
@@ -282,8 +284,8 @@ def test_zero_tests_signals_selective_applied(self, tmp_path):
282284

283285
gh = gh_output.read_text()
284286
assert "has-selected-tests=true" in gh
285-
assert "test-count=0" in gh
286-
assert output.read_text() == ""
287+
assert f"test-count={len(ALWAYS_RUN_TESTS)}" in gh
288+
assert set(output.read_text().splitlines()) == ALWAYS_RUN_TESTS
287289

288290
def test_renamed_file_queries_old_path(self, tmp_path):
289291
"""When a file is renamed, the old path should be queried against the coverage DB."""
@@ -319,8 +321,9 @@ def test_renamed_file_queries_old_path(self, tmp_path):
319321

320322
gh = gh_output.read_text()
321323
assert "has-selected-tests=true" in gh
322-
assert "test-count=1" in gh
323-
assert output.read_text().strip() == "tests/sentry/test_old_name.py"
324+
assert f"test-count={1 + len(ALWAYS_RUN_TESTS)}" in gh
325+
expected_output = sorted({"tests/sentry/test_old_name.py"} | ALWAYS_RUN_TESTS)
326+
assert output.read_text().splitlines() == expected_output
324327

325328
def test_renamed_file_without_previous_misses_coverage(self, tmp_path):
326329
"""Without --previous-filenames, a renamed file gets no coverage hits."""
@@ -349,7 +352,7 @@ def test_renamed_file_without_previous_misses_coverage(self, tmp_path):
349352

350353
gh = gh_output.read_text()
351354
assert "has-selected-tests=true" in gh
352-
assert "test-count=0" in gh
355+
assert f"test-count={len(ALWAYS_RUN_TESTS)}" in gh
353356

354357
def test_missing_db_returns_error(self):
355358
ret = _run(["--coverage-db", "/nonexistent/coverage.db", "--changed-files", "foo.py"])

0 commit comments

Comments
 (0)