-
Notifications
You must be signed in to change notification settings - Fork 5.1k
bun test: stop truncating .snap files on open, write them per file and on --bail #38974
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
robobun
wants to merge
6
commits into
main
Choose a base branch
from
farm/9bea3ead/bail-flush-snapshots
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a4e585e
bun test: write snapshot files and inline snapshots before exiting on…
robobun 984da5a
test: drain stdout and leave LSAN off for the --bail children
robobun 2e9a25f
bun test: shorten the write_snapshots_before_bail doc comment
robobun f0778dd
bun test: drop the doc comment on write_snapshots_before_bail
robobun 8a17153
bun test: replace the .snap file only when its contents are written, …
robobun a09511d
bun test: one-line comments at the snapshot write sites
robobun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 The per-file
write_snapshot_file()at line 3421 both prints viaOutput::errandreturn Err(err); every caller ofTestCommand::runroutes that Err tohandle_top_level_test_error_before_javascript_start(-> !,Global::exit(1)), so apwrite/ftruncatefailure after a file's tests have run hard-exits without JUnit/timings/summary or remaining files, and a--parallelworker exits before sendingFileDone(which the coordinator reads as a crash — see the comment inbuild_worker_argv). This is inconsistent withwrite_snapshots_before_bailin the same PR, which prints the identical error and continues; drop thereturn Err(err)to match.Extended reasoning...
What the bug is
The new per-file snapshot flush at
test_command.rs:3421-3424handles awrite_snapshot_file()failure by printing it (Output::err(err.name(), "Failed to write snapshot file", ())) and propagating it (return Err(err)). ButTestCommand::run's callers do not handle a returnedErrgracefully:run_all_testsattest_command.rs:3125andtest_command.rs:3154WorkerLoop::beginatparallel/runner.rs:571All three route it to
handle_top_level_test_error_before_javascript_start(test_command.rs:3429-3436), which is-> !and callsGlobal::exit(1)unconditionally. So an I/O failure writing the.snap— after the file's tests have already run to completion — aborts the whole process.The code path
TestCommand::runreaches line 3421 and callsreporter.jest.snapshots.write_snapshot_file().pwrite_allorftruncatefails (e.g.ENOSPC,EIO, filesystem gone read-only mid-run) →Err(FailedToWriteSnapshotFile).Err.handle_top_level_test_error_before_javascript_start, whichGlobal::exit(1)— beforewrite_junit_report_if_needed/write_timings_if_needed/ the summary, and before any remaining test files run. In a--parallelworker the process exits before theFileDoneframe is sent, whichbuild_worker_argv's own comment says the coordinator "would misread as a crash".Output::errat 3422, again bydebug_warn!at 3432.Why existing code doesn't prevent it
The handler is named
..._before_javascript_startand was designed for module-resolution-style failures that happen before a file's JS runs. This newErris returned after the file's tests have all executed, so it lands in a handler semantically not meant for it. There is no other exit-time flush for JUnit/timings on this path — contrast the two bail exits at lines 1527-1529 and 3313-3315, which explicitly callwrite_junit_report_if_needed/write_timings_if_neededbeforeGlobal::exit.Why it's inconsistent within this PR
write_snapshots_before_bail(test_command.rs:1556-1563), added in the same PR, handles the identical error from the identical function with print-and-continue:— no propagation, so JUnit/timings still get written on the very next lines. The per-file site should do the same.
It is also a behavior change vs. main: before this PR the equivalent write happened lazily inside
get_snapshot_file()on the next file's firsttoMatchSnapshot(), where an error surfaced throughget_or_putas a per-test JS exception (one assertion fails, the run continues). This PR upgrades the same underlying I/O failure to a whole-process abort.Impact
Rare in practice —
pwrite_all/ftruncatefailing on an fd that was successfully openedO_RDWRmoments earlier requires disk-full/quota/EIO/EROFS mid-run. Nothing breaks in normal operation, hence nit. But when it does trigger: the JUnit report and--timingsfile are lost (both of which the bail paths in this PR go out of their way to preserve), remaining test files are silently skipped, and under--parallelthe coordinator reports the file as a worker crash rather than a snapshot-write failure.Fix
Drop the
return Err(err);at line 3423 to matchwrite_snapshots_before_bail:If a nonzero exit is desired for this case, bump a failure counter on the reporter/summary instead so the run finishes and JUnit/timings are still written.