Skip to content

fix(cli): reject out-of-range numeric options with exit code 2 - #21

Merged
royalpinto007 merged 2 commits into
AgentPostmortem:mainfrom
sharadvc:fix/cli-numeric-validation
Sep 18, 2026
Merged

royalpinto007 merged 2 commits into
AgentPostmortem:mainfrom
sharadvc:fix/cli-numeric-validation

Conversation

@sharadvc

Copy link
Copy Markdown
Contributor

What

Closes #8. CLI numeric options (e.g. --top, --limit, --tail) accepted negative, NaN, and out-of-range values, producing garbage reports or silent truncation.

Changes

  • src/ctxlens/cli.py: validate numeric option values up front; reject invalid ranges with a clean error and exit code 2.
  • tests/test_cli.py: regression cases for negative / NaN / out-of-range values.

Checklist

Authored with AI assistance; rebased onto current main, tests re-run.

--top, --tool-result-cap, --tool-def-budget and --fail-over-ratio accepted
negative, NaN and out-of-range values and produced garbage output. Add
validation callbacks so invalid values exit with code 2 and a clear
message instead of silently mis-running.

Closes AgentPostmortem#8
@sharadvc
sharadvc force-pushed the fix/cli-numeric-validation branch from 73f8584 to c9bbb16 Compare September 17, 2026 03:01
@royalpinto007

Copy link
Copy Markdown
Member

Production code is correct (exit 2 fires). Only the new test is at fault: with color enabled (as in CI) Rich highlights the flag as ANSI fragments, so literal --top never appears contiguously. Please strip ANSI codes (re.sub(r'\x1b[[0-9;]*m', '', result.stderr)) before asserting the flag name.

Rich 15 renders the error panel with ANSI styling, splitting flag names
(e.g. '--top' becomes '-[esc]-top'), so substring-matching the option
flag in stderr is unreliable. Assert on the plain-text reason message
from the callback instead.
@royalpinto007
royalpinto007 merged commit c5081ca into AgentPostmortem:main Sep 18, 2026
3 checks passed
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.

CLI numeric options accept negative/NaN/out-of-range values

2 participants