potiuk commented on code in PR #77119:
URL: https://github.com/apache/airflow/pull/77119#discussion_r4580878438


##########
dev/breeze/src/airflow_breeze/utils/selective_checks.py:
##########
@@ -2726,6 +2733,27 @@ def _is_self_hosted_label_approved(self) -> bool:
     def has_migrations(self) -> bool:
         return any([file.startswith("airflow-core/src/airflow/migrations/") 
for file in self._files])
 
+    @cached_property
+    def has_added_or_renamed_files(self) -> bool:
+        if self._commit_ref is None:
+            return True
+        from airflow_breeze.utils.run_utils import run_command
+

Review Comment:
   **Keep selective-checks behaviour and its documentation in sync.**
   
   > Keep selective-checks behaviour and its documentation in sync. The CI 
optimisation logic lives in 
`dev/breeze/src/airflow_breeze/utils/selective_checks.py` (run-mode decisions, 
file-group matching, test-type selection, prek-hook skipping).
   
   `has_added_or_renamed_files` always diffs `commit_ref^..commit_ref`, but 
`selective-check` does not always derive the changed files that way. On a fork 
push (the AIP-120 fork-CI path this PR itself runs on) the files come from 
`get_fork_changes(...)` against the merge base, and on a selective push from 
`get_changed_files_since(push_base_commit, commit_ref)`. Both can span many 
commits. A contributor who adds a file in commit 1 and pushes a fix in commit 2 
gets `has-added-or-renamed-files=false`, so `Test git clone on Windows` is 
skipped even though the PR adds a path. Derive the flag from the same base that 
produced `files` (the fork merge base or the push base, with `git diff 
--name-only --diff-filter=A --no-renames <base> <commit_ref>`), or return 
`True` whenever the files did not come from `get_changed_files`.
   
   *Flagged by both the primary and adversarial reviewers.*



##########
dev/breeze/src/airflow_breeze/utils/selective_checks.py:
##########
@@ -1739,7 +1740,9 @@ def _only_new_ui_files() -> bool:
 
     @cached_property
     def run_system_tests(self) -> bool:
-        return self.run_unit_tests
+        if self.full_tests_needed:
+            return True
+        return self._should_be_run(FileGroupForCi.SYSTEM_TEST_FILES)

Review Comment:
   **Keep selective-checks behaviour and its documentation in sync.**
   
   > Keep selective-checks behaviour and its documentation in sync. The CI 
optimisation logic lives in 
`dev/breeze/src/airflow_breeze/utils/selective_checks.py` (run-mode decisions, 
file-group matching, test-type selection, prek-hook skipping).
   
   `run-system-tests` gates only the `System Tests` job in 
`integration-system-tests.yml`, and that job runs one smoke test: 
`./scripts/ci/testing/run_system_tests.sh 
airflow-core/tests/system/example_empty.py`. It checks that the system-test 
harness and core Dag execution still work end to end. It does not run whichever 
system test changed. With this change, the job stops running for the changes it 
guards: core or Task SDK sources (the PR's own 
`unit-test-only-skips-system-tests` case with `models/dag.py` expects `False`), 
`run_system_tests.sh`, and the `--system` handling in `pytest_plugin.py`, which 
this PR also changes. Meanwhile a change to `providers/*/tests/system/` now 
triggers a job that never runs that provider's test. If the goal is to save 
runner time, gate on the harness and core files instead (or keep 
`run_unit_tests`). As written, the trigger set is close to the opposite of what 
the job checks.



##########
dev/breeze/src/airflow_breeze/utils/selective_checks.py:
##########
@@ -1739,7 +1740,9 @@ def _only_new_ui_files() -> bool:
 
     @cached_property
     def run_system_tests(self) -> bool:

Review Comment:
   **Any other new `run_*` output must be scoped, so that it does not run 
there.**
   
   > The outputs that stay as computed on the branch of a single component: 
they are general checks rather than another component's tests. Any other new 
`run_*` output must be scoped, so that it does not run there.
   
   `run_system_tests` is in `GENERAL_CHECKS` only because it used to follow the 
scoped `run_unit_tests` (`# follows run_unit_tests`). Now that it no longer 
does, it is unscoped: a push to `chart/v1-2x-test` (full tests) turns on the 
Airflow `System Tests` job on the chart branch. Add 
`@_scoped_to_component_branch` and remove it from `GENERAL_CHECKS`, or keep it 
following `run_unit_tests`.



##########
devel-common/src/tests_common/pytest_plugin.py:
##########
@@ -899,14 +899,22 @@ def pytest_collection_modifyitems(config, items):
     to OOM on Python 3.14 CI runners. Deselecting during collection avoids 
distributing
     these items to workers entirely.
     """
-    if not skip_db_tests and not run_db_tests_only:
-        return
+    include_quarantined = getattr(config.option, "include_quarantined", False)
+    include_long_running = getattr(config.option, "include_long_running", 
False)
+    system = getattr(config.option, "system", False)
 
     selected = []
     deselected = []
     for item in items:
         is_db = _is_db_test(item)
-        if (skip_db_tests and is_db) or (run_db_tests_only and not is_db):
+        should_deselect = (
+            (skip_db_tests and is_db)
+            or (run_db_tests_only and not is_db)
+            or (not include_quarantined and 
item.get_closest_marker("quarantined"))

Review Comment:
   **Comment only when context is not readily apparent from the code.**
   
   > Keep necessary explanations short, precise and at the source of truth.
   
   Deselecting instead of skipping changes what a developer sees. Before, 
`pytest path/to/quarantined_test.py` printed a skip reason telling them to pass 
`--include-quarantined` (or `--include-long-running` / `--system`). Now 
everything is deselected and pytest exits with code 5 ("no tests ran") with no 
hint. Breeze accepts exit code 5 only under `--run-db-tests-only` 
(`testing_commands.py`), so a test type left empty by these markers would now 
fail. Consider deselecting these markers only when the runs are distributed 
(xdist), or adding a collection-time message. Also update the docstring, which 
still describes only the DB/non-DB split, and drop the `skip_quarantined_test` 
/ `skip_long_running_test` / `skip_system_test` runtime paths, which can no 
longer fire.



##########
devel-common/tests/unit/tests_common/test_pytest_plugin.py:
##########
@@ -461,3 +461,108 @@ def initial_db_init():
             f"Unable to re-initialize the SQLite test DB. Remove 
`{sqlite_db_file}` and rerun pytest."
         )
         assert isinstance(exc_info.value.__cause__, SQLAlchemyError)
+
+
+class TestCollectionModifyItems:

Review Comment:
   **Use `@pytest`.mark.parametrize for multiple similar inputs**
   
   > Use `@pytest.mark.parametrize` for multiple similar inputs — consolidate 
tests that only differ in input/expected values into a single parametrized test.
   
   The two tests duplicate all four dummy classes and differ only in the flag 
values and the expected survivors. Move the dummies to module level (or a 
fixture) and use one test parametrized over (flags, expected names). A case per 
marker would also show that each flag works on its own.



##########
dev/breeze/src/airflow_breeze/utils/selective_checks.py:
##########
@@ -2726,6 +2733,27 @@ def _is_self_hosted_label_approved(self) -> bool:
     def has_migrations(self) -> bool:
         return any([file.startswith("airflow-core/src/airflow/migrations/") 
for file in self._files])
 
+    @cached_property
+    def has_added_or_renamed_files(self) -> bool:
+        if self._commit_ref is None:
+            return True
+        from airflow_breeze.utils.run_utils import run_command

Review Comment:
   **Imports at top of file.**
   
   > Imports at top of file. Valid exceptions: circular imports, lazy loading 
for worker isolation, `TYPE_CHECKING` blocks.
   
   `run_command` is already imported at the top of `selective_checks.py`, so 
drop this local import. The tail can also be simplified to `return 
result.returncode != 0 or bool(result.stdout.strip())`.



##########
dev/breeze/src/airflow_breeze/utils/selective_checks.py:
##########
@@ -1776,6 +1779,10 @@ def ci_image_build(self) -> bool:
     @_scoped_to_component_branch
     def run_generic_basic_tests(self) -> bool:
         """The standalone Airflow test, which runs for every change."""

Review Comment:
   **Comment only when context is not readily apparent from the code.**
   
   > Do not narrate code, repeat code, or invent a rationale in comments. Keep 
necessary explanations short, precise and at the source of truth.
   
   The docstring still says "runs for every change". Also, `run_unit_tests` 
already returns True when `full_tests_needed`, so the body reduces to `return 
self.run_unit_tests and not self.only_text_non_doc_files_changed`.



##########
dev/breeze/tests/test_selective_checks.py:
##########
@@ -6426,3 +6426,83 @@ def 
test_provider_compatibility_tests_skip_only_changes_hidden_from_them(
     )
     assert checks.skip_providers_tests is False
     assert checks.run_providers_compatibility_tests is expected
+
+
[email protected](
+    ("files", "pr_labels", "expected"),
+    [
+        pytest.param(
+            ("airflow-core/src/airflow/models/dag.py",),
+            (),
+            False,
+            id="unit-test-only-skips-system-tests",
+        ),
+        pytest.param(
+            ("airflow-core/tests/system/example_dag.py",),
+            (),
+            True,
+            id="core-system-test-runs-system-tests",
+        ),
+        pytest.param(
+            ("providers/standard/tests/system/example_standard.py",),
+            (),
+            True,
+            id="provider-system-test-runs-system-tests",
+        ),
+        pytest.param(
+            ("airflow-core/src/airflow/models/dag.py",),
+            ("full tests needed",),
+            True,
+            id="full-tests-runs-system-tests",
+        ),
+    ],
+)
+def test_run_system_tests_gating(files: tuple[str, ...], pr_labels: tuple[str, 
...], expected: bool):
+    checks = SelectiveChecks(
+        files=files,
+        commit_ref=NEUTRAL_COMMIT,
+        github_event=GithubEvents.PULL_REQUEST,
+        pr_labels=pr_labels,
+        default_branch="main",
+    )
+    assert checks.run_system_tests is expected
+
+
[email protected](
+    ("files", "expected"),
+    [
+        pytest.param(
+            ("README.md",),
+            False,
+            id="markdown-only-skips-generic-basic-tests",
+        ),
+        pytest.param(
+            ("docs/apache-airflow/index.rst",),
+            False,
+            id="docs-only-skips-generic-basic-tests",
+        ),
+        pytest.param(
+            ("airflow-core/src/airflow/models/dag.py",),
+            True,
+            id="core-code-runs-generic-basic-tests",
+        ),
+    ],
+)
+def test_run_generic_basic_tests_gating(files: tuple[str, ...], expected: 
bool):
+    checks = SelectiveChecks(
+        files=files,
+        commit_ref=NEUTRAL_COMMIT,
+        github_event=GithubEvents.PULL_REQUEST,
+        default_branch="main",
+    )
+    assert checks.run_generic_basic_tests is expected
+
+
+def test_has_added_or_renamed_files_neutral_commit():

Review Comment:
   **Every changed or added behaviour must have a test**
   
   > Target exactly 100% coverage of what the PR changes — no more, no less. 
Every changed or added behaviour must have a test; every test must fail without 
the PR's change.
   
   Only the `commit_ref is None` early return is tested. Add parametrized cases 
that mock `run_command` (with `autospec`) for: an added file (True), modified 
files only (False), and a non-zero git exit (True).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to