Skip to content

test(core): build a private bundle for the worker-event forwarding test - #59

Merged
lucasbraum merged 1 commit into
mainfrom
fix/flaky-progress-worker-events
Oct 10, 2026
Merged

lucasbraum merged 1 commit into
mainfrom
fix/flaky-progress-worker-events

Conversation

@lucasbraum

Copy link
Copy Markdown
Collaborator

What and why

Closes #58.

forwards real workspace worker events without serializing the callback (packages/core/src/check/progress.test.ts) imported the shared packages/core/dist/index.js. pnpm build runs tsup with clean: true, which deletes and rewrites dist/. A build running at the same time as the test (the PR #54 case: lint and build in parallel) can remove the bundle while the child process imports it.

This was not a timing problem. There are no sleeps or fixed timeouts, and event order is fine: progress messages and the result share one worker port, so they arrive in order. Both failures I reproduced are the same ERR_MODULE_NOT_FOUND:

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/user/uptide/packages/core/dist/index.js' imported from /home/user/uptide/packages/core/[eval1]

The test exists to run the built worker (dist/worker.js), which the source-based suite never runs, so it still needs a real build. It now builds its own copy:

  • tsup with the package's own config, --no-dts --no-sourcemap (about 1 s), into a fresh mkdtemp directory under packages/core/node_modules/. Being inside the package lets the bundle's bare imports (ts-morph, …) resolve.
  • The directory is removed in afterAll.

No published code changes, so there is no changeset.

How it was verified

Each loop is 50 runs of vitest run src/check/progress.test.ts -t 'forwards real workspace' on a 4-core machine:

Load Before After
Busy loop on every core 0 / 50 failed not rerun (time was never the cause)
pnpm build and pnpm lint looping in parallel 2 / 50 failed (4%), both ERR_MODULE_NOT_FOUND 0 / 50 failed

At a 4% rate, 0 failures in 50 runs could still happen by chance (about 13%), so I also checked the mechanism directly. With packages/core/dist deleted, the original test fails with the same error and the new one passes.

Checklist

  • Tests for the change (with dist/ removed: the old test fails, the new one passes)
  • pnpm lint && pnpm typecheck && pnpm test pass (core 927 passed / 15 skipped, cli 350 passed)
  • README and docs updated if behavior changed (no behavior change)
  • Changeset added if a user would notice (test-only, none)
  • No new dependency (tsup is already a devDependency of @uptide/core)
  • No private code, names or paths in fixtures, tests or docs
  • The rules in CONTRIBUTING.md ("Rules that do not bend") still hold

Not changed here: other tests that read a package's dist/ (for example packages/cli/src/list-registry.test.ts and telemetry/sender.test.ts) could hit the same race when a build runs alongside them.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EmiChUUtLdjbg6mNzKqVep


Generated by Claude Code

The test imported packages/core/dist/index.js, which `pnpm build` (tsup,
clean: true) deletes and rewrites. A build running alongside the test could
remove the bundle mid-import: ERR_MODULE_NOT_FOUND, 2 failures in 50 runs
with build and lint looping in parallel. The test now builds its own copy
into a fresh directory under node_modules (so bare imports resolve) and
removes it afterwards. 0 failures in 50 runs under the same load.

Closes #58

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EmiChUUtLdjbg6mNzKqVep
Signed-off-by: Claude <noreply@anthropic.com>
@lucasbraum lucasbraum added the no-changeset Change needs no release note label Oct 10, 2026 — with Claude
@lucasbraum
lucasbraum marked this pull request as ready for review October 10, 2026 03:46
@lucasbraum
lucasbraum merged commit 45677eb into main Oct 10, 2026
8 of 9 checks passed
@lucasbraum
lucasbraum deleted the fix/flaky-progress-worker-events branch October 10, 2026 03:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-changeset Change needs no release note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky: progress.test.ts worker-event forwarding fails under load

2 participants