spark-test commented on code in PR #60615:
URL: https://github.com/apache/spark/pull/60615#discussion_r4608255294


##########
dev/sparktestsupport/tests/test_utils.py:
##########
@@ -39,16 +43,45 @@ def test_github_files_only_count_in_github_actions(self):
 
 
 class IdentifyChangedFilesFromGitHistoryTests(unittest.TestCase):
+    _GIT_IDENTITY = (
+        "-c",
+        "[email protected]",
+        "-c",
+        "user.name=Spark Test",
+        "-c",
+        "commit.gpgsign=false",
+    )
+
     def changed_modules(self, patch_sha, target_ref):
         changed_files = identify_changed_files_from_git_commits(patch_sha, 
target_ref=target_ref)
         return determine_modules_for_files(changed_files)
 
+    def changed_files_for_rename(self, old_path, new_path):
+        with tempfile.TemporaryDirectory() as tmp, chdir(tmp):
+
+            def git(*args):
+                return subprocess.check_output(["git", *args], text=True)

Review Comment:
   **Non-blocking (P2):** This runner, and the `git diff` that the helper call 
on line 73 runs, inherit the caller's full environment and global and system 
git configuration, so the temporary repository is isolated only by `chdir(tmp)`.
   
   An inherited `GIT_DIR` or `GIT_INDEX_FILE` overrides the working directory, 
and git exports one or both to hooks and, in a linked worktree, to `git rebase 
--exec` commands. In scratch repositories set up that way, the fixture 
committed `add` and `rename` onto the calling repository's branch, stopped a 
rebase with `cannot rebase: You have unstaged changes.`, or staged `old.txt` 
into the calling repository's commit in progress so that its `git commit` 
failed. A global or system hook that refuses commits on main made the test 
error, which also aborts a local `dev/run-tests.py` run because `_test()` runs 
this suite first. With `diff.renames=false` in the global or system 
configuration, the test passed against the helper without `--no-renames`. CI 
runs the suite with default git configuration, so CI still catches a regression 
of the fix.
   
   Running the whole fixture, including the helper call, under 
`mock.patch.dict(os.environ, env, clear=True)`, where `env` is `os.environ` 
without its `GIT_*` entries plus `GIT_CONFIG_GLOBAL=os.devnull` and 
`GIT_CONFIG_NOSYSTEM="1"`, fixed every one of these cases in the same repros, 
and the test still failed against the helper without `--no-renames`.
   
   **Verification:**
   - **Regression:** Run the rename test with `GIT_DIR` pointing at a separate 
scratch repository, and again with `GIT_INDEX_FILE` pointing at its index, and 
confirm it passes and that repository's history, index and status are 
unchanged; run it through `git rebase --exec` from a linked worktree and 
confirm the rebase completes with no extra commits; and run it from a 
pre-commit hook during `git commit -a` in a scratch repository's main worktree 
and in a linked worktree, and confirm each commit succeeds and contains only 
that repository's own change.
   - **Regression:** Under a global git configuration whose hooks path holds a 
pre-commit hook that refuses commits on main, and separately under a system 
configuration that does the same (for example one named by 
`GIT_CONFIG_SYSTEM`), run the rename test and confirm it passes both times.
   - **Regression:** Under `diff.renames=false` in the global configuration, 
and separately in the system one, confirm the rename test fails against the 
helper without `--no-renames` and passes with it.
   - **Behavior:** Confirm that the process environment, including `GIT_` 
variables set before the test, and the working directory are exactly restored 
after the rename test runs.



##########
dev/sparktestsupport/utils.py:
##########
@@ -73,7 +76,8 @@ def identify_changed_files_from_git_commits(patch_sha, 
target_branch=None, targe
     else:
         diff_target = target_ref
     raw_output = subprocess.check_output(
-        ["git", "diff", "--name-only", patch_sha, diff_target], 
universal_newlines=True
+        ["git", "diff", "--name-only", "--no-renames", patch_sha, diff_target],

Review Comment:
   **Non-blocking (P2):** This flag fixes the helper, but the precondition job 
in `.github/workflows/build_and_test.yml` still builds its own changed-file 
list at line 135 with `git diff --name-only "$APACHE_SPARK_REF" HEAD`. That 
command keeps git's rename detection and diffs from base to head, so it lists 
only a rename's new path, and on fork PR builds that list alone sets the 
`sparkr`, `transpile` and `static_only` gates (build_and_test.yml lines 
132-167), while `dev/is-changed.py`, running in the same step, now sees both 
paths.
   
   As a result, a rename whose old path matches one of those gates and whose 
new path does not still skips the tests the gate controls. Moving `R/pkg/foo.R` 
to `dev/foo.R` leaves `sparkr` false, so the SparkR job does not run. Renaming 
a `*transpile*` file to a name without `transpile` leaves `transpile` false, so 
the PySpark job skips the UDF transpile hypothesis tests. A PR whose only 
change moves a resource from outside a static directory into a 
`*/resources/*/static/*` directory gets `static_only=true`, which turns off the 
PySpark, pandas-on-Spark, SparkR, TPC-DS and Docker integration jobs. Replaying 
that gating in a scratch repository reproduced all three, and with 
`--no-renames` the same renames give `sparkr=true`, `transpile=true` and 
`static_only=false`.
   
   Adding `--no-renames` to the command at 
`.github/workflows/build_and_test.yml` line 135 would carry this fix to the 
other list that CI test selection reads.
   
   **Verification:**
   - **Regression:** Replay the gating at lines 132-167 of 
.github/workflows/build_and_test.yml over three scratch repository commits that 
each rename a file whose old path matches a gate its new path does not: one 
moves `R/pkg/foo.R` to `dev/foo.R`, one renames `sql/x/transpile_rules.py` to 
`sql/x/rules.py`, and one has as its only change a resource file moved from 
outside a `*/resources/*/static/*` directory into one. With the flag, confirm 
the first gives sparkr=true, the second transpile=true, and the third 
static_only=false; without it, they give sparkr=false, transpile=false, and 
static_only=true.
   - **Compatibility:** For a change without renames, such as one that edits 
one file and adds another, confirm the command at 
.github/workflows/build_and_test.yml line 135 lists exactly the same paths with 
and without `--no-renames`, so the gates of ordinary PRs are unchanged.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to