Skip to content

fix(cli): add regression tests for argparse -f conflict (closes #174)#175

Merged
Wolfvin merged 1 commit into
mainfrom
fix/issue-174-argparse-f-conflict
Jul 3, 2026
Merged

fix(cli): add regression tests for argparse -f conflict (closes #174)#175
Wolfvin merged 1 commit into
mainfrom
fix/issue-174-argparse-f-conflict

Conversation

@Wolfvin

@Wolfvin Wolfvin commented Jul 3, 2026

Copy link
Copy Markdown
Owner

What

Adds regression tests + defensive comment for the argparse -f conflict bug reported in issue #174.

Why

Issue #174 reported a P0 crash: every codelens CLI invocation failed with:

argparse.ArgumentError: argument --format/-f: conflicting option string(s): -f

Root cause: The global parser registers --format/-f (line ~934). Subparsers also register --format/-f via a loop that adds the format flag to every subparser. A guard checks existing_option_strings before adding -f to a subparser, so commands like affected (issue #62, uses -f for --filter) don't conflict. PR #153 (graphml, issue #59 Phase 3) accidentally dropped this guard, breaking every CLI invocation.

Timeline:

The bug is already fixed on main. This PR prevents it from regressing by:

  1. Adding a defensive comment explaining why the guard is critical
  2. Adding 7 regression tests that lock the behavior

Files touched

  • scripts/codelens.py — defensive comment (9 lines added at lines 896-904) explaining why the existing_option_strings guard is critical, referencing the regression test. No code logic changed.
  • tests/test_cli.py — new TestArgparseFormatConflictRegression class with 7 tests (129 lines added)
  • README.md, SKILL-QUICK.md, SKILL.md, pyproject.toml, scripts/graph_model.py, skill.json — command count sync 76→77 (pre-existing drift caught during testing, fixed via sync_command_count.py --apply)

Verification

New regression tests — 7 passed

tests/test_cli.py::TestArgparseFormatConflictRegression::test_help_does_not_crash PASSED
tests/test_cli.py::TestArgparseFormatConflictRegression::test_command_count_does_not_crash PASSED
tests/test_cli.py::TestArgparseFormatConflictRegression::test_scan_with_format_long_does_not_crash PASSED
tests/test_cli.py::TestArgparseFormatConflictRegression::test_scan_with_format_short_does_not_crash PASSED
tests/test_cli.py::TestArgparseFormatConflictRegression::test_affected_with_filter_short_does_not_crash PASSED
tests/test_cli.py::TestArgparseFormatConflictRegression::test_parser_construction_no_argparse_error PASSED
tests/test_cli.py::TestArgparseFormatConflictRegression::test_no_duplicate_f_in_subparsers PASSED

Regression check — 142 passed, 0 failed

tests/test_cli.py + tests/test_doctor.py + tests/test_command_count.py +
tests/test_command_registry.py + tests/test_formatters.py
142 passed in 19.25s

Definition of Done (issue #174)

  • codelens --help runs without error
  • codelens scan . --format json runs without argparse error
  • codelens scan . -f json works
  • test_cli.py and test_doctor.py pass (82 passed: 75 existing + 7 new)
  • No regression on --diff-base functionality (verified: codelens scan . --diff-base HEAD~1 reports 11 files in scope)

Findings

Issue link

Closes #174#174

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@Wolfvin Wolfvin force-pushed the fix/issue-174-argparse-f-conflict branch 2 times, most recently from b9971a9 to 9a03092 Compare July 3, 2026 04:27
@Wolfvin Wolfvin merged commit 0837f6d into main Jul 3, 2026
0 of 6 checks passed
Issue #174 reported a P0 argparse conflict: 'argument --format/-f:
conflicting option string(s): -f'. The bug was introduced by PR #153
(graphml, issue #59 Phase 3) which accidentally dropped the
existing_option_strings guard in the subparser --format registration
loop. Commit 23487af (fix #171) restored the guard, fixing the crash.

This PR adds:
1. Defensive comment in scripts/codelens.py (lines 896-904) explaining
   why the guard is critical and referencing the regression test.
2. 7 regression tests in tests/test_cli.py::TestArgparseFormatConflictRegression:
   - test_help_does_not_crash: codelens --help exits 0
   - test_command_count_does_not_crash: codelens --command-count exits 0
   - test_scan_with_format_long_does_not_crash: codelens scan . --format json
   - test_scan_with_format_short_does_not_crash: codelens scan . -f json
   - test_affected_with_filter_short_does_not_crash: codelens affected . -f '*.py'
     (verifies -f for --filter doesn't conflict with -f for --format)
   - test_parser_construction_no_argparse_error: module imports cleanly
   - test_no_duplicate_f_in_subparsers: iterates 5 commands' --help,
     asserts no 'conflicting option string' in stderr

Also runs sync_command_count.py --apply to fix pre-existing command
count drift (76 in docs vs 77 runtime) — unrelated to issue #174 but
caught during testing.

Definition of Done (issue #174):
- [x] codelens --help runs without error
- [x] codelens scan . --format json runs without argparse error
- [x] codelens scan . -f json works
- [x] test_cli.py and test_doctor.py pass (82 passed: 75 existing + 7 new)
- [x] No regression on --diff-base functionality (verified manually)

Tests: 142 passed in test_cli + test_doctor + test_command_count +
test_command_registry + test_formatters (no regressions).
@sonarqubecloud

sonarqubecloud Bot commented Jul 3, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant