Fix module sort comparator and drop Drupal 8/9 dead code in autoloader - #1036
Merged
Conversation
mglaman
force-pushed
the
audit/1d-autoloader-cleanup
branch
from
August 5, 2026 17:15
8463308 to
af47a4d
Compare
mglaman
force-pushed
the
audit/1d-autoloader-cleanup
branch
from
August 5, 2026 19:13
af47a4d to
822edb0
Compare
mglaman
force-pushed
the
audit/1d-autoloader-cleanup
branch
from
August 5, 2026 19:33
822edb0 to
9bac357
Compare
mglaman
force-pushed
the
audit/1d-autoloader-cleanup
branch
from
September 8, 2026 17:42
9bac357 to
65d4b55
Compare
mglaman
changed the base branch from
audit/1c-latent-fixes
to
audit/1c2-legacy-cleanups
September 8, 2026 17:44
mglaman
force-pushed
the
audit/1d-autoloader-cleanup
branch
from
September 8, 2026 18:15
65d4b55 to
3c6afad
Compare
mglaman
force-pushed
the
audit/1d-autoloader-cleanup
branch
from
September 8, 2026 18:27
3c6afad to
f391e31
Compare
The usort callback never returned a negative value, so test-module ordering was implementation-defined. Replace it with a valid comparator that sorts _test extensions last. Remove the PhpUnit8 ClassWriter shim (removed in Drupal 10) and the Drush 8 directory-depth branch (composer requires drush ^11 || ^12 || ^13). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
mglaman
force-pushed
the
audit/1d-autoloader-cleanup
branch
from
September 8, 2026 18:27
f391e31 to
1f4686e
Compare
…he comparator The sort exists so test modules' .module files load after their parent module's. Test modules stub parent functions behind function_exists() guards, and loading them first turns the parent's declaration into a compile error the bootstrap cannot catch. Namespaces are keyed by module name, so order never affected them. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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.
Part 5 of 9 in the legacy-code audit stack (on top of #1042).
What changed
usortcallback inDrupalAutoloaderreturned 10 or 0 and ignored its second operand, so it was not a valid comparator and the order of test modules was implementation-defined. On PHP 8 it did not sort test modules last at all. Replaced with a valid comparator that reliably loads_testextensions after regular ones.function_exists()guards. If the test module's.modulefile loads first, the parent's unconditional declaration is a compile error thatloadAndCatchErrors()cannot intercept. This was the original blazy_test fix from 2019. The comment now says so.PhpUnit8\ClassWritershim (the class was removed in Drupal 10) and the Drush 8 directory-depth branch (composer requires drush ^11 || ^12 || ^13).Known consequence
Service definitions are last-writer-wins by ID. With the ordering now deterministic, a test module that redefines a production service ID always wins in the service map, where before the winner depended on filesystem order. Core's own collisions are against
core.services.yml, which is processed first regardless, and the pattern is rare in contrib. Tracked as a follow-up together with a path-based test-module check, since_testin the name misses test extensions undertests/directories and catches real modules likeab_tests.Testing
Full suite, self-analysis, and phpcs are green.
🤖 Generated with Claude Code