Skip to content

fix(cli): reject unknown --batch values in ocr scan - #2009

Open
Walternater wants to merge 1 commit into
alibaba:mainfrom
Walternater:feat/scan-batch-validation
Open

Walternater wants to merge 1 commit into
alibaba:mainfrom
Walternater:feat/scan-batch-validation

Conversation

@Walternater

Copy link
Copy Markdown
Contributor

Fixes #2008

What

ocr scan --batch now rejects values outside the documented set (none, by-language, by-directory) instead of silently discarding them:

$ ocr scan --batch by-languag --preview        # before
Preview: 1 file(s) changed  |  +2  -0          # typo silently ignored

$ ocr scan --batch by-languag --preview        # after
Error: invalid --batch value "by-languag": must be 'none', 'by-language', or 'by-directory'

This matches the command's existing treatment of --format (invalid --format value %q: must be 'text', 'json', or 'sarif').

How

  • validateScanOptions (cmd/opencodereview/shared_flags.go) calls a new validateBatchStrategy, which trims and lower-cases the value (so By-Directory still works) and errors otherwise. Empty stays valid: it means "use the template default".
  • The comment on the opts.batch override in cmd/opencodereview/scan_cmd.go is updated accordingly.
  • parseBatchStrategy in internal/scan/batch.go is unchanged: its lenient fallback is documented safe v1 behavior for the template-level BATCH_STRATEGY, where arbitrary strings can also arrive from a user-supplied scan_template.json. Only the CLI surface — where the flag help and shell completion advertise exactly three values — fails fast.

Tests

  • TestParseScanFlags_InvalidBatch — bogus, by-languag, language, directory all error, and the message names --batch.
  • TestParseScanFlags_NormalizedBatch — the three valid values, mixed case/whitespace normalization, and empty passthrough.
  • Full suite: go test ./... passes; make check passes; make english-check passes.

AI/LLM disclosure

This PR was prepared with AI assistance (DeepSeek Harness agent, model group/smart-split): code exploration, patch drafting, and test generation. Every changed line was reviewed and verified by running the built CLI locally on macOS (Apple Silicon) against commit a74bcbb.

validateScanOptions now validates the --batch strategy the same way it
already validates --format: values outside none | by-language |
by-directory fail fast with an error naming the flag. Previously a typo
was silently discarded and the scan ran unbatched, because
parseBatchStrategy falls back to BatchNone for unknown input. The
lenient template-level BATCH_STRATEGY fallback is unchanged; only the
CLI surface rejects typos early.
@github-actions

Copy link
Copy Markdown
Contributor

✅ OpenCodeReview: Review complete: 0 finding(s) across 2 selected item(s).

This branch has not been deployed

No deployments
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.

ocr scan --batch silently ignores misspelled values

1 participant