fix(healthz): read version from package.json (not npm_package_version)#134
Merged
Merged
Conversation
`process.env.npm_package_version` is only set when the process is
launched via an npm script. The repo Dockerfile (line 80)
`CMD ["node", "server.js"]` — no npm wrapper — so in production
deployments `/healthz` always returned `version: "unknown"`.
Operators trying to verify a rolling deploy ("is the new pod at
v1.2.3 yet?") got no signal.
Read `version` from `package.json` once at module load. The lookup
is wrapped in try/catch so a broken install can't take /healthz
down — the endpoint is operationally critical and must come up
even when the manifest is missing.
New test asserts `body.version === require('../../package.json').version`
and that the fallback `'unknown'` string never appears on a healthy
install.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Closes #133.
Summary
process.env.npm_package_versionis only set when the process is launched via an npm script. The repo Dockerfile (line 80) launches viaCMD ["node", "server.js"]— no npm wrapper — so in production deployments/healthzalways returnedversion: "unknown". Operators verifying a rolling deploy ("is the new pod at v1.2.3 yet?") got no signal.Read
versionfrompackage.jsononce at module load. Wrapped in try/catch so a broken install can't take/healthzdown — the endpoint is operationally critical and must come up even when the manifest is missing.Test plan
npm run lint— cleannpm test— 492 passed (was 491 + new regression test), 15 skippedbody.version === require('../../package.json').versionand that the'unknown'fallback never appears on a healthy installProudly Made in Nebraska. Go Big Red! 🌽 https://xkcd.com/2347/