Summary
test/config/store.test.ts contains a test that is order-dependent and intermittently fails under Bun's test runner:
1 tests failed:
(fail) store > getResolvedConfig > returns undefined before any config is set [2.72ms]
Observed in CI run 26566675678 / job 78263017234 on PR #373. A re-run of the same commit (26566675678 second attempt) passed, confirming the failure is non-deterministic.
Root cause
test/config/store.test.ts:24 asserts:
it('returns undefined before any config is set', () => {
assert.equal(getResolvedConfig(), undefined)
})
The file's only cleanup hook is afterEach, which runs after each test. The first test therefore relies on the module's initial state (_config = undefined at module load time).
- Under Node's built-in
--test runner, each test file runs in an isolated worker, so the singleton state is always fresh.
- Under Bun's runner, all test files share a single process and the same module instance. Whenever another test file (
test/lib/cloud-client.test.ts, test/lib/es-client.test.ts, test/lib/kibana-client.test.ts, test/kb/kibana-client.test.ts, test/factory.test.ts) loads first and calls setResolvedConfig, its afterEach is supposed to reset state — but file ordering, parallelism, and missing before cleanup combine to expose a race where _config is non-undefined when the store test starts.
Small changes to other test files (adding/removing tests, renaming describes) can shift Bun's file-discovery order and trigger the failure. This makes it a latent CI hazard that surfaces on unrelated PRs.
Suggested fix
Add an explicit reset before the first test so it's order-independent:
import { describe, it, beforeEach, afterEach } from 'node:test'
// ...
beforeEach(() => {
setResolvedConfig(undefined as unknown as ResolvedConfig)
})
afterEach(() => {
setResolvedConfig(undefined as unknown as ResolvedConfig)
})
Optionally rename the first test from "returns undefined before any config is set" → "returns undefined when the store has been reset" so the assertion matches what's actually being verified.
The same pattern (relying on initial singleton state) should be audited in other test files that import from src/config/store.ts to make sure none of them have a similar order-dependent first test.
Acceptance criteria
Summary
test/config/store.test.tscontains a test that is order-dependent and intermittently fails under Bun's test runner:Observed in CI run 26566675678 / job 78263017234 on PR #373. A re-run of the same commit (26566675678 second attempt) passed, confirming the failure is non-deterministic.
Root cause
test/config/store.test.ts:24asserts:The file's only cleanup hook is
afterEach, which runs after each test. The first test therefore relies on the module's initial state (_config = undefinedat module load time).--testrunner, each test file runs in an isolated worker, so the singleton state is always fresh.test/lib/cloud-client.test.ts,test/lib/es-client.test.ts,test/lib/kibana-client.test.ts,test/kb/kibana-client.test.ts,test/factory.test.ts) loads first and callssetResolvedConfig, itsafterEachis supposed to reset state — but file ordering, parallelism, and missingbeforecleanup combine to expose a race where_configis non-undefined when the store test starts.Small changes to other test files (adding/removing tests, renaming describes) can shift Bun's file-discovery order and trigger the failure. This makes it a latent CI hazard that surfaces on unrelated PRs.
Suggested fix
Add an explicit reset before the first test so it's order-independent:
Optionally rename the first test from "returns undefined before any config is set" → "returns undefined when the store has been reset" so the assertion matches what's actually being verified.
The same pattern (relying on initial singleton state) should be audited in other test files that import from
src/config/store.tsto make sure none of them have a similar order-dependent first test.Acceptance criteria
test/config/store.test.tspasses regardless of which test files run before it.