Skip to content

Tests: build dist/ once; Vitest: wait for bench workers to exit before reading their logs - #8

Merged
Saeris merged 6 commits into
mainfrom
fix/build-dist-once
Nov 9, 2026
Merged

Saeris merged 6 commits into
mainfrom
fix/build-dist-once

Conversation

@Saeris

@Saeris Saeris commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

Fixes the CI failures on main and the version PR (#5) after #7.

bench.spec.ts and preset.e2e.spec.ts each ran vp pack in a beforeAll, and vp pack empties dist/ first (clean: true). With test files in parallel, one rebuild deleted chunks that the other file's child process was loading. The race was already there with two rebuilds; #7 added a third, and it then failed on two runners:

  • Ubuntu, Node latest: ERR_MODULE_NOT_FOUND on dist/parseLog-*.mjs in bench.spec.ts.
  • macOS, Node latest: Cannot find package 'deoptkit/bench' in the iteration-limit project.

And a Windows-only failure, in the product. On one Windows lane per run, findings.json lacked the getX finding while the test before it found that finding in the same logs. That was not the race: it failed again here with dist/ built once. The cause is the order Vitest closes in. It starts stopping a worker when its file ends, but waits for the exit only in pool.close(), after global teardowns ("Runner terminations are started but not awaited until the end of full run"). V8 writes the end of a log as the process exits: sampling one log's size while its process ran, about 7% arrived only at exit. So the teardown could read a log before its worker finished it. The test after it reads once Vitest has exited, and sees the whole log.

The teardown now waits for each of this run's logs to lose its writer (the pid in v8-<pid>.log), up to 10 s, and names any worker still running on stderr. With isolate: false Vitest keeps workers until after the teardown, so there it skips the wait and says on stderr that the logs are unfinished. This affects users' own findings.json too, so the bump file is a patch.

A Vitest global setup (src/__tests__/buildDist.ts) now builds dist/ once, before any test file runs. Vitest finishes every project's global setup before it collects a file, so nothing can empty dist/ while a test is using it. No spec calls ensureDist() any more.

Checked:

  • No spec rebuilds dist/ (grep for ensureDist and "pack" in specs finds none).
  • With dist/ deleted, bench.spec.ts alone passes, because the setup builds it. With the setup removed too, it fails.
  • The teardown waits for a stand-in worker that writes its last line just before exiting, and doesn't wait for one under isolate: false (it returns at once and says why). Mutations: no wait, every writer treated as gone, the pid read wrongly, isolate: false ignored, no message, never waiting.
  • vp check is clean, and vp run test passes 194 tests in 26 files on Node 26.13 (Windows).

bench.spec.ts and preset.e2e.spec.ts each ran `vp pack` in a beforeAll, and `vp pack` empties dist/ first. With test files in parallel, one rebuild deleted chunks that the other file's child process was loading. After #7 added a third rebuild, main and the version PR failed three ways on three runners: ERR_MODULE_NOT_FOUND on dist/parseLog-*.mjs (Ubuntu), "Cannot find package 'deoptkit/bench'" (macOS), and a findings.json without the expected finding, because the teardown could not analyze its log (Windows).

A Vitest global setup now builds dist/ once, before any file runs, and no spec rebuilds it.
@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

bumpy-frog

The changes in this PR will be included in the next version bump.

patch Patch releases

  • deoptkit 0.2.0 → 0.2.1
  • deoptkit-vscode 0.1.0 → 0.1.1 (cascade)

Bump files in this PR

Click here if you want to add another bump file to this PR


This comment is maintained by bumpy.

…d finding

This test has failed on one Windows lane in three of the last five runs, while the test before it finds the same finding in the same logs. The failure now reports how many findings and logs findings.json holds, how many logs the manifest lists, and the child's stderr, where the teardown reports a log it could not analyze.
Vitest starts stopping a worker when its test file ends, but waits for the exit only when it closes the pool, after global teardowns ("Runner terminations are started but not awaited until the end of full run"). V8 writes the end of a log as the process exits: about 7% of one measured log arrived only at exit. So the teardown could read a log before its worker finished it, and write a findings.json without findings that were in the log. That is the Windows-only failure of "the teardown writes findings.json that the LSP can publish", where the test before it read the same logs later and found the finding.

The teardown now waits for each of this run's logs to lose its writer (the pid in v8-<pid>.log) before it reads them, for up to 10 s, and says on stderr which worker was still running if any was. With isolate: false Vitest keeps workers alive until after the teardown, so the wait can only time out there.
… logs may be unfinished

With isolate: false Vitest stops its workers only when it closes the pool, after the teardown, so waiting for them added the whole 10 s timeout to every run and still read unfinished logs. The setup reads isolate from the project; the teardown then skips the wait and says on stderr why findings.json may miss findings, and what to do instead.
@Saeris Saeris changed the title Tests: build dist/ once in a global setup, not in each spec that runs it Tests: build dist/ once; Vitest: wait for bench workers to exit before reading their logs Nov 9, 2026
…for each log's writer

On Linux, pids 1 and 2 always belong to running processes, so v8-1.log and v8-2.log made the teardown wait its full 10 s for system processes and the test timed out on every Ubuntu lane.
@Saeris
Saeris merged commit f637a62 into main Nov 9, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant