Skip to content

🔥 QD-14791 QD-14813 Remove implicit scan injection from CLI dispatch - #962

Open
Anna Zhukova (bindreams) wants to merge 2 commits into
mainfrom
azhukova/QD-14791
Open

🔥 QD-14791 QD-14813 Remove implicit scan injection from CLI dispatch#962
Anna Zhukova (bindreams) wants to merge 2 commits into
mainfrom
azhukova/QD-14791

Conversation

@bindreams

@bindreams Anna Zhukova (bindreams) commented May 27, 2026

Copy link
Copy Markdown
Collaborator

What

Removes the setDefaultCommandIfNeeded layer in internal/cmd/root.go that silently rewrote qodana <args> to qodana scan <args> when args didn't match a hand-rolled list of known invocations. After this PR, cobra's standard subcommand resolution handles every invocation.

This is a deliberate, product-approved removal — broader than a narrow patch to QD-14791 alone.

Why

The injection was added in November 2023 to make qodana -i . work as a shorthand for qodana scan -i .. It has produced a recurring class of UX bugs over 2+ years:

  • QD-9907 (2024) — qodana completion ran scan. Patched narrowly.
  • QD-14791 (2026) — qodana help completion runs scan. Same root cause as QD-9907; the 2024 patch didn't generalize. This is the bug the PR fixes.
  • QD-5338 (2023) — same UX class, qodana pull auto-promoted to scan. Won't-fix.
  • Latent (unreported, fixed incidentally): cobra's hidden __complete / __completeNoDesc (used by shell completion scripts at every Tab press) were silently misrouted to scan.
  • Latent (unreported, fixed incidentally): qodana -i scan was misread because the old isCommandRequested scanned the entire argv for command names.

The dispatch layer saved five keystrokes and has cost the team multiple bug reports. Time to retire it.

Tickets

  • Fixes QD-14791qodana help completion runs scan.
  • Resolves QD-14813 — "Remove implicit scan injection from CLI dispatch". Migration guide lives there.

Behavior changes (breaking)

Invocation Before After
qodana help completion starts scan (QD-14791) shows completion help
qodana <Tab> (shell completion) silently runs scan works correctly
qodana starts scan in CWD shows root help
qodana -i . runs scan with -i . error: unknown flag -i
qodana --linter qodana-jvm runs scan with linter error: unknown flag
qodana scan -i . unchanged unchanged
qodana <known-subcommand> [args] unchanged unchanged
qodana -v / --version / -h / --help unchanged unchanged

See QD-14813 for the full table and migration cookbook (TL;DR: anywhere you had qodana <flags>, write qodana scan <flags>).

Diff

  • internal/cmd/root.go: −32 lines. Deletes isHelpOrVersion, isCompletionRequested, isCommandRequested, setDefaultCommandIfNeeded, the call site in Execute(), and the slices import. Execute() collapses to the warning + update check + rootCommand.Execute().
  • internal/cmd/cmd_test.go: refactor. Deletes the four obsolete helper tests. Adds dispatchTestRoot() test helper and six dispatch tests covering the QD-14791 bug, the QD-9907 prior-art path, cobra's hidden __complete, bare invocation, unknown subcommand, and the latent scan flag-value collision.

TDD trail

Two commits, deliberately structured to make TDD visible:

  1. da649ecd adds TestQD14791HelpCompletionDispatch with an explicit setDefaultCommandIfNeeded(...) call that demonstrates the bug. The test fails on this commit (scan runs instead of help dispatch).
  2. 1bc21cb3 deletes the dispatch helpers and the call site. The keystone test loses its setDefaultCommandIfNeeded line (now undefined) and passes against cobra-native dispatch. Adds five additional post-removal dispatch tests.

CI on commit 1 in isolation would surface the failing test (the regression the fix addresses). CI on the branch HEAD (commit 2) is green.

Test plan

  • go test ./internal/cmd/... — all tests pass.
  • Build & manual smoke against the local binary, every row in the behavior table above.
  • CI: all 14 substantive gates green (lint, codeql, goreleaser, install scripts, test matrix across macos/ubuntu/windows × docker/podman/none).

@github-actions

Copy link
Copy Markdown

Qodana for Go

115 new problems were found

Inspection name Severity Problems
Check dependency licenses 🔴 Failure 5
Vulnerable declared dependency 🔴 Failure 1
Check GO source code coverage 🔶 Warning 52
Unhandled error 🔶 Warning 13
Potential resource leak 🔶 Warning 6
Check dependency licenses 🔶 Warning 4
Deprecated element 🔶 Warning 4
Imported package name as a name identifier 🔶 Warning 1
Reserved word used as name 🔶 Warning 1
Vulnerable declared dependency 🔶 Warning 1
Unsorted imports ◽️ Notice 13
Name starts with a package name ◽️ Notice 8
Empty slice declared using a literal ◽️ Notice 3
Comment of exported element starts with the incorrect name ◽️ Notice 1
Redundant type conversion ◽️ Notice 1
Vulnerable declared dependency ◽️ Notice 1
@@ Code coverage @@
+ 65% total lines covered
10639 lines analyzed, 6935 lines covered
# Calculated according to the filters of your coverage tool

☁️ View the detailed Qodana report

Contact Qodana team

Contact us at qodana-support@jetbrains.com

@bindreams Anna Zhukova (bindreams) changed the title QD-14791 QD-14813: Remove implicit scan injection from CLI dispatch 🔥 QD-14791 QD-14813 Remove implicit scan injection from CLI dispatch May 27, 2026
@bindreams
Anna Zhukova (bindreams) marked this pull request as ready for review May 27, 2026 11:56
@bindreams
Anna Zhukova (bindreams) requested a review from a team as a code owner May 27, 2026 11:56

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1bc21cb358

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "Codex (@codex) address that feedback".

Comment thread internal/cmd/root.go
@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had recent activity for 7 days.

What happens next?

  • If this PR is still relevant, please add a comment or push new commits to keep it active
  • If no activity occurs within 3 days, this PR will be automatically closed
  • You can always reopen the PR later if needed
  • You can also add a label 'wip' to keep the PR open

Thank you for your contribution! 🙏

@github-actions github-actions Bot added the stale label Jun 4, 2026
@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown

This pull request has been automatically closed due to inactivity.

Don't worry! You can always:

  • Reopen this PR if you want to continue working on it
  • Create a new PR with your changes
  • Reach out to the maintainers if you need help

Thank you for your contribution! 🙏

@github-actions

github-actions Bot commented Jul 27, 2026

Copy link
Copy Markdown

Qodana for Go

115 new problems were found

Inspection name Severity Problems
Check dependency licenses 🔴 Failure 5
Vulnerable declared dependency 🔴 Failure 1
Check GO source code coverage 🔶 Warning 52
Unhandled error 🔶 Warning 13
Potential resource leak 🔶 Warning 6
Check dependency licenses 🔶 Warning 4
Deprecated element 🔶 Warning 4
Imported package name as a name identifier 🔶 Warning 1
Reserved word used as name 🔶 Warning 1
Vulnerable declared dependency 🔶 Warning 1
Unsorted imports ◽️ Notice 13
Name starts with a package name ◽️ Notice 8
Empty slice declared using a literal ◽️ Notice 3
Comment of exported element starts with the incorrect name ◽️ Notice 1
Redundant type conversion ◽️ Notice 1
Vulnerable declared dependency ◽️ Notice 1
@@ Code coverage @@
+ 65% total lines covered
10603 lines analyzed, 6943 lines covered
# Calculated according to the filters of your coverage tool

☁️ View the detailed Qodana report

Contact Qodana team

Contact us at qodana-support@jetbrains.com

@github-actions github-actions Bot removed the stale label Jul 27, 2026
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had recent activity for 7 days.

What happens next?

  • If this PR is still relevant, please add a comment or push new commits to keep it active
  • If no activity occurs within 3 days, this PR will be automatically closed
  • You can always reopen the PR later if needed
  • You can also add a label 'wip' to keep the PR open

Thank you for your contribution! 🙏

@github-actions github-actions Bot added the stale label Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants