Repository navigation
fix: lazy read NEMAR_CONFIG_DIR in config store (#489) - #490
Merged
Merged
Conversation
Drop the module-load capture of NEMAR_CONFIG_DIR (and the eager Conf instance) so test ordering no longer decides which config dir wins. The new getStore() resolves the env var on each call, caches the Conf instance keyed by dir, and rebuilds it (rerunning structural migrations once per dir) when the env flips between calls. Production: first config accessor triggers migration before returning, preserving the old startup behavior. Tests: update config-migrate-api-url test 1 to call migrateApiUrl() explicitly so it runs against the test's NEMAR_CONFIG_DIR regardless of whether another test file imported src/lib/config.ts first. Fixes #489
📦 Package PreviewYour package is ready to test! bun install -g nemar-cli@PR490Version: 🤖 Updated on each push. |
- update-check.ts: same module-load env capture as the old config.ts;
swap CONFIG_DIR/CACHE_FILE constants for getConfigDir()/getCacheFile()
helpers so tests setting NEMAR_CONFIG_DIR after import always win.
- config.ts:
- Clarify the re-entrancy comment on the migration block. The cache
short-circuit (cachedStore && cachedStoreDir === dir) is the actual
guard against recursion; migrationsRunForDirs covers the separate
dir-flip-and-revisit case.
- setConfig: read activeAccount/accounts directly off the cached
Conf instance instead of going back through getActiveAccountName /
getAccountsMap. Same behavior, fewer cache lookups.
- Add __resetStoreCacheForTesting() so tests can force a fresh init
for the same dir (bun --rerun-each, isolated retests).
- test/config-migrate-api-url.test.ts: rewrite the stale test 3
comment. The 'previous tests already locked NEMAR_CONFIG_DIR' line
described the old eager-capture behavior and was misleading.
Review findings: #490
Contributor
Author
Review triage (from
|
| Severity | Finding | Action |
|---|---|---|
| Important | Stale comment in test 3 (test/config-migrate-api-url.test.ts:122-125) described old locking | Fixed in fbf13c3 |
| Important | Re-entrancy comment at src/lib/config.ts:201-203 mis-attributes the guard | Fixed in fbf13c3 |
| Important | src/lib/update-check.ts:23 has the same eager NEMAR_CONFIG_DIR capture anti-pattern | Fixed in fbf13c3 (lazy getConfigDir()/getCacheFile()) |
| Suggestion | setConfig() calls getStore() 3x redundantly | Fixed in fbf13c3 (one cache read, derive locally) |
| Suggestion | No __resetForTesting() hook for --rerun-each | Added __resetStoreCacheForTesting() in fbf13c3 |
| Suggestion | Test plan only lists paired-file runs, not full suite | CI's unit-test-all covers the full suite; no code change needed |
| Suggestion | No dedicated test for migrateConfig() through the lazy path | Covered transitively by auth/account tests; skipping as a separate test would be redundant |
| Pre-existing | new Conf() error path not handled | Out of scope for this PR (same in old code); file separately if it becomes a real failure mode |
This was referenced May 14, 2026
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
src/lib/config.tsno longer capturesNEMAR_CONFIG_DIRat module load. A newgetStore()resolves the env var on each call, caches the Conf instance by dir, and rebuilds + reruns structural migrations once when the env flips between calls.migrateConfig()/migrateApiUrl()are now triggered lazily on first config access. Production behavior is unchanged: the first command-handler call (e.g.getConfig()) triggers the migration before returning.test/config-migrate-api-url.test.tstest 1 callsmigrateApiUrl()explicitly so it runs against the test'sNEMAR_CONFIG_DIRregardless of which test file importedsrc/lib/config.tsfirst.Why
Module-load capture of
NEMAR_CONFIG_DIRmadebun testresults depend on file load order. If any earlier test importedsrc/lib/config.tsbeforeconfig-migrate-api-url.test.ts'sbeforeAllset the env var, the Conf instance was already pinned to the wrong dir and the migration tests asserted against a file the module never read.Closes #489.
Test plan
bun test test/config-migrate-api-url.test.ts(3/3 pass)bun test test/publish-progress.test.ts test/config-migrate-api-url.test.ts(config loaded first, still pass)bun test test/auth-status.test.ts test/config-migrate-api-url.test.ts(same, pass)bun run build— greenbun dist/index.js auth statusreads config and lists accounts