Repository navigation
fix: parse the whole value of numeric CLI flags - #177
Merged
Merged
Conversation
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.
There was a problem hiding this comment.
🟡 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
| ), | ||
| ); | ||
|
|
||
| const spy = vi.spyOn(validationMod, 'validateRunnerOptions'); |
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.
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.

Summary
Closes #176.
afdocs checkwere parsed withparseInt, which reads only the leading digits.--request-delay 500msbecame 500,--request-delay 1e3became 1 and--max-concurrency 2.5became 2, and the run went ahead with a value the user did not ask for.Error: --request-delay must be a whole number, got "500ms". Every bad flag is reported in the same run.validateRunnerOptionsafter 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)5ms,2.5and an empty value are rejected with the flag-named message, and1e1is read as 10 rather than 1--request-delay 500ms --max-concurrency 2.5 --pass-threshold 50kprints one error per flag and exits 1;--max-concurrency 500still produces the existing range error