This is an automated email from the ASF dual-hosted git repository.

nchammas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/master by this push:
     new 94bd3dcf4b7c [SPARK-59569][BUILD] Add support for shell script test 
goals
94bd3dcf4b7c is described below

commit 94bd3dcf4b7cfade398e05253374544b4316f980
Author: Nicholas Chammas <[email protected]>
AuthorDate: Thu Nov 12 16:12:09 2026 -0500

    [SPARK-59569][BUILD] Add support for shell script test goals
    
    ### What changes were proposed in this pull request?
    
    Add a new test goal type: shell scripts. A shell script test goal runs a 
script at a specific stage of our test build and confirms it succeeds.
    
    Port the existing build test (`test-dependencies.sh`) over to this new test 
goal type.
    
    ### Why are the changes needed?
    
    We have many existing tests that fit the pattern of a shell script test 
goal. However, they are currently all expressed as custom functions in 
`dev/run-tests.py` with custom execution handling there and in our workflows. 
This makes it very hard to standardize the handling of these tests, to express 
test dependencies, or select/deselect tests based on what files are modified in 
a given PR.
    
    This PR migrates just the existing build test as a demonstration of its 
use, but in follow-up PRs I plan to migrate all of the following tests to this 
new test goal type:
    
    | Stage | Script |
    | --- | --- |
    | `pre_build` | `dev/check-license` |
    | `pre_build` | `dev/check-protos.py` |
    | `pre_build` | `dev/lint-java` |
    | `pre_build` | `dev/lint-js` |
    | `pre_build` | `dev/lint-python` |
    | `pre_build` | `dev/lint-scala` |
    | `pre_build` | `dev/structured_logging_style.py` |
    | `pre_build` | `dev/test-dependencies.sh` (done in this PR) |
    | `pre_build` | New UI Jest wrapper |
    | `post_build` | `dev/connect-jvm-client-mima-check` |
    | `post_build` | `dev/mima` |
    | `post_assembly_sbt` | `dev/sbt-checkstyle` |
    | `post_assembly` | `dev/run-pip-tests` |
    
    Some of these shell script tests require additional context to be passed 
in, like the active sbt profiles or a list of files modified by the PR. When I 
port these tests to the new test goal type, I will make the necessary API 
changes to `ShellScriptTestGoal`.
    
    The proposed stages apart from `pre_build` are tentative. I will firm them 
up one by one as I port the first test to that stage.
    
    ### Does this PR introduce _any_ user-facing change?
    
    No.
    
    ### How was this patch tested?
    
    New unit tests added to `sparktestsupport`, executed via:
    
    ```sh
    python3 -m unittest discover -s dev/sparktestsupport/tests -t dev
    ```
    
    I also ran `SKIP_SCALA_BUILD=true SKIP_MIMA=1 ./dev/run-tests --modules 
build` locally and confirmed it runs `dev/test-dependencies.sh` via the new 
shell script goal. Ran the same with `--modules docs` and confirmed it does not.
    
    ### Was this patch authored or co-authored using generative AI tooling?
    
    Generated-by: GitHub Copilot
    
    Closes #59250 from nchammas/shell-script-test-goals.
    
    Authored-by: Nicholas Chammas <[email protected]>
    Signed-off-by: Nicholas Chammas <[email protected]>
    
    
    skip-checks: true
---
 dev/run-tests.py                           | 21 +++++--
 dev/sparktestsupport/modules.py            | 64 ++++++++++++++++++--
 dev/sparktestsupport/tests/test_modules.py | 96 +++++++++++++++++++++++++++++-
 dev/sparktestsupport/tests/test_utils.py   | 20 +++++++
 dev/sparktestsupport/utils.py              | 17 ++++++
 5 files changed, 207 insertions(+), 11 deletions(-)

diff --git a/dev/run-tests.py b/dev/run-tests.py
index 93d327e7add2..530411166c4b 100755
--- a/dev/run-tests.py
+++ b/dev/run-tests.py
@@ -24,6 +24,7 @@ import subprocess
 import sys
 import tempfile
 from argparse import ArgumentParser
+from collections.abc import Sequence
 from contextlib import contextmanager
 
 import sparktestsupport.modules as modules
@@ -33,6 +34,7 @@ from sparktestsupport.utils import (
     determine_dangling_python_tests,
     determine_modules_for_files,
     determine_modules_to_test,
+    determine_shell_script_test_goals,
     identify_changed_files_from_git_commits,
 )
 
@@ -380,8 +382,16 @@ def run_python_packaging_tests():
     run_cmd(command)
 
 
-def run_build_tests():
-    run_cmd([os.path.join(SPARK_HOME, "dev", "test-dependencies.sh")])
+def run_shell_script_tests(
+    test_modules: Sequence[modules.Module], stage: modules.TestStage
+) -> None:
+    """Run the selected shell script goals for the given stage."""
+    shell_script_test_goals = determine_shell_script_test_goals(test_modules, 
stage)
+
+    for test_goal in shell_script_test_goals:
+        with titled_block(f"Running {test_goal.path}"):
+            command = [os.path.join(SPARK_HOME, test_goal.path)]
+            run_cmd(command)
 
 
 def run_sparkr_tests():
@@ -602,9 +612,10 @@ def main():
             with titled_block("Running R style checks"):
                 run_sparkr_style_checks()
 
-    if any(m.should_run_build_tests for m in test_modules):
-        with titled_block("Running build tests"):
-            run_build_tests()
+    run_shell_script_tests(
+        test_modules,
+        modules.TestStage.PRE_BUILD,
+    )
 
     # spark build
     if os.environ.get("SKIP_SCALA_BUILD", "false") != "true":
diff --git a/dev/sparktestsupport/modules.py b/dev/sparktestsupport/modules.py
index 2993a683094a..7c344d76ea77 100644
--- a/dev/sparktestsupport/modules.py
+++ b/dev/sparktestsupport/modules.py
@@ -18,6 +18,9 @@
 import itertools
 import os
 import re
+from collections.abc import Sequence
+from dataclasses import dataclass
+from enum import Enum
 from functools import total_ordering
 from pathlib import Path, PurePath
 
@@ -180,6 +183,47 @@ def is_ignored_file(filename: str) -> bool:
     return False
 
 
+class TestStage(Enum):
+    """
+    When a shell script test goal runs in dev/run-tests.py.
+    """
+
+    # Before the Spark build.
+    PRE_BUILD = "pre_build"
+
+
+@dataclass(frozen=True)
+class ShellScriptTestGoal:
+    """
+    Describe a shell script test goal.
+
+    >>> goal = ShellScriptTestGoal("dev/example")
+    >>> goal.stage.value
+    'pre_build'
+
+    The stage must be a `TestStage`, not its string value. The path may be 
supplied
+    as a `str` or `Path` and is normalized to a `Path`. It must be non-blank,
+    repository-relative, and must not contain `..` path components.
+    """
+
+    path: Path
+    stage: TestStage
+
+    def __init__(self, path: str | Path, stage: TestStage = 
TestStage.PRE_BUILD) -> None:
+        if not isinstance(stage, TestStage):
+            raise TypeError(f"Unsupported test stage: {stage!r}")
+        original_path = path
+        # `Path` rejects non-path types and normalizes spellings like 
"./dev//x".
+        path = Path(path)
+        if not str(path).strip() or path == Path() or path.is_absolute() or 
".." in path.parts:
+            raise ValueError(
+                f"Shell script path must be relative to repo root: 
{str(original_path)!r}"
+            )
+        # We have to call `object.__setattr__` because the class is frozen.
+        object.__setattr__(self, "path", path)
+        object.__setattr__(self, "stage", stage)
+
+
 @total_ordering
 class Module(object):
     """
@@ -198,10 +242,10 @@ class Module(object):
         environ=None,
         sbt_test_goals=(),
         python_test_goals=(),
+        shell_script_test_goals: Sequence[ShellScriptTestGoal] = (),
         excluded_python_implementations=(),
         test_tags=(),
         should_run_r_tests=False,
-        should_run_build_tests=False,
     ):
         """
         Define a new module.
@@ -219,16 +263,24 @@ class Module(object):
             module are changed.
         :param sbt_test_goals: A set of SBT test goals for testing this module.
         :param python_test_goals: A set of Python test goals for testing this 
module.
+        :param shell_script_test_goals: A sequence (e.g. a list or tuple) of 
shell script test
+            goals for testing this module.
         :param excluded_python_implementations: A set of Python 
implementations that are not
             supported by this module's Python components. The values in this 
set should match
             strings returned by Python's `platform.python_implementation()`.
         :param test_tags A set of tags that will be excluded when running unit 
tests if the module
             is not explicitly changed.
         :param should_run_r_tests: If true, changes in this module will 
trigger all R tests.
-        :param should_run_build_tests: If true, changes in this module will 
trigger build tests.
         """
         if any(module.name == name for module in all_modules):
             raise ValueError(f"module name {name!r} is already in use")
+        if isinstance(shell_script_test_goals, (str, bytes)) or not isinstance(
+            shell_script_test_goals, Sequence
+        ):
+            raise TypeError(f"{name}: shell_script_test_goals must be a 
sequence")
+        for goal in shell_script_test_goals:
+            if not isinstance(goal, ShellScriptTestGoal):
+                raise TypeError(f"{name}: expected ShellScriptTestGoal, got 
{goal!r}")
 
         self.name = name
         self.dependencies = dependencies
@@ -237,10 +289,10 @@ class Module(object):
         self.build_profile_flags = build_profile_flags
         self.environ = environ or {}
         self.python_test_goals = python_test_goals
+        self.shell_script_test_goals = shell_script_test_goals
         self.excluded_python_implementations = excluded_python_implementations
         self.test_tags = test_tags
         self.should_run_r_tests = should_run_r_tests
-        self.should_run_build_tests = should_run_build_tests
 
         self.dependent_modules = set()
         for dep in dependencies:
@@ -1883,7 +1935,7 @@ build = Module(
         ".*pom.xml",
         "dev/test-dependencies.sh",
     ],
-    should_run_build_tests=True,
+    shell_script_test_goals=[ShellScriptTestGoal("dev/test-dependencies.sh")],
 )
 
 yarn = Module(
@@ -1952,8 +2004,10 @@ root = Module(
         "test",
     ],
     python_test_goals=list(itertools.chain.from_iterable(m.python_test_goals 
for m in all_modules)),
+    shell_script_test_goals=list(
+        itertools.chain.from_iterable(m.shell_script_test_goals for m in 
all_modules)
+    ),
     should_run_r_tests=True,
-    should_run_build_tests=True,
 )
 
 
diff --git a/dev/sparktestsupport/tests/test_modules.py 
b/dev/sparktestsupport/tests/test_modules.py
index b0087137469d..0540cceee542 100644
--- a/dev/sparktestsupport/tests/test_modules.py
+++ b/dev/sparktestsupport/tests/test_modules.py
@@ -15,10 +15,13 @@
 # limitations under the License.
 #
 
+import os
 import unittest
+from pathlib import Path
 from unittest import mock
 
-from sparktestsupport import modules
+from sparktestsupport import SPARK_HOME, modules
+from sparktestsupport.shellutils import is_exe
 from sparktestsupport.utils import determine_modules_for_files, 
determine_modules_to_test
 
 
@@ -34,6 +37,51 @@ class IsIgnoredFileTests(unittest.TestCase):
         
self.assertFalse(modules.is_ignored_file("dev/sparktestsupport/modules.py"))
 
 
+class ShellScriptTestGoalTests(unittest.TestCase):
+    def test_default_stage(self):
+        goal = modules.ShellScriptTestGoal("dev/example")
+        self.assertIs(goal.stage, modules.TestStage.PRE_BUILD)
+
+    def test_normalizes_and_hashes_equivalent_paths(self):
+        goal = modules.ShellScriptTestGoal("dev/example")
+        equivalents = (
+            modules.ShellScriptTestGoal(Path("dev/example")),
+            modules.ShellScriptTestGoal("./dev//example"),
+        )
+        self.assertEqual(goal.path, Path("dev/example"))
+        for equivalent in equivalents:
+            with self.subTest(goal=equivalent):
+                self.assertEqual(equivalent.path, goal.path)
+                self.assertEqual(equivalent, goal)
+        self.assertEqual(len({goal, *equivalents}), 1)
+
+    def test_rejects_invalid_stages(self):
+        for stage in ("post_build", "pre_build", None):
+            with self.subTest(stage=stage):
+                with self.assertRaises(TypeError) as error:
+                    modules.ShellScriptTestGoal("dev/example", stage)
+                self.assertEqual(str(error.exception), f"Unsupported test 
stage: {stage!r}")
+
+    def test_rejects_invalid_paths(self):
+        absolute_path = Path.cwd() / "example"
+        for path in (
+            str(absolute_path),
+            absolute_path,
+            "",
+            "  ",
+            ".",
+            "../example",
+            "dev/../example",
+        ):
+            with self.subTest(path=path):
+                with self.assertRaises(ValueError) as error:
+                    modules.ShellScriptTestGoal(path)
+                self.assertEqual(
+                    str(error.exception),
+                    f"Shell script path must be relative to repo root: 
{str(path)!r}",
+                )
+
+
 class ModuleTests(unittest.TestCase):
     def test_duplicate_name_does_not_change_module_graph(self):
         with mock.patch.object(modules, "all_modules", []):
@@ -44,6 +92,46 @@ class ModuleTests(unittest.TestCase):
             self.assertEqual(modules.all_modules, [dependency, original])
             self.assertEqual(dependency.dependent_modules, set())
 
+    def test_shell_script_test_goals_accept_sequences(self):
+        goal = modules.ShellScriptTestGoal("dev/lint")
+        with mock.patch.object(modules, "all_modules", []):
+            for index, goals in enumerate(([goal], (goal,))):
+                with self.subTest(goals=goals):
+                    module = modules.Module(f"valid-{index}", [], [], 
shell_script_test_goals=goals)
+                    self.assertEqual(module.shell_script_test_goals, goals)
+
+    def test_shell_script_test_goals_require_a_sequence(self):
+        goal = modules.ShellScriptTestGoal("dev/lint")
+        invalid_goals = (
+            "dev/lint-java",
+            b"dev/lint-java",
+            goal,
+            (item for item in [goal]),
+        )
+        with mock.patch.object(modules, "all_modules", []):
+            dependency = modules.Module("dependency", [], [])
+            for goals in invalid_goals:
+                with self.subTest(goals=goals):
+                    with self.assertRaisesRegex(
+                        TypeError, "^invalid: shell_script_test_goals must be 
a sequence$"
+                    ):
+                        modules.Module("invalid", [dependency], [], 
shell_script_test_goals=goals)
+                    self.assertEqual(modules.all_modules, [dependency])
+                    self.assertEqual(dependency.dependent_modules, set())
+
+    def test_shell_script_test_goals_reject_invalid_items(self):
+        goal = modules.ShellScriptTestGoal("dev/lint")
+        with mock.patch.object(modules, "all_modules", []):
+            dependency = modules.Module("dependency", [], [])
+            for goals in (["dev/lint-java"], [goal, "dev/lint-java"]):
+                with self.subTest(goals=goals):
+                    with self.assertRaisesRegex(
+                        TypeError, "^invalid: expected ShellScriptTestGoal, 
got 'dev/lint-java'$"
+                    ):
+                        modules.Module("invalid", [dependency], [], 
shell_script_test_goals=goals)
+                    self.assertEqual(modules.all_modules, [dependency])
+                    self.assertEqual(dependency.dependent_modules, set())
+
 
 class ModuleDefinitionsTests(unittest.TestCase):
     def test_all_pyspark_modules_depend_on_base(self):
@@ -66,6 +154,12 @@ class ModuleDefinitionsTests(unittest.TestCase):
         }
         self.assertEqual(set(modules.root.build_profile_flags), expected)
 
+    def test_shell_script_test_goals_are_executable(self):
+        for module in modules.all_modules:
+            for goal in module.shell_script_test_goals:
+                with self.subTest(module=module.name, goal=str(goal.path)):
+                    self.assertTrue(is_exe(os.path.join(SPARK_HOME, 
goal.path)))
+
     def test_streaming_kafka_does_not_match_sql_kafka(self):
         self.assertTrue(
             
modules.streaming_kafka_0_10.contains_file("connector/kafka-0-10/test.scala")
diff --git a/dev/sparktestsupport/tests/test_utils.py 
b/dev/sparktestsupport/tests/test_utils.py
index d8395bdba384..eb08f50692d2 100644
--- a/dev/sparktestsupport/tests/test_utils.py
+++ b/dev/sparktestsupport/tests/test_utils.py
@@ -24,6 +24,7 @@ from sparktestsupport.utils import (
     determine_dangling_python_tests,
     determine_modules_for_files,
     determine_modules_to_test,
+    determine_shell_script_test_goals,
     identify_changed_files_from_git_commits,
 )
 
@@ -138,6 +139,25 @@ class DetermineModulesToTestTests(unittest.TestCase):
         self.assertCountEqual([module.name for module in result], expected)
 
 
+class DetermineShellScriptTestGoalsTests(unittest.TestCase):
+    def test_preserves_order_and_deduplicates_goals(self):
+        a, b, c = (modules.ShellScriptTestGoal(f"dev/{name}") for name in 
"abc")
+        with mock.patch.object(modules, "all_modules", []):
+            first = modules.Module("first", [], [], 
shell_script_test_goals=[b, a])
+            duplicate_b = modules.ShellScriptTestGoal("./dev//b")
+            second = modules.Module("second", [], [], 
shell_script_test_goals=[c, duplicate_b])
+            self.assertEqual(
+                determine_shell_script_test_goals([first, second], 
modules.TestStage.PRE_BUILD),
+                (b, a, c),
+            )
+
+    def test_root_includes_test_dependencies(self):
+        self.assertIn(
+            modules.ShellScriptTestGoal("dev/test-dependencies.sh"),
+            determine_shell_script_test_goals([modules.root], 
modules.TestStage.PRE_BUILD),
+        )
+
+
 class DetermineDanglingPythonTestsTests(unittest.TestCase):
     def setUp(self):
         # Pretend every changed file exists so results do not depend on the 
working directory.
diff --git a/dev/sparktestsupport/utils.py b/dev/sparktestsupport/utils.py
index d1f1ba3ea698..f8642935db7d 100644
--- a/dev/sparktestsupport/utils.py
+++ b/dev/sparktestsupport/utils.py
@@ -15,8 +15,10 @@
 # limitations under the License.
 #
 
+import itertools
 import os
 import subprocess
+from collections.abc import Sequence
 
 from sparktestsupport import modules
 from sparktestsupport.shellutils import run_cmd
@@ -109,6 +111,21 @@ def determine_modules_to_test(changed_modules, 
deduplicated=True):
     )
 
 
+def determine_shell_script_test_goals(
+    test_modules: Sequence[modules.Module], stage: modules.TestStage
+) -> tuple[modules.ShellScriptTestGoal, ...]:
+    """
+    Return the shell script test goals that the given modules declare for a 
stage.
+
+    Goals are returned in the order determined by the modules passed in,
+    preserving each module's declaration order. Each goal is returned only 
once.
+    """
+    declared_goals = itertools.chain.from_iterable(m.shell_script_test_goals 
for m in test_modules)
+    stage_goals = (goal for goal in declared_goals if goal.stage == stage)
+    # `dict.fromkeys` preserves order, unlike `set`.
+    return tuple(dict.fromkeys(stage_goals))
+
+
 def determine_dangling_python_tests(changed_files):
     """
     Given a list of changed files, return the set of Python tests that are not 
associated with any


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

Reply via email to