Skip to content

refactor: consolidate deprecated bool flag helpers into pkg/cli/flags.go - #48680

Merged
pelikhan merged 3 commits into
mainfrom
copilot/deep-report-consolidate-flags
Jul 28, 2026
Merged

refactor: consolidate deprecated bool flag helpers into pkg/cli/flags.go#48680
pelikhan merged 3 commits into
mainfrom
copilot/deep-report-consolidate-flags

Conversation

Copilot AI commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

The --no-security-scanner/--disable-security-scanner registration + resolution pattern was copy-pasted across 5 command files (~20 lines of identical logic, 5 near-duplicate tests). One test had already drifted in naming (HasDisableSecurityScannerFlag vs DeprecatesDisableSecurityScannerFlag), confirming the duplication was causing inconsistency.

Changes

  • pkg/cli/flags.go — Two new helpers:

    • addSecurityScannerFlag(cmd): registers --no-security-scanner + deprecated --disable-security-scanner alias
    • resolveDeprecatedBoolFlag(cmd, newName, oldName string) bool: collapses a renamed flag pair into a single effective value
  • 5 command files — Replace copy-pasted 3-line registration and 3-line resolution blocks with the helpers. resolveDeprecatedBoolFlag also applied to the analogous no-release-bump/disable-release-bump pair in update_command.go and delete-host-repo-before/force-delete-host-repo-before in trial_command.go.

  • Tests — Remove 6 duplicated per-command deprecation tests; add TestAddSecurityScannerFlag and TestResolveDeprecatedBoolFlag (subtests: both-false, new-set, old-set) in flags_test.go as the single authoritative location.

// Before (repeated verbatim in 5 files):
cmd.Flags().Bool("no-security-scanner", false, "Skip security scanning of workflow markdown content")
cmd.Flags().Bool("disable-security-scanner", false, "Skip security scanning of workflow markdown content")
_ = cmd.Flags().MarkDeprecated("disable-security-scanner", "use --no-security-scanner instead")
// ...
disableSecurityScanner, _ := cmd.Flags().GetBool("no-security-scanner")
disableSecurityScannerLegacy, _ := cmd.Flags().GetBool("disable-security-scanner")
disableSecurityScanner = disableSecurityScanner || disableSecurityScannerLegacy

// After:
addSecurityScannerFlag(cmd)
// ...
disableSecurityScanner := resolveDeprecatedBoolFlag(cmd, "no-security-scanner", "disable-security-scanner")

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Consolidate CLI flag duplication into pkg/cli/flags.go helpers refactor: consolidate deprecated bool flag helpers into pkg/cli/flags.go Jul 28, 2026
Copilot AI requested a review from pelikhan July 28, 2026 16:16
@pelikhan
pelikhan marked this pull request as ready for review July 28, 2026 16:28
Copilot AI review requested due to automatic review settings July 28, 2026 16:28
@github-actions

github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

PR Code Quality Reviewer completed the code quality review.

@github-actions

github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

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

No ADR enforcement needed: PR #48680 does not have the 'implementation' label and has ≤100 new lines of code in business logic directories (95 additions, threshold is 100).

@github-actions

github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Test Quality Sentinel completed test quality analysis.

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

Centralizes deprecated boolean flag handling in pkg/cli/flags.go, reducing duplication while preserving CLI compatibility.

Changes:

  • Adds shared security-scanner registration and deprecated-flag resolution helpers.
  • Migrates five commands to the shared helpers.
  • Consolidates duplicated tests into helper-focused coverage.
Show a summary per file
File Description
pkg/cli/flags.go Adds shared flag helpers.
pkg/cli/flags_test.go Tests registration and resolution helpers.
pkg/cli/add_command.go Uses shared helpers.
pkg/cli/add_command_test.go Removes duplicate alias test.
pkg/cli/add_wizard_command.go Uses shared helpers.
pkg/cli/add_wizard_command_test.go Removes duplicate alias test.
pkg/cli/deploy_command.go Uses shared helpers.
pkg/cli/deploy_command_test.go Removes duplicate alias test.
pkg/cli/trial_command.go Consolidates deprecated boolean aliases.
pkg/cli/trial_command_test.go Removes duplicate test and unused imports.
pkg/cli/update_command.go Consolidates scanner and release-bump aliases.
pkg/cli/update_command_test.go Removes superseded deprecation tests.

Review details

Tip

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

  • Files reviewed: 12/12 changed files
  • Comments generated: 0
  • Review effort level: Medium

@github-actions github-actions Bot mentioned this pull request Jul 28, 2026

@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.

Verdict: Approve — clean, correct refactor

Mechanical dedup of the --no-X/--disable-X deprecated-flag pattern into two shared helpers; no correctness issues found across two independent passes (own review + grumpy-coder sub-agent).

Review notes
  • Verified all 5 call sites (add, add_wizard, deploy, trial x2, update x2) pass resolveDeprecatedBoolFlag(cmd, newName, oldName) with correct argument order matching prior behavior, including the less-obvious delete-host-repo-before/force-delete-host-repo-before pair in trial_command.go.
  • addSecurityScannerFlag is applied consistently everywhere the old manual 3-line registration existed; no leftover duplicated registrations.
  • New helpers in flags.go are simple, side-effect-free, and covered by TestAddSecurityScannerFlag / TestResolveDeprecatedBoolFlag (including both-false, new-set, old-set subtests).
  • Minor, non-blocking observation: deleting the 6 per-command deprecation tests in favor of centralized tests in flags_test.go means a future copy-paste typo in one command's call site (wrong flag name string) would no longer be caught by that command's own test suite — only the shared helper's correctness is verified, not each call site's wiring. Not worth blocking on given current correctness, but worth keeping in mind if more commands adopt this pattern.

🔎 Code quality review by PR Code Quality Reviewer · sonnet50 · 31.8 AIC · ⌖ 4.31 AIC · ⊞ 7.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.

Skills-Based Review 🧠

Applied /codebase-design and /tdd — requesting changes on two gaps before merge.

📋 Key Themes & Highlights

Issues

  1. Incomplete pattern--no-release-bump/--disable-release-bump registration in update_command.go is still inline (lines 171-173), while all security-scanner pairs were moved to addSecurityScannerFlag. The PR's own goal of consistency calls for an addReleaseBumpFlag helper here.

  2. Coverage gapTestNewUpdateCommand_DeprecatesDisableReleaseBumpFlag was deleted but no equivalent was added to flags_test.go. The deprecation message on --disable-release-bump is now untested.

  3. Silent error swallowingresolveDeprecatedBoolFlag discards GetBool errors with _. A misspelled flag name returns false silently; a panic on programmer error would surface this immediately.

Positive Highlights

  • ✅ Clean elimination of 20+ lines of copy-pasted flag logic across 5 command files
  • TestResolveDeprecatedBoolFlag has well-structured parallel subtests covering both-false, new-set, and old-set cases
  • resolveDeprecatedBoolFlag is a genuinely general helper — good API surface
  • ✅ PR description accurately captures the scope and motivation

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 · 48 AIC · ⌖ 5.11 AIC · ⊞ 6.7K
Comment /matt to run again

Comment thread pkg/cli/update_command.go
@@ -175,9 +171,7 @@ Note: In GitHub Enterprise repos, shorthand source specs resolve on your enterpr
cmd.Flags().Bool("no-release-bump", false, "Restrict automatic major version bumps to core actions/* only (non-core actions are left as-is)")
cmd.Flags().Bool("disable-release-bump", false, "Restrict automatic major version bumps to core actions/* only (non-core actions are left as-is)")
_ = cmd.Flags().MarkDeprecated("disable-release-bump", "use --no-release-bump instead")

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.

[/codebase-design] The --no-release-bump/--disable-release-bump pair is still registered inline here, inconsistent with the addSecurityScannerFlag pattern introduced in this PR.

💡 Suggestion

Extract an addReleaseBumpFlag(cmd) helper in flags.go alongside addSecurityScannerFlag and replace these three lines:

func addReleaseBumpFlag(cmd *cobra.Command) {
	cmd.Flags().Bool("no-release-bump", false, "Restrict automatic major version bumps...")
	cmd.Flags().Bool("disable-release-bump", false, "Restrict automatic major version bumps...")
	_ = cmd.Flags().MarkDeprecated("disable-release-bump", "use --no-release-bump instead")
}

Then call addReleaseBumpFlag(cmd) at the registration site. All deprecated-pair registrations are then in one place, eliminating this last inline exception.

@copilot please address this.

Comment thread pkg/cli/flags_test.go
t.Error("expected true when deprecated old flag is set")
}
})
}

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] TestResolveDeprecatedBoolFlag and TestAddSecurityScannerFlag cover the security-scanner pair, but there is no test for the --no-release-bump/--disable-release-bump pair that was also migrated to resolveDeprecatedBoolFlag in this PR.

TestNewUpdateCommand_DeprecatesDisableReleaseBumpFlag was deleted from update_command_test.go without a corresponding canonical test in flags_test.go. The deprecation message on --disable-release-bump is now untested.

💡 Suggestion

Add a TestAddReleaseBumpFlag (or extend TestAddSecurityScannerFlag into a table-driven test) covering the --no-release-bump / --disable-release-bump pair:

func TestAddReleaseBumpFlag(t *testing.T) {
	t.Parallel()
	cmd := &cobra.Command{Use: "test"}
	addReleaseBumpFlag(cmd)

	deprecated := cmd.Flags().Lookup("disable-release-bump")
	if deprecated == nil {
		t.Fatal("addReleaseBumpFlag should register --disable-release-bump")
	}
	if deprecated.Deprecated != "use --no-release-bump instead" {
		t.Errorf("unexpected deprecation message: %q", deprecated.Deprecated)
	}
}

@copilot please address this.

Comment thread pkg/cli/flags.go
// them into a single effective value.
func resolveDeprecatedBoolFlag(cmd *cobra.Command, newName, oldName string) bool {
newVal, _ := cmd.Flags().GetBool(newName)
oldVal, _ := cmd.Flags().GetBool(oldName)

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.

[/codebase-design] resolveDeprecatedBoolFlag silently discards errors from GetBool. If either flag name is misspelled at a call site, the function returns false without any indication of the mistake — the call site will behave incorrectly and no test will catch it at registration time.

💡 Suggestion

Panic (or use must-style) on a programming error at startup, consistent with how cobra itself handles unknown-flag access in tests:

func resolveDeprecatedBoolFlag(cmd *cobra.Command, newName, oldName string) bool {
	newVal, err := cmd.Flags().GetBool(newName)
	if err != nil {
		panic(fmt.Sprintf("resolveDeprecatedBoolFlag: flag %q not registered: %v", newName, err))
	}
	oldVal, err := cmd.Flags().GetBool(oldName)
	if err != nil {
		panic(fmt.Sprintf("resolveDeprecatedBoolFlag: flag %q not registered: %v", oldName, err))
	}
	return newVal || oldVal
}

A panic at startup is far easier to diagnose than a silent false in production. Alternatively, return (bool, error) if callers can handle it, but a panic is idiomatic for programmer errors in cobra-based CLIs.

@copilot please address this.

@github-actions

Copy link
Copy Markdown
Contributor

🧪 Test Quality Sentinel Report

⚠️ Test Quality Score: 75/100 — Acceptable

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 YES — flags_test.go: +65 vs flags.go: +18 = 3.6:1 (nominal for consolidation refactor; net lines ~unchanged)
🚨 Violations 0
Test File Classification Issues
TestAddSecurityScannerFlag pkg/cli/flags_test.go design_test / high_value None
TestResolveDeprecatedBoolFlag (3 subtests) pkg/cli/flags_test.go design_test / high_value None

Context

This PR consolidates 6 per-command deprecated-flag tests (removed from add_command_test.go, add_wizard_command_test.go, deploy_command_test.go, trial_command_test.go, update_command_test.go) into 2 centralized tests in flags_test.go. The 3.6:1 line inflation ratio is an artifact of this deliberate consolidation — net test lines across all files are roughly unchanged (−61 removed, +65 added). Build tag present (//go:build !integration). No mock libraries used.

Verdict

passed. 0% implementation tests (threshold: 30%). Test consolidation is a quality improvement: shared helpers are tested once rather than per-command.

🧪 Test quality analysis by Test Quality Sentinel · sonnet46 · 57.7 AIC · ⌖ 8.12 AIC · ⊞ 8.1K ·
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: 75/100. 0% implementation tests (threshold: 30%). No violations detected. Test consolidation is a quality improvement.

@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: refactor consolidation is sound — one follow-up needed

The core refactor is clean and correct. addSecurityScannerFlag and resolveDeprecatedBoolFlag are well-named, well-tested, and properly applied across all five command files.

One inconsistency: the analogous no-release-bump/disable-release-bump pair in update_command.go had its resolution migrated to resolveDeprecatedBoolFlag but the 3-line registration block was left in place (not extracted to a helper). See the inline comment for the suggested fix.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · sonnet46 · 19 AIC · ⌖ 5.3 AIC · ⊞ 5K

Comment thread pkg/cli/update_command.go
@@ -175,9 +171,7 @@ Note: In GitHub Enterprise repos, shorthand source specs resolve on your enterpr
cmd.Flags().Bool("no-release-bump", false, "Restrict automatic major version bumps to core actions/* only (non-core actions are left as-is)")
cmd.Flags().Bool("disable-release-bump", false, "Restrict automatic major version bumps to core actions/* only (non-core actions are left as-is)")
_ = cmd.Flags().MarkDeprecated("disable-release-bump", "use --no-release-bump instead")

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.

The no-release-bump/disable-release-bump registration block (lines 171–173) was not extracted into a helper the way the security-scanner pair was. For full consistency — and so that the deprecated-alias contract is tested centrally — consider adding an addReleaseBumpFlag(cmd) helper in flags.go (mirroring addSecurityScannerFlag) and a matching TestAddReleaseBumpFlag test in flags_test.go. The deleted TestNewUpdateCommand_DeprecatesDisableReleaseBumpFlag had value; removing it without a central replacement leaves the deprecation message untested. @copilot please address this.

@pelikhan
pelikhan merged commit e0a0396 into main Jul 28, 2026
28 checks passed
@pelikhan
pelikhan deleted the copilot/deep-report-consolidate-flags branch July 28, 2026 16:50
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.

[deep-report] Consolidate --no-security-scanner style CLI flag duplication into pkg/cli/flags.go helpers

3 participants