fix(ci): Execute newly added or modified scheduled_only tests in pre-submits#4339
Open
mesakhcienet wants to merge 1 commit into
Open
fix(ci): Execute newly added or modified scheduled_only tests in pre-submits#4339mesakhcienet wants to merge 1 commit into
scheduled_only tests in pre-submits#4339mesakhcienet wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
81f5793 to
9e07cb9
Compare
xibinliu
reviewed
Jul 2, 2026
| @@ -0,0 +1,192 @@ | |||
| # Copyright 2025 Google LLC | |||
| @@ -0,0 +1,167 @@ | |||
| # Copyright 2025 Google LLC | |||
| return found | ||
|
|
||
|
|
||
| def get_changed_tests(base_ref=None): |
Collaborator
There was a problem hiding this comment.
Do we want to detect both newly added tests and the modified tests, or just new tests? @shralex
Collaborator
There was a problem hiding this comment.
detecting modified tests sounds great
shralex
reviewed
Jul 3, 2026
| changed_tests = get_changed_tests() # set[(file_path, test_name)] | ||
| if changed_tests: | ||
| for item in items: | ||
| item_file = item.nodeid.split("::", 1)[0] |
Collaborator
There was a problem hiding this comment.
item_file = os.path.abspath(item.nodeid.split("::", 1)[0])
| "external_training: goodput integrations", | ||
| "decoupled: marked on tests that are not skipped due to GCP deps, when DECOUPLE_GCLOUD=TRUE", | ||
| "skip_on_tpu7x: skip test if running on TPU7x platform", | ||
| "newly_added: newly introduced tests in PRs, executed even if scheduled_only", |
| stderr=subprocess.DEVNULL, | ||
| check=False, | ||
| ) | ||
| try: |
Collaborator
There was a problem hiding this comment.
gemini proposes the following (more fallback strategies):
# Diff strategies to try in order of preference.
# Remote specs are tried first (for CI), falling back to local specs (for local development).
diff_strategies = [
["origin/{base}...HEAD"],
["origin/{base}", "HEAD"],
["{base}...HEAD"],
["{base}", "HEAD"],
]
diff_text = None
for strategy in diff_strategies:
try:
diff_text = subprocess.check_output(
["git", "diff", "--unified=0"] + [arg.format(base=base) for arg in strategy],
text=True,
stderr=subprocess.DEVNULL,
)
break
except Exception: # pylint: disable=broad-exception-caught
continue
if diff_text is None:
return set()
| for path, touched_lines in parse_changed_line_map(diff_text).items(): | ||
| if not _is_test_file(path): | ||
| continue | ||
| try: |
Collaborator
There was a problem hiding this comment.
Lets convert to absolute path here and return that instead of path
# Resolve the absolute path to open the file and return in the set
full_path = os.path.abspath(os.path.join(repo_root, path))
| except OSError: | ||
| continue | ||
| for name in touched_test_names(source, touched_lines): | ||
| changed.add((path, name)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This change makes the pre-submit execute the
scheduled_onlytests that a PR introduces or modifies, so each is verified at least once before merge, while unrelatedscheduled_onlytests remain nightly-only (unchanged).How it works
tests/conftest.pycomputes the set of tests a PR adds or modifies — viagit diff --unified=0 origin/<base>...HEAD— and dynamically applies a newnewly_addedmarker to the matching collected tests.<marker> and not scheduled_onlyto<marker> and (not scheduled_only or newly_added). Scheduled (nightly) runs are untouched and continue to run everything.Detection details / robustness
tests/utils/newly_added_detection.py(parse_changed_testsis pure;get_changed_testswraps git). Keeping it out ofconftest.pylets it be tested without importing absl/pytest/jax.(file_path, test_name)— so identically named tests in different files (e.g.test_basic_callappears in 6 files) do not cross-contaminate and pull unrelatedscheduled_onlytests into pre-submit..gitattributessets*.py diff=pythonsogit diffhunk headers expose the enclosingdef test_*for edits inside class methods (the suite is overwhelmingly class-based). This enables detection of modified tests, not just brand-new ones.fetch-depth: 0so the three-dotorigin/main...HEADdiff has a reachable merge-base (otherwise the shallow clone forces a less precise fallback).GITHUB_BASE_REF(thenmain), so PRs targeting a non-mainbranch are handled.Files changed
tests/conftest.pynewly_added(file-qualified match)tests/utils/newly_added_detection.py(new)tests/unit/newly_added_detection_test.py(new).github/workflows/run_tests_against_package.ymlfetch-depth: 0.github/workflows/run_pathways_tests.yml.gitattributes(new)*.py diff=pythonpytest.ininewly_addedmarkerShortcomings / future work
maxtext_installed=true(the runner doescd /deps, which is not a git work tree). Not on the current PR pre-submit path, but worth noting.run_pathways_tests.ymlchecks out via a hardcodedgit clone https://github.com/google/maxtext.git, which does not resolve fork build SHAs (pre-existing, out of scope here).Tests
New unit tests in
tests/unit/newly_added_detection_test.py(markedcpu_only) cover the diff parser across: new top-level function, new class method, modified method detected via the hunk header, cross-file name-collision isolation, non-test /src/changes ignored, and multi-file diffs.All commands run locally against the repo
.venv(Python 3.12).1. Unit tests
2. Lint gate (same hooks as
code_quality.yml)3. End-to-end through the real
conftest.py— a temporaryscheduled_onlyprobe test committed on the branch, collected through the actualtests/conftest.py:This confirms the full chain:
git diff→ file-qualified parse →newly_addedmarker → survives-mselection → thescheduled_onlytest runs. The.gitattributeschange was separately verified to makegit diff --unified=0emit@@ ... @@ def test_column(...)headers for edits inside class methods (instead of the enclosingclass ...line).4. CI: the two modified workflows exercise this change on the actual TPU / GPU / CPU and Pathways pre-submit runners in this PR.
Checklist
Before submitting this PR, please make sure (put X in square brackets):
gemini-reviewlabel.