feat(cli): shared flag-validation helper, migrate 3 fixed scripts, fix scan.mjs (#2270) - #2778
Conversation
…x scan.mjs (santifer#2270) Adds validateFlags(args, knownFlags, usage, { valueFlags }) to lib/cli-flags.mjs, collecting the shape independently hand-rolled in scan-ats-full.mjs (santifer#1633/santifer#1635), reply-watch.mjs (santifer#2743/santifer#2745), and dedup-tracker.mjs (santifer#2744/santifer#2746): reject any unrecognized flag before honoring --help/-h (the ordering CodeRabbit flagged on the last two PRs), value-taking flags never mistake their own value for an unrecognized flag. Migrates all three scripts to the shared helper (behavior-preserving — same error messages, same exit codes, same usage text). Also fixes scan.mjs (santifer#2270): --help and any unrecognized flag used to fall straight through into a full live scan and write to pipeline.md/scan-history.tsv instead of printing usage. Closes santifer#2775. Closes santifer#2270.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe pull request adds shared CLI flag validation and applies it to four scripts. It validates known and value-bearing flags, preserves help handling, rejects unknown flags before side effects, and adds unit and subprocess regression tests. ChangesCLI validation
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related issues
Sequence Diagram(s)sequenceDiagram
participant scan.mjs
participant validateFlags
participant Scan setup
scan.mjs->>validateFlags: Validate command-line arguments
alt Unknown flag
validateFlags-->>scan.mjs: Report error and exit 1
else Help flag
validateFlags-->>scan.mjs: Print usage and exit 0
else Valid arguments
validateFlags-->>scan.mjs: Return validated arguments
scan.mjs->>Scan setup: Continue scan processing
end
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@lib/cli-flags.mjs`:
- Around line 105-107: Update the unknownFlags filtering logic to accept
equals-value syntax only when the base flag belongs to valueFlags; boolean flags
such as --dry-run=1 must remain rejected, while value-bearing flags such as
--since=-5 must be accepted. Add regression coverage for both cases.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 7a8a7848-d1c6-4f11-8468-f0e873b0fca0
📒 Files selected for processing (7)
dedup-tracker.mjslib/cli-flags.mjsreply-watch.mjsscan-ats-full.mjsscan.mjstests/cli-flags.test.mjstests/scan-help-flag.test.mjs
--dry-run=1 was silently accepted (its base flag --dry-run is known),
but every caller checks args.includes('--dry-run') literally, which
is false for the string '--dry-run=1' -- a silent way to run with no
dry-run protection. The equals form is now only valid when the base
flag is registered in valueFlags.
Addresses CodeRabbit finding on PR santifer#2778.
|
The header comment on Verified both halves by running them rather than reading them.
The second pair is the one that matters. On
One consequence beyond this PR. I seeded five Merged. 🚀 |
Closes #2775. Closes #2270.
What this is
Three scripts (
scan-ats-full.mjs#1633/#1635,reply-watch.mjs#2743/#2745,dedup-tracker.mjs#2744/#2746) independently hand-rolled the identical fix for the identical bug: an unrecognized/mistyped CLI flag silently falling through to default/live behavior instead of failing fast.lib/cli-flags.mjsgainsvalidateFlags(args, knownFlags, usage, { valueFlags })— the shape all three converged on, in one place:--prefixed arg not inknownFlagserrors and exits 1 — checked before--help/-his honored (the ordering CodeRabbit flagged as a bug on both fix(reply-watch): reject unrecognized CLI flags instead of treating them as a candidates path #2745 and fix(dedup-tracker): reject unrecognized flags instead of silently live-running #2746:--help --bogusmust still error, not exit 0 having never looked at--bogus).--help/-hprints the caller-supplied usage and exits 0.valueFlagslist (mirroringscan-ats-full.mjs's existing adjacency rule) keeps a value-taking flag's own value — e.g. the-5in--since -5— from being misread as an unrecognized flag.Migration (behavior-preserving)
scan-ats-full.mjs,reply-watch.mjs, anddedup-tracker.mjsnow call the shared helper instead of their own copies. Same error messages, same exit codes, same usage text — this is de-duplication, not a behavior change. (scan-ats-full.mjspicks up one small fix as a side effect: its own--help-before-unknown-flag ordering had the same latent bug the other two were caught on, just never exercised by a test that combined both.)The one genuinely new fix:
scan.mjs(#2270)node scan.mjs --helpnever checked--helpat all — it fell straight through into a full live scan, hitting every configured ATS and writing topipeline.md/scan-history.tsv. Same failure class as the other three, fixed the same way.KNOWN_FLAGSwas built from the script's own existing docblock usage examples;--company/--posted-after/--posted-before/--sinceare registered asvalueFlags(--throttledeliberately isn't — it's only ever read in its bare or--throttle=<ms>forms).Tests
tests/cli-flags.test.mjsextended with direct unit coverage ofvalidateFlags(unrecognized-flag rejection,--help/-h, the ordering case,valueFlagsnegative-number handling) plus subprocess-level coverage for cases that need a real exit code.tests/scan-help-flag.test.mjs: hermetic (CAREER_OPS_PORTALSpointed at a nonexistent path) coverage proving--help,-h, and an unrecognized flag onscan.mjsnever reach the portals-loading step — i.e. never attempt a live scan.node test-all.mjs --quick: 3647 passed, 0 failed.Summary by CodeRabbit
New Features
Bug Fixes
Tests