mycobun-test-runtime-hardeninglisted
Install: claude install-skill goondocks-co/myco
# Bun Test Runtime Hardening
Bun runs its test suite in a shared process where module-scope state persists
across test files. This creates three categories of hard-to-diagnose failures:
process-scoped mock registrations that poison unrelated tests, module-level
timers that block suite exit, and eager SDK construction that fails in Bun's
browser-like environment. These issues typically surface only on CI — due to
non-deterministic file execution order — or after extended test runs.
## Prerequisites
- You are working within Myco's monorepo test suite, executed via `npm test`
or direct `bun test` invocations
- Understand that `npm test` delegates to `node scripts/run-bun-tests.mjs`,
which orchestrates multiple Bun process invocations. Files in the same
`NO_ISOLATE_NODE_GROUPS` entry share a Bun process.
- To reproduce CI ordering locally, run `bun test --watch=false` on the same
group of files that CI bundles together (e.g., the `tests-agent-stable` group
in `scripts/run-bun-tests.mjs`).
## Procedure A: Isolating Process-Scoped mock.module() Registrations
**When to apply:** A test file uses top-level `mock.module()` calls outside any
`beforeEach`/`describe` block, and other test files that import the same module
fail non-deterministically on CI.
**Root cause:** Bun's `mock.module()` is **process-scoped, not file-scoped**.
When multiple test files share one Bun process (i.e., they are in the same
`NO_ISOLATE_NODE_GROUPS` entry in `scripts/run-bun-tests.mjs`), a to