Skip to content

feat(cli): runtime Node-version preflight guard (#734) - #736

Merged
admarble merged 2 commits into
mainfrom
feature/734-feat-cli-runtime-node-version-preflight-guard-clea
Jun 21, 2026
Merged

admarble merged 2 commits into
mainfrom
feature/734-feat-cli-runtime-node-version-preflight-guard-clea

Conversation

@admarble

Copy link
Copy Markdown
Contributor

Summary

  • Add a runtime Node-version preflight guard at CLI startup: when the running Node is below the engines.node floor, print a clear message (current vs required + fnm/nvm/nodejs.org upgrade paths) and exit non-zero before any command logic runs (including sequant serve).
  • Converts an ignorable EBADENGINE warning + later opaque crash into one friendly, immediate message.
  • Floor is derived from package.json engines.node (single source of truth, no hardcoded literal); comparison reuses the existing compareVersions helper — 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 it parseInt(">=22") → NaN → 0 would wrongly pass Node 20). Returns null when 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 → getPackageMeta reads version + engines.node in one package.json walk-up; assertNodeVersion(engineFloor) invoked near the existing home-stray guard.

Pre-PR AC Verification

AC Description Status Evidence
AC-1 Sub-floor → message (current vs required + upgrade path), exit non-zero before command logic ✅ assertNodeVersion in bin/cli.ts before home-stray block; verified end-to-end (exit 1 + message)
AC-2 At/above floor → zero behavior change, exit 0 ✅ node dist/bin/cli.js --version/--help → no added output, exit 0
AC-3 Floor derived from engines.node, not hardcoded ✅ getPackageMeta returns pkg.engines?.node; no 22.12.0 literal in guard logic
AC-4 Reuses compareVersions; no new runtime dep ✅ no semver import/dep added
AC-5 Pure fn unit-tested across boundaries (20.x/22.11/22.12.0/22.12.1/24.x) ✅ getNodeVersionError table tests + range-strip test
AC-6 Guard in version-check.ts, invoked from bin/cli.ts, built-in globals only ✅ placement + globals-only confirmed

Test plan

  • npm run build — passes
  • npm run lint — passes (0 warnings)
  • npx vitest run src/lib/version-check.test.ts — 66 passed
  • End-to-end: assertNodeVersion('>=999.0.0') prints message + exits 1; current Node passes silently

Closes #734

🤖 Generated with Claude Code

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).
@admarble

Copy link
Copy Markdown
Contributor Author

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 cli.ts's body, after all top-of-file imports. Since ESM evaluates imports first, a dependency tripping a Node-22-only API at module-load time on old Node would crash the import with an opaque stack trace before the guard ran — the exact failure mode the feature replaces. Fix: moved the guard into bin/preflight.ts, now the first (side-effecting) import in cli.ts. ESM depth-first source-order evaluation runs it before commander / chalk / the agent SDK / command modules. The only earlier-evaluated modules 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. bin/preflight.test.ts locks in the ordering so a reorder can't silently reopen the window.

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 node-floor-guard CI job — builds on Node 22, switches the runtime to Node 20, runs the prebuilt CLI, and asserts it prints the guard message and exits non-zero. ✅ Passed on real Node 20 in this run, which also proves the import-time ordering fix end-to-end.

All checks green (build (22.x), node-floor-guard, typecheck, validate-skills, validate-plugin). Verdict stands: READY_FOR_MERGE.

@admarble
admarble merged commit f4550f1 into main Jun 21, 2026
5 checks passed
@admarble
admarble deleted the feature/734-feat-cli-runtime-node-version-preflight-guard-clea branch June 21, 2026 04:09
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.

feat(cli): runtime Node-version preflight guard (clear message instead of opaque crash below engines floor)

1 participant