fix(cli): read package.json version lazily in handleInfo - #165
Merged
Conversation
Reading package.json at module load time via readFileSync baked the version into a module-level constant, so release-please's version bump commit needed a rebuild before handleInfo would report the new version, causing the release PR to fail its version check. Move the read inside handleInfo() so it reflects the on-disk package.json at call time. Also documents a mocking-scope convention: prefer describe/test-local mocks and vi.mocked(...) overrides over module-level mock factories.
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## main #165 +/- ##
=======================================
Coverage 93.36% 93.36%
=======================================
Files 15 15
Lines 2488 2488
Branches 296 296
=======================================
Hits 2323 2323
Misses 163 163
Partials 2 2
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
mk0x9
reviewed
Jul 29, 2026
Comment on lines
+108
to
+117
| // cli-functions.ts reads package.json synchronously via fs.readFileSync inside | ||
| // handleInfo(). ESM named exports aren't spy-able directly, so mock the module, | ||
| // defaulting to the real implementation so other tests are unaffected; | ||
| vi.mock("fs", async (importOriginal) => { | ||
| const actual = await importOriginal<typeof import("fs")>(); | ||
| return { | ||
| ...actual, | ||
| readFileSync: vi.fn(actual.readFileSync), | ||
| }; | ||
| }); |
Contributor
There was a problem hiding this comment.
This looks is a little bit cursed 🙈
mk0x9
approved these changes
Jul 29, 2026
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.



Problem
handleInfo()readpackages/cli/package.jsononce at module load time into a module-level constant. This caused the release-please release PR to fail: release-please bumps the version inpackage.json, but since the CLI'sdistoutput baked in the version read before that bump (at the previous build), the expected vs. actual version mismatched.Fix
Move the
readFileSynccall insidehandleInfo()so the version is read fresh from disk on every call, always reflecting the currentpackage.json.Also included
Added a "Mocking Scope" section to
docs/TESTING_CONVENTION.mdcodifying a convention surfaced while fixing the corresponding test: prefervi.mock('module')(auto-mock) plus per-testvi.mocked(fx).mockReturnValue(...)over inlinevi.mock('module', () => ({...}))factories, and keep persistent mock defaults inbeforeEach(relevant oncemockResetis enabled).Testing
npm run test --workspace @aignostics/cli -- cli-functions.spec.ts— 82/82 passingnpm run lint:cli— 0 warnings/errorsnpm run format:check— passing