Skip to content

fix: parse the whole value of numeric CLI flags - #177

Merged
dacharyc merged 2 commits into
mainfrom
fix/issue-176-numeric-flag-parsing
Nov 29, 2026
Merged

dacharyc merged 2 commits into
mainfrom
fix/issue-176-numeric-flag-parsing

Conversation

@dacharyc

Copy link
Copy Markdown
Member

Summary

Closes #176.

  • The numeric flags on afdocs check were parsed with parseInt, which reads only the leading digits. --request-delay 500ms became 500, --request-delay 1e3 became 1 and --max-concurrency 2.5 became 2, and the run went ahead with a value the user did not ask for.
  • All 15 numeric flags now go through one helper that converts the whole argument. A value that is not a whole number (including an empty one) fails before the run starts.
  • The error names the flag and quotes the input, for example Error: --request-delay must be a whole number, got "500ms". Every bad flag is reported in the same run.
  • Range errors are unchanged: they are still raised by validateRunnerOptions after flag and config values are merged, and still name the option (maxConcurrency must be between 1 and 100, got 500).

This is a behavior change for anyone passing a value with a trailing unit or a decimal today: those runs now exit with an error instead of using the truncated number.

Test plan

  • npx vitest run (2111 tests pass)
  • New table-driven tests run against each of the 15 flags: 5ms, 2.5 and an empty value are rejected with the flag-named message, and 1e1 is read as 10 rather than 1
  • Type-check, ESLint and Prettier pass
  • Manual run of the built CLI with --request-delay 500ms --max-concurrency 2.5 --pass-threshold 50k prints one error per flag and exits 1; --max-concurrency 500 still produces the existing range error

The numeric flags on afdocs check were parsed with parseInt, which reads
only the leading digits, so "500ms" became 500, "1e3" became 1 and "2.5"
became 2, and the run went ahead with a value the user did not ask for.

Route all 15 flags through one helper that converts the whole argument
and reports anything that is not a whole number by flag name, quoting the
input. Range checks stay with validateRunnerOptions.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The parsed-options test starts real scans that can outlive its wait and affect later tests; the validation spy should return an invalid result to prevent scans from starting.

1 open issue
What changed in this PR

This PR addresses #176 by parsing complete numeric arguments for afdocs check, preventing silently truncated values while preserving range validation after configuration merging.

Changes:

  • Routes all 15 numeric flags through one whole-number parser.
  • Reports invalid inputs by flag name and stops before scanning.
  • Adds table-driven tests for malformed, empty, fractional, and exponential inputs.
File Description
test/​unit/​cli/​check-command.test.ts Expands numeric parsing tests across all 15 flags.
src/​cli/​commands/​check.ts Centralizes numeric parsing and collects flag-specific errors before runner validation.

Review effort: Balanced

Comment thread test/unit/cli/check-command.test.ts Outdated
),
);

const spy = vi.spyOn(validationMod, 'validateRunnerOptions');

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in fba923b

Where 1e1 was a valid value, the validation spy let a real scan start, and
with the default 200 ms request delay it could outlive the test's 100 ms
wait and write output or set the exit code during a later test. Have the
spy report the options invalid so the command stops before scanning.
@dacharyc
dacharyc merged commit 7483094 into main Nov 29, 2026
2 checks passed
@dacharyc
dacharyc deleted the fix/issue-176-numeric-flag-parsing branch November 29, 2026 20:49
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.

Numeric CLI flags accept partial values such as 1e4 and 500ms

2 participants