Repository navigation
Conversation
Add a startup guard that fails fast with a clear message when the running Node is below the engines.node floor, instead of letting an ignorable EBADENGINE warning lead to a later opaque crash. - getNodeVersionError(current, floor): pure, side-effect-free message-or-null; strips the >= range operator before comparing, reuses compareVersions (no semver dep), returns null when floor is missing/unparseable. - assertNodeVersion(floor): thin shell that prints + process.exit(1); uses only built-in globals so it runs on the old Node it rejects. - bin/cli.ts: getVersion -> getPackageMeta reads version + engines.node in one walk-up (single source of truth); assertNodeVersion called near the home-stray guard, before any command logic. - Boundary unit tests (20.x/22.11/22.12.0/22.12.1/24.x) + range-strip + exit behavior with process.exit mocked. Closes #734 Entire-Checkpoint: 853fc704b76f
…overage (#734) QA on PR #736 surfaced two residual gaps in the runtime Node-version guard: 1. Import-time crash window: the guard ran in cli.ts's body, *after* all top-of-file imports. ESM evaluates imports first, so a dependency that tripped a Node-22-only API at module-load time on old Node would crash the import with an opaque stack trace before the guard ever ran — the exact failure the feature exists to replace. Move the guard into bin/preflight.ts and make it the first (side-effecting) import in cli.ts. ESM depth-first source-order evaluation guarantees it runs before commander / chalk / the agent SDK / command modules. The only modules evaluated earlier are Node built-ins + the first-party version-check→stacks→fs chain (built-ins only), so it stays self-safe on the old Node it rejects. Pure logic stays in version-check.ts; floor still derived from engines.node (single source). 2. No real sub-floor coverage: CI is Node-22-only, so the guard's fail path was never exercised on the old Node it targets. Add a node-floor-guard CI job: build on Node 22, switch the runtime to Node 20, run the prebuilt CLI, and assert it prints the guard message and exits non-zero before reaching command logic — proving both the fail path and the import-time ordering on real 20.x. Adds bin/preflight.test.ts to lock in the import ordering (a reorder would silently reopen the window while build + pure-fn tests still pass).
Follow-up: both QA-surfaced gaps fixed (commit 2be9073)QA flagged two residual gaps (both within the original AC scope, but worth closing): 1. Import-time crash window — the guard ran in 2. No real sub-floor coverage — CI was Node-22-only, so the guard's fail path was never run on the old Node it targets. Fix: added a All checks green ( |
Summary
engines.nodefloor, print a clear message (current vs required + fnm/nvm/nodejs.org upgrade paths) and exit non-zero before any command logic runs (includingsequant serve).EBADENGINEwarning + later opaque crash into one friendly, immediate message.package.jsonengines.node(single source of truth, no hardcoded literal); comparison reuses the existingcompareVersionshelper — zero new dependencies.Implementation
src/lib/version-check.ts:getNodeVersionError(current, floor)— pure, side-effect-free, returns message-or-null. Strips the>=range operator before comparing (the load-bearing detail — without itparseInt(">=22")→NaN→0would wrongly pass Node 20). Returnsnullwhen the floor is missing/unparseable (skip guard, never crash on a metadata problem).assertNodeVersion(floor)— thin shell that prints +process.exit(1); uses only built-in globals (process.version,console,process.exit) so it runs on the old Node it rejects.bin/cli.ts:getVersion→getPackageMetareadsversion+engines.nodein one package.json walk-up;assertNodeVersion(engineFloor)invoked near the existing home-stray guard.Pre-PR AC Verification
assertNodeVersioninbin/cli.tsbefore home-stray block; verified end-to-end (exit 1 + message)node dist/bin/cli.js --version/--help→ no added output, exit 0engines.node, not hardcodedgetPackageMetareturnspkg.engines?.node; no22.12.0literal in guard logiccompareVersions; no new runtime depsemverimport/dep addedgetNodeVersionErrortable tests + range-strip testversion-check.ts, invoked frombin/cli.ts, built-in globals onlyTest plan
npm run build— passesnpm run lint— passes (0 warnings)npx vitest run src/lib/version-check.test.ts— 66 passedassertNodeVersion('>=999.0.0')prints message + exits 1; current Node passes silentlyCloses #734
🤖 Generated with Claude Code