Skip to content

CLI consistency: reject legacy nested gh fallback under multi-subcommand parents - #49673

Merged
pelikhan merged 4 commits into
mainfrom
copilot/cli-consistency-issues-2026-07-31
Aug 2, 2026
Merged

CLI consistency: reject legacy nested gh fallback under multi-subcommand parents#49673
pelikhan merged 4 commits into
mainfrom
copilot/cli-consistency-issues-2026-07-31

Conversation

Copilot AI commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Manual CLI review found that gh aw <parent> gh --help (secrets|mcp|project|pr|env) rendered parent help, creating a hidden/duplicate-command impression and inconsistent unknown-command behavior. This change makes those invocations fail explicitly as unknown commands.

  • Behavior fix: block legacy nested gh path

    • Added a hidden gh guard subcommand that always returns an unknown-command error for the parent command path.
    • Prevents Cobra help fallback from treating gh --help as parent help for these command groups.
  • Scope of application

    • Wired the guard into:
      • secrets
      • mcp
      • project
      • pr
      • env
  • Regression coverage

    • Added a focused consistency test asserting gh --help under each affected parent returns:
      • unknown command "gh" for "<parent>"
func newLegacyGHGuardSubcommand() *cobra.Command {
	return &cobra.Command{
		Use:                "gh",
		Hidden:             true,
		DisableFlagParsing: true,
		RunE: func(cmd *cobra.Command, _ []string) error {
			return fmt.Errorf("unknown command %q for %q", cmd.Name(), cmd.Parent().CommandPath())
		},
	}
}

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 9.35 AIC · ⌖ 6.47 AIC · ⊞ 8.1K ·
Comment /souschef to run again

…arents

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix CLI consistency issues for threat detection CLI consistency: reject legacy nested gh fallback under multi-subcommand parents Aug 1, 2026
Copilot AI requested a review from pelikhan August 1, 2026 22:47
@pelikhan
pelikhan marked this pull request as ready for review August 1, 2026 23:00
Copilot AI review requested due to automatic review settings August 1, 2026 23:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a hidden Cobra guard to reject legacy nested gh invocations consistently.

Changes:

  • Introduces a reusable hidden gh guard subcommand.
  • Applies it to five multi-subcommand parents.
  • Adds regression coverage for gh --help.
Show a summary per file
File Description
pkg/cli/gh_guard_subcommand.go Implements the rejection guard.
pkg/cli/secrets_command.go Registers the guard for secrets.
pkg/cli/mcp.go Registers the guard for mcp.
pkg/cli/project_command.go Registers the guard for project.
pkg/cli/pr_command.go Registers the guard for pr.
pkg/cli/env_command.go Registers the guard for env.
pkg/cli/cli_consistency_help_test.go Tests consistent rejection across affected parents.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 7/7 changed files
  • Comments generated: 0
  • Review effort level: Balanced

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

⚠️ PR Code Quality Reviewer failed during code quality review.

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Design Decision Gate 🏗️ completed the design decision gate check.

No ADR enforcement needed: PR does not have the 'implementation' label and has ≤100 new lines of code in business logic directories (53 additions found).

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Test Quality Sentinel completed test quality analysis.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review: LGTM

The change is focused, correct, and well-tested.

  • DisableFlagParsing: true is the right mechanism — it ensures --help reaches RunE instead of being intercepted by Cobra's flag parser, which is exactly what blocks the silent parent-help fallback.
  • Error message format matches the test assertions exactly.
  • All 5 affected command groups are covered by the regression test.
  • No security or correctness concerns.

Minor nit (non-blocking): The RunE closure names the args parameter args []string but never uses it. Consider renaming to _ for clarity, e.g. func(cmd *cobra.Command, _ []string) error {.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · sonnet46 · 18.8 AIC · ⌖ 10.3 AIC · ⊞ 5.4K

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Skills-Based Review 🧠

Applied /diagnosing-bugs and /tdd — two minor suggestions, no blocking issues.

📋 Key Themes & Highlights

Key Themes

  • Coverage scope: experiments (2 subcommands) is the one remaining multi-subcommand parent that does not yet have the guard. Worth adding for consistency.
  • Test breadth: Tests confirm the ["gh", "--help"] path; ["gh", "subcommand"] with extra args is not exercised.

Positive Highlights

  • ✅ Excellent single-responsibility abstraction: one tiny file, one reusable guard, wired uniformly into five commands.
  • DisableFlagParsing: true is the right knob — prevents Cobra from consuming --help before the RunE fires.
  • ✅ Regression test is table-driven, covers all affected commands, and reads as a clear specification.
  • ✅ Zero deletions — purely additive, low risk.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 · 37.7 AIC · ⌖ 7.86 AIC · ⊞ 7.1K
Comment /matt to run again

Comment thread pkg/cli/gh_guard_subcommand.go Outdated
Use: "gh",
Hidden: true,
DisableFlagParsing: true,
RunE: func(cmd *cobra.Command, args []string) error {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[/diagnosing-bugs] The args parameter is unused — name it _ per Go convention to signal it is intentionally discarded and avoid linter warnings.

💡 Suggested fix
RunE: func(cmd *cobra.Command, _ []string) error {

@copilot please address this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated in dfef025ce8: RunE now uses _ []string to intentionally discard the unused args parameter.


err := cmd.Execute()
require.Error(t, err)
assert.Equal(t, `unknown command "gh" for "`+tt.cmdName+`"`, err.Error())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[/tdd] The test only verifies the error message for the first positional arg (gh), not for deeper paths like gh subcommand --help. Consider adding a case to confirm that gh aw <parent> gh subcommand also returns an error, guarding against args being passed to the guard command.

💡 Example additional table row
{name: "secrets gh with args", newCmd: NewSecretsCommand, cmdName: "secrets", args: []string{"gh", "set", "--help"}},

With the current DisableFlagParsing: true this should still error; a test would lock in that guarantee.

@copilot please address this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in dfef025ce8: added a nested-args regression case (gh set --help) in TestLegacyNestedGHHelpIsRejected to verify the guard still errors when extra positional args are present.

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

🧪 Test Quality Sentinel Report

Test Quality Score: 85/100 — Excellent

Analyzed 2 test(s): 2 design, 0 implementation, 0 violation(s).

📊 Metrics (2 tests)
Metric Value
Analyzed 2 (Go: 2, JS: 0)
✅ Design 2 (100%)
⚠️ Implementation 0 (0%)
Edge/error coverage 1 (50%)
Duplicate clusters 0
Inflation No (test:prod ≈ 1.1:1)
🚨 Violations 0
Test File Classification Issues
TestLegacyNestedGHHelpIsRejected pkg/cli/cli_consistency_help_test.go design_test / behavioral_contract / high_value None
TestSubcommandListingsUseHyphenBullets (extended) pkg/cli/cli_consistency_help_test.go design_test / behavioral_contract / high_value None

Verdict

passed. 0% implementation tests (threshold: 30%). Build tag present. No mock violations.

🧪 Test quality analysis by Test Quality Sentinel · sonnet46 · 34.3 AIC · ⌖ 9.89 AIC · ⊞ 8.4K ·
Comment /review to run again

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Test Quality Sentinel: 85/100. 0% implementation tests (threshold: 30%).

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot
Please investigate this PR and move it toward merge readiness.
Failed checks:

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 9.35 AIC · ⌖ 6.47 AIC · ⊞ 8.1K ·
Comment /souschef to run again

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>

Copilot AI commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

@copilot
Please investigate this PR and move it toward merge readiness.
Failed checks:...

Implemented fixes in commit dfef025ce8: addressed the unresolved review feedback (_ for unused guard args and added nested gh-with-args coverage), synced the aw-failure-investigator prefetch expectation with current workflow behavior, and ran local validation (make fmt, make lint, make test-unit, make test).

@github-actions

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

🔍 Triage Summary

Field Value
Category bug
Risk medium
Priority medium
Score 58/100 (impact 25 + urgency 15 + quality 18)
Recommended action fast_track
Batch

CLI fix rejecting legacy nested gh fallback for multi-subcommand parents. CI green, approved by automated reviewer.

Automated triage — see the triage report for full context.

Generated by 🔧 PR Triage Agent · auto · 40.3 AIC · ⌖ 4.01 AIC · ⊞ 8K ·

@pelikhan
pelikhan merged commit 1d9b0f8 into main Aug 2, 2026
29 checks passed
@pelikhan
pelikhan deleted the copilot/cli-consistency-issues-2026-07-31 branch August 2, 2026 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[cli-consistency] CLI Consistency Issues - 2026-07-31

4 participants