Repository navigation
fix(import): reject a non-numeric --max-repos instead of passing NaN - #1781
Conversation
parseInt('abc') gave NaN, which importFromOrg's listing loop (while len < NaN) never entered, so the run finished with an empty whitelist and no error. Validate like --max-files: a positive integer or an error.
|
No findings in the scoped diff. The PR description provides sufficient testing: focused unit tests, related import tests, typecheck, lint, and a representative real-CLI run after build showing invalid No code was run, built, or installed during this review. |
SaulMoro
left a comment
There was a problem hiding this comment.
This was generated by AI during triage.
Approving. parseInt('abc') gave NaN, and while (repos.length < NaN) never runs, so import --from-org <org> --max-repos abc ended with an empty whitelist and exit 0. parsePositiveInt uses the same contract as the existing parseMaxFiles (Number, an integer of 1 or more, otherwise "<flag> must be a positive integer"), so 0, -3 and 1.5 are refused too. The default of 200 is unchanged. depth is not an import flag, and import-from-repo.ts:64 already required a positive integer there, so routing it through the same helper only moves the refusal earlier. The new non-zero exit replaces a silent no-op, so it is the fix, not a breaking change.
The new tests go through importCmd, and the description has a built-CLI run of the failing input.
[P3 nit] parseMaxFiles and parsePositiveInt now share their body. parseMaxFiles could be the helper with --max-files and no default, if you want one copy. Optional.
Merge risk: low
Alignment: good
- The fix covers the reported input. The only other change is
depth, which the description explains.
Impact: small
- One option parser of
import. A valid value behaves as before.
Verification: good
- The description shows the four refused inputs red before the fix, and a built-CLI run of
--max-repos abc.
Rollback cost: low
- A revert restores the old parse.
Error detection: good
- A bad value now fails with a message naming the flag, instead of importing nothing.
CI review: no findings, and we agree. I'll merge once CI is green at this head.
teamai import --from-org <org> --max-repos abcparsed the cap withparseInt, givingNaN. The org listing loops (while (repos.length < maxRepos)) never run withNaN, so the command ended with an empty whitelist and no error.Fix: a small
parsePositiveInthelper insrc/import.ts, same contract as the existingparseMaxFiles(positive integer or... must be a positive integer). Used for--max-repos(default 200 unchanged); the--from-repobranch'sdepthsetting (default 1, not exposed as animportflag today) goes through the same helper so it cannot becomeNaNeither.Test: new
src/__tests__/import-numeric-options.test.ts(valid value, default, andabc/0/-3/1.5rejected without callingimportFromOrg). Red before the fix (4 failed), green after (6 passed).import-organdimport-dirtests still pass;npm run typecheckand oxlint clean.Real CLI (after
npm run build):node dist/index.js import --from-org acme --max-repos abcprints✖ Import from organization [FAILED: --max-repos must be a positive integer]and exits non-zero.This change was prepared with AI assistance (Claude Code) and reviewed before submission.