Skip to content

[SPARK-62148][INFRA] Refactor merge script's mega-doctest blob into unit tests - #60779

Open
nchammas wants to merge 2 commits into
apache:masterfrom
nchammas:prmerge-tests
Open

nchammas wants to merge 2 commits into
apache:masterfrom
nchammas:prmerge-tests

Conversation

@nchammas

@nchammas nchammas commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Move the doctests captured in __test__ out of dev/merge_spark_pr.py and into proper unit tests under dev/prmerge/tests/. These tests cover the abort path, the title prompts, JIRA updates, and main().

Before a merge, dev/merge_spark_pr.py still runs all of its own tests and stops if they fail. It also correctly instructs users on how to update the script and tests if they are stale.

Committers still run dev/merge_spark_pr.py. The merge itself is unchanged. Outside the tests, the only changes to the script are how it runs them at startup and the update command it suggests when it's out of date.

This change overlaps with #60472. Happy to help rebase whichever PR gets merged second.

Why are the changes needed?

__test__ is a single, massive text blob of doctests, about 1,000 lines long. Formatting these tests is brittle and failures are annoying to match to the source test as they show up without a line number:

File "dev/merge_spark_pr.py", line ?, in __main__.__test__.abort_entrypoint
Failed example:
    ...

Split out into proper unit tests, these tests are much easier to read, change, and maintain over time.

Moreover, this is the first step towards breaking up the merge script into a proper library under dev/prmerge with topic-specific modules and reusable tools. SPARK-62147 tracks the larger effort.

Does this PR introduce any user-facing change?

No.

For committers, the interface to and behavior of dev/merge_spark_pr.py is unchanged. It takes the same arguments and does the same merge.

A passing startup check is still quiet. If the unit tests fail, or dev/prmerge/tests/ is missing, the script prints a hint to update dev/merge_spark_pr.py and dev/prmerge/ together.

How was this patch tested?

I ran the unit tests directly, and I ran the script so it would execute both the doctests and the suite before printing help. I also ran it with a failing test and with dev/prmerge/ removed. Both stopped before the merge and printed the update hint. I also launched the script through a symlink from another directory, and it found the suite.

New tests cover the startup check's refusals (missing, failing, or empty suite), a passing suite staying quiet, the symlink case, and the entrypoint exiting with -1 before main() when the suite fails.

python3 -m unittest discover -s dev/prmerge/tests -t dev
python3 dev/merge_spark_pr.py --help

Was this patch authored or co-authored using generative AI tooling?

Generated-by: Cursor Grok 4.7
Generated-by: Cursor Claude Opus 5.5

spark-test

This comment was marked as resolved.

@nchammas
nchammas requested a review from spark-test November 22, 2026 00:00

@spark-test spark-test left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review summary

The latest commit addresses all six comments from the previous review. run_prmerge_tests() now resolves the script's real path, so a launch through a symlink finds the suite, and both update commands use git checkout --no-overlay, so files that master deleted are removed. New tests cover each refusal of the startup check and the exit before main(). The prepare_merge_title tests again assert the captured errors and the exact output, the missing-reopen-transition test again asserts that no transition is applied, and the _wrapped docstring now matches the summary the helper returns.

Three smaller gaps remain in the new startup check. A dev/prmerge/tests directory that exists without init.py, such as one left holding only pycache after its tracked files were removed, passes the isdir() guard, so unittest's discover() raises an uncaught ImportError instead of the check printing the not-found notice and the update command. The update command uses pathspecs relative to the repository root, so it fails when run from dev/, where the script's usage line launches it, or from any other subdirectory. The new refusal tests check only the hint line that every refusal shares, so no test fails if a refusal stops printing the failing test's report or prints the not-found notice in the wrong case.

The review also covered the doctest scenarios ported into the new test modules and the dev/prmerge entries added to .github/labeler.yml and dev/sparktestsupport/modules.py, with no finding there.

Cross-cutting observations

  • The new startup check in dev/merge_spark_pr.py refuses safely in every state this review traced: whether the script is launched directly or through a symlink, a missing, empty, failing, or unimportable dev/prmerge/tests stops it before main() runs, so no merge can start without a passing suite. The three findings listed below are about what a refused committer is told and how they recover, not about whether the check refuses.

    None of the three lets a merge start untested, so each is a non-blocking fix to what the refusal prints or to the tests that check it.

    Related:

    • Refusal tests don't check the failure report or the not-found notice
    • Printed update command works only from the repository root
    • Tests directory without init.py gets a traceback, not the update hint

Findings

3 total: 0 P0, 0 P1, 0 P2, 3 P3.

Nit (P3)

  • Tests directory without init.py gets a traceback, not the update hint — dev/merge_spark_pr.py:4252-4253 — see inline.
  • Printed update command works only from the repository root — dev/merge_spark_pr.py:4250 — see inline.
  • Refusal tests don't check the failure report or the not-found notice — dev/prmerge/tests/test_entrypoint.py:173 — see inline.

Re-review status

Prior AI findings: 6 no longer raised, 0 still raised; additional unresolved findings in this review: 3.

Of these: 1 in code changed since the previous review; 2 in code the previous review already covered.

Generated by Omnigent on Databricks

Comment thread dev/merge_spark_pr.py Resolved
Comment thread dev/merge_spark_pr.py
"If dev/prmerge/ is behind master, update it with the script:\n"
f" git fetch {PUSH_REMOTE_NAME} master && "
f"git checkout --no-overlay {PUSH_REMOTE_NAME}/master -- "
"dev/merge_spark_pr.py dev/prmerge\n"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit (P3): Git resolves these pathspecs against the current directory, and the hint is printed before main() runs, so the committer runs it from wherever they launched the script. From dev/, the directory the usage line ./merge_spark_pr.py assumes, or from any other subdirectory, the checkout fails with error: pathspec 'dev/merge_spark_pr.py' did not match any file(s) known to git (and the same for dev/prmerge) and updates nothing, so the committer has to work out that the paths are relative to the repository root. maybe_compile_check handles the dev/ working directory for the same reason (dev/merge_spark_pr.py:1352-1354). Top-anchored pathspecs work from any directory of the checkout:

Suggested change
"dev/merge_spark_pr.py dev/prmerge\n"
":/dev/merge_spark_pr.py :/dev/prmerge\n"

To keep one update command, print :/%s :/dev/prmerge in the out-of-date message at dev/merge_spark_pr.py:3965 as well. Add the prefix only in the message text: MERGE_SCRIPT_REPO_PATH also builds the GitHub commits query at dev/merge_spark_pr.py:3934, and the check treats a query that returns no commits as up to date.

Verification:

  • Regression: In a throwaway repository, run the update command the startup refusal prints from the repository root, from dev/, and from another subdirectory, in a checkout that predates dev/prmerge and in one that tracks a test module master has since deleted: every run exits 0, updates the script, and brings dev/prmerge to master's state, which removes the deleted module from the second checkout.
  • Inspection: The startup refusal and the out-of-date message print the same update command, neither one passes git a pathspec that resolves against the current directory, and the GitHub commits query still uses the unprefixed script path.

Comment thread dev/prmerge/tests/test_entrypoint.py Resolved

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants