Skip to content

fix(cli): read package.json version lazily in handleInfo - #165

Merged
santi698 merged 1 commit into
mainfrom
tssdk-fix-handleinfo-package-json
Jul 29, 2026
Merged

fix(cli): read package.json version lazily in handleInfo#165
santi698 merged 1 commit into
mainfrom
tssdk-fix-handleinfo-package-json

Conversation

@santi698

Copy link
Copy Markdown
Collaborator

Problem

handleInfo() read packages/cli/package.json once at module load time into a module-level constant. This caused the release-please release PR to fail: release-please bumps the version in package.json, but since the CLI's dist output baked in the version read before that bump (at the previous build), the expected vs. actual version mismatched.

Fix

Move the readFileSync call inside handleInfo() so the version is read fresh from disk on every call, always reflecting the current package.json.

Also included

Added a "Mocking Scope" section to docs/TESTING_CONVENTION.md codifying a convention surfaced while fixing the corresponding test: prefer vi.mock('module') (auto-mock) plus per-test vi.mocked(fx).mockReturnValue(...) over inline vi.mock('module', () => ({...})) factories, and keep persistent mock defaults in beforeEach (relevant once mockReset is enabled).

Testing

  • npm run test --workspace @aignostics/cli -- cli-functions.spec.ts — 82/82 passing
  • npm run lint:cli — 0 warnings/errors
  • npm run format:check — passing

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

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Impacted file tree graph

@@           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           
Flag Coverage Δ
unittests 93.36% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
packages/cli/src/cli-functions.ts 99.65% <100.00%> (ø)

Impacted file tree graph

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sonarqubecloud

Copy link
Copy Markdown

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),
};
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks is a little bit cursed 🙈

@santi698
santi698 merged commit b6fe81a into main Jul 29, 2026
16 checks passed
@santi698
santi698 deleted the tssdk-fix-handleinfo-package-json branch July 29, 2026 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants