Repository navigation
Description
Symptom
test/config-migrate-api-url.test.ts passes on main HEAD (run 25861017229) but fails on dev HEAD (run 25861050894) with the same cumulative diff (just package.json version + auto-sync merge commit).
Failing assertions:
migrateApiUrl > first launch rewrites legacy URLs, drops top-level field, leaves live URLs alonemigrateApiUrl > only top-level field stale: accounts already clean, still drops the field
Root cause hypothesis
The test relies on NEMAR_CONFIG_DIR being set in beforeAll and being captured at module load. src/lib/config.ts reads it at module-level:
// Module-level state in src/lib/config.ts captures NEMAR_CONFIG_DIR at first
// import. Bun caches modules across tests, so we set up the config once,
// import once, and assert all migration scenarios from one snapshot.If ANY earlier test in the same bun test invocation imports src/lib/config.ts (directly or transitively) before this test's beforeAll runs, the module-level capture sees a different (or unset) value. Subsequent tests see stale state.
Adding new test files (e.g. recent additions like backend/test/migrations.test.ts, backend/test/rate-limit-buckets.test.ts) may shift the load order enough to surface this latent bug.
Reproduce locally
bun test test/*.test.ts backend/test/*.test.ts | grep -A2 migrateApiUrlMay not reproduce on every run depending on dirent ordering / runner state.
Fix paths
- Refactor
src/lib/config.tsto readNEMAR_CONFIG_DIRlazily (per function call) instead of at module load. This is the proper fix; removes the test-ordering hazard. - Use Bun's
--bail+ per-file isolation so each test file gets a fresh module cache. Won't fix the root cause but stops cross-contamination. - Drop the import-time singleton in the test by spawning the migration in a subprocess.
(1) is cleanest. The risk on (1) is recomputing the path each call, but the path is from an env var; this is cheap.
Why this is noise, not a regression
- v0.8.14 already shipped to npm and is serving prod (
api.nemar.org/healthreportsversion 0.8.14) - Same code passes on main, fails on dev — diff is only the version field
- The deploy pipeline ran cleanly: tag, npm publish, deploy backend, sync dev
Tracking for v0.8.15 cleanup.
Activity
Lazy read NEMAR_CONFIG_DIR in config store
Merge pull request #490 from nemarOrg/feature/issue-489-config-lazy-init
neuromechanist commentedon May 14, 2026
Merged via #490 to dev (commit f90be01).
Merge pull request #494 from nemarOrg/dev