Skip to content

fix(#845): harden the eight numeric CLI options #833 left on bare parseInt - #855

Merged
admarble merged 3 commits into
mainfrom
feature/845-8-numeric-cli-options-still-use-bare-parseint-833-
Jul 29, 2026
Merged

admarble merged 3 commits into
mainfrom
feature/845-8-numeric-cli-options-still-use-bare-parseint-833-

Conversation

@admarble

Copy link
Copy Markdown
Contributor

Summary

Extends #833's parseWholeNumber guard to the eight numeric CLI options PR #836 left on a bare parseInt. Those eight were justified as safe by reasoning only about NaN — but the failure #833 is named for is the unit-suffix misparse (parseInt("30m", 10) === 30), which none of them handled.

Demonstrated end-to-end against the build before this change:

  • logs --last 30m rendered 30 runs; logs --issue 817x filtered to 817; status 999999x was read as 999999
  • dashboard --port 3100x / serve --port 3199x bound the truncated port silently (the PR called these "fails loudly" — true for NaN, false for the misparse)
  • --max-age failed open: state-cleanup.ts:181 gates on a truthy value, so NaN safely skipped the age rule, but --max-age 1w parsed to a truthy 1, silently narrowing a 7-day retention to 1 day and deleting more than asked

All eight sites now use the same parseWholeNumber guard, coerced during commander's parse phase so a rejection exits before any server binds or cleanup runs. --wait uses min: 0 (not parsePositiveSeconds) because prompt.ts:259 reads --wait 0 as "don't block"; the rest use min: 1.

Pre-PR AC Verification

AC Description Status Evidence
AC-1 All eight options reject a unit-suffixed value with #833's message shape ✅ Implemented bin/cli.ts (8 sites); numeric-flags.integration.test.ts REJECTED_845 (all 8, spawns real CLI); cli-flags.test.ts per-flag table
AC-2 --max-age rejects 1w rather than narrowing retention to 1 day ✅ Implemented Both status/state clean --max-age rejected before cleanup; mutation-checked (reverting reaches "🧹 Cleaning up…" and the test fails)
AC-3 Both port flags reject 3100x instead of binding the truncated port ✅ Implemented dashboard/serve --port integration cases
AC-4 Legitimate boundary values continue to parse ✅ Implemented --wait 0 (min:0) accepted end-to-end; per-flag boundary table (123, 7, 30, 817, 3100, 3199)

Test plan

  • npm run build — passes
  • npm run lint — passes (0 warnings)
  • cli-flags.test.ts + numeric-flags.integration.test.ts — 66 passed
  • Mutation check: revert --max-age coercion → AC-2 integration test fails on the fail-open path
  • End-to-end reproductions from the issue body run against the real build (all rejected; boundaries preserved)

Note: src/commands/__tests__/prompt-wait.test.ts has one failing test (returns 0 and prints the reply…) — verified pre-existing by reproducing it on the pristine tree (stash) with none of this PR's changes. It calls promptCommand() directly and never exercises CLI coercion; the failure is a setTimeout-race ENOENT on inbox.jsonl, unrelated to #845.

Closes #845

admarble added 2 commits July 29, 2026 01:50
…d of swallowing it

Extract the frozen provisioning install into installWorktreeDeps, which
mirrors reinstallIfLockfileChanged's status check: on a non-zero exit it
warns (chalk.yellow) naming the resolved command so the user can rerun it,
and warn-and-continues rather than aborting. Previously ensureWorktree ran
the install and discarded the result, so after #816/#826 switched to a
frozen npm ci a repo with no/stale lockfile yielded a silently
dependency-less worktree whose breakage only surfaced later as a confusing
phase error.

Adds a mocked unit test (no lockfile => npm ci exit 1) asserting the
failure is reported, the stderr is surfaced, and the command is named even
when stderr is empty.

Entire-Checkpoint: 8e84f0faf466
…seInt

#833 hardened 10 numeric flags with parseWholeNumber but left eight on a
bare parseInt, justified in PR #836's AC-6 table by reasoning only about
NaN. The unit-suffix misparse the guard exists for (parseInt("30m",10) is
30) was never addressed, so `logs --last 30m` read 30, the two --port flags
bound the truncated port silently, and `--max-age 1w` failed *open* —
state-cleanup.ts:181 gates on a truthy value, so 1w narrowed a 7-day
retention to 1 day and deleted more than asked.

All eight sites (status [issue], status --max-age, prompt --wait,
logs --last, logs --issue, dashboard --port, serve --port,
state clean --max-age) now use the same parseWholeNumber guard, coerced
during commander's parse phase so a rejection exits before any server
binds or cleanup runs. --wait uses min:0 (prompt.ts:259 reads 0 as
"don't block"); the rest use min:1.

Tests: extend numeric-flags.integration.test.ts with the issue's eight
end-to-end reproductions (proves wiring, not just the coercion) plus the
--wait 0 boundary; add a data-driven per-flag table in cli-flags.test.ts
pinning reject-suffix (AC-1) and preserve-boundary (AC-4). Mutation-checked
the --max-age case: reverting the coercion reaches the fail-open cleanup
and the test fails.

Entire-Checkpoint: 8a29dcd37f14
…-cli-options-still-use-bare-parseint-833-

# Conflicts:
#	CHANGELOG.md
@admarble
admarble merged commit 60e0061 into main Jul 29, 2026
5 checks passed
@admarble
admarble deleted the feature/845-8-numeric-cli-options-still-use-bare-parseint-833- branch July 29, 2026 14:01
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.

8 numeric CLI options still use bare parseInt — #833's unit-suffix misparse is unaddressed (--max-age fails open)

1 participant