Skip to content

test: isolate store singleton from cross-file bun leaks#386

Merged
JoshMock merged 1 commit into
mainfrom
fix/bun-store-test-isolation
May 29, 2026
Merged

test: isolate store singleton from cross-file bun leaks#386
JoshMock merged 1 commit into
mainfrom
fix/bun-store-test-isolation

Conversation

@margaretjgu

Copy link
Copy Markdown
Member

Summary

  • Fixes the Test Bun CI failure on main, which started at commit 2297c98 (fix: respect --json flag on --help for root and groups #373) and fails at test/config/store.test.ts:25 (store > getResolvedConfig > returns undefined before any config is set).
  • Root cause: src/config/store.ts is a module-level singleton. bun test runs all test files in a shared process (and distributes them across concurrent workers that share module state), unlike node --test, which isolates each file. Sibling suites such as test/lib/es-client.test.ts leave _config set to { context: {} } in their afterEach, so when store.test.ts's first test runs after one of them in the same worker, the initial-state assertion fails. The node runner never sees this because it isolates files.
  • Commit 2297c98 added a large batch of tests to test/cli.test.ts and test/factory.test.ts, which perturbed bun's per-worker file scheduling enough to surface this pre-existing latent leak.
  • The fix resets the store singleton via _testResetConfig() in a beforeEach (in addition to afterEach), so the test no longer depends on residual global state and is order-independent under both bun and node.

Test plan

  • npx tsc --noEmit passes
  • npx tsx --test test/config/store.test.ts passes (node runner)
  • bun test test/lib/es-client.test.ts test/config/store.test.ts passes (bun, polluter ordering)
  • CI Test Bun job is green on all three OS runners

@github-actions

Copy link
Copy Markdown
Contributor

MegaLinter analysis: Success

Descriptor Linter Files Fixed Errors Warnings Elapsed time
✅ COPYPASTE jscpd yes no no 10.61s
✅ REPOSITORY gitleaks yes no no 60.79s
✅ REPOSITORY git_diff yes no no 0.77s
✅ REPOSITORY secretlint yes no no 33.16s
✅ REPOSITORY trivy yes no no 18.57s
✅ TYPESCRIPT eslint 1 0 0 3.65s

Notices

📣 MegaLinter 9.5.0 is out! Discover the new features and security recommendations in the release announcement. (Skip this info by defining SECURITY_SUGGESTIONS: false)

See detailed reports in MegaLinter artifacts
Set VALIDATE_ALL_CODEBASE: true in mega-linter.yml to validate all sources, not only the diff

MegaLinter is graciously provided by OX Security
Show us your support by starring ⭐ the repository

@JoshMock JoshMock merged commit a8893c6 into main May 29, 2026
23 checks passed
@JoshMock JoshMock deleted the fix/bun-store-test-isolation branch May 29, 2026 18:51
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.

2 participants