Repository navigation
fix(@angular/build): sort discovered unit-test files for deterministic builds - #34337
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the findTests function to sort the resolved test files, ensuring deterministic build outputs regardless of the asynchronous directory crawling order. A new unit test suite has also been added to verify this sorting behavior. The review feedback suggests providing an explicit, locale-independent comparison function to Array.prototype.sort() to avoid potential linting errors and guarantee strict determinism across different environments.
7af73a2 to
72f963a
Compare
This comment was marked as resolved.
This comment was marked as resolved.
|
Oh nvm, it seems the tooling error was saying you didn't sign the CLA when you actually did. Should be good to merge. |
|
This pull request has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
PR Checklist
PR Type
What is the current behavior?
Issue Number: #34335
findTestsreturns the test files in the ordertinyglobbyyields them. The glob crawls directories asynchronously, so the order changes between runs: on a project with 255 spec files, 8 consecutive calls returned 8 different orders (same set of files). That order feeds the build entry points androotFiles, so twong testbuilds of the same sources produce different chunks: imports come out reordered, the content-hashed chunk names change, and the change cascades to every importer (79 to 89 of 593 output files renamed between two runs). This defeats Vitest 5'sfsModuleCache, which is keyed on file content.What is the new behavior?
The discovered test files are sorted before being turned into entry points. With that change, three consecutive builds of the same project produced byte-identical test bundles (0 of 593 files differing,
--dump-virtual-filesoutput compared withdiff -r), and Vitest's module cache was fully reused across runs.A
findTestsspec checks the result is sorted. The crawl order can happen to be sorted on a small fixture, so it guards against a regression rather than reproducing the race on every run.Does this PR introduce a breaking change?
Other information
Measured with
@angular/build22.2.2, Vitest 5.0.4, Node 24, on macOS; the same non-determinism shows up in AOT and JIT test builds, with and without--coverage, and withNG_BUILD_MAX_WORKERS=1.