Skip to content

Harden Cobra command behavior: graceful proxy shutdown, default consistency, and completion updates#7047

Merged
lpcox merged 3 commits into
mainfrom
copilot/go-fan-review-spf13-cobra
Jun 5, 2026
Merged

Harden Cobra command behavior: graceful proxy shutdown, default consistency, and completion updates#7047
lpcox merged 3 commits into
mainfrom
copilot/go-fan-review-spf13-cobra

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jun 5, 2026

This issue identified several Cobra integration gaps in awmg: proxy shutdown was abrupt, proxy --guards-mode used a divergent default, Bash completion was on the legacy generator, and CLI completion/verbosity behavior had minor UX inconsistencies. This PR aligns proxy/root command behavior and modernizes completion wiring with minimal surface-area changes.

  • Proxy shutdown semantics

    • proxy now performs graceful HTTP drain on exit (Shutdown + timeout) instead of immediate connection teardown (Close).
    • Shutdown errors are now propagated/logged instead of being silently ignored.
    • Added a named shutdown timeout constant for maintainability.
  • guards-mode default alignment

    • proxy --guards-mode now uses difc.DefaultEnforcementMode() instead of a hardcoded literal, matching root command behavior and env-driven defaults.
  • Shell completion modernization

    • Switched Bash completion generation to GenBashCompletionV2(..., true) to include richer completion metadata.
    • Replaced manual file-extension completion callbacks for --config and --env with MarkFlagFilename(...) and explicit error handling.
  • Verbosity UX cleanup

    • Removed the -v (level 1) informational startup log line that added noise without changing runtime logging behavior.
  • Targeted test adjustments

    • Updated/added tests to validate env-driven guards-mode default behavior.
    • Updated completion tests to assert MarkFlagFilename annotations for config/env.
    • Added coverage ensuring -v does not emit extra startup noise.
cmd.Flags().StringVar(&proxyDIFCMode, "guards-mode", difc.DefaultEnforcementMode(), "DIFC enforcement mode: strict, filter, propagate")

const proxyShutdownTimeout = 5 * time.Second
shutdownCtx, cancel := context.WithTimeout(context.Background(), proxyShutdownTimeout)
defer cancel()
if err := httpServer.Shutdown(shutdownCtx); err != nil {
    logger.LogError("shutdown", "HTTP server shutdown error: %v", err)
    return err
}

Copilot AI linked an issue Jun 5, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Review Go Module spf13/cobra for compliance Harden Cobra command behavior: graceful proxy shutdown, default consistency, and completion updates Jun 5, 2026
Copilot finished work on behalf of lpcox June 5, 2026 14:12
Copilot AI requested a review from lpcox June 5, 2026 14:12
@lpcox lpcox marked this pull request as ready for review June 5, 2026 14:40
Copilot AI review requested due to automatic review settings June 5, 2026 14:40
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens the awmg Cobra CLI by making proxy shutdown behavior graceful, aligning proxy --guards-mode defaults with the root command/environment-driven behavior, and modernizing shell completion generation and flag filename completion metadata.

Changes:

  • Implement graceful HTTP server shutdown for awmg proxy using http.Server.Shutdown with a bounded timeout and error propagation.
  • Align proxy --guards-mode default to difc.DefaultEnforcementMode() and extend tests to cover env-driven defaults.
  • Modernize Bash completion generation (GenBashCompletionV2) and replace manual file-extension completion callbacks with MarkFlagFilename + updated completion tests.
Show a summary per file
File Description
internal/cmd/root.go Removes -v info-level startup log noise while keeping higher verbosity/debug logging behavior.
internal/cmd/root_test.go Adds a regression test asserting -v doesn’t emit startup log output.
internal/cmd/proxy.go Adds graceful proxy HTTP drain on shutdown and aligns --guards-mode default with difc.DefaultEnforcementMode().
internal/cmd/proxy_test.go Updates defaults test and adds env-driven default coverage for --guards-mode.
internal/cmd/flags.go Switches config/env completions to MarkFlagFilename(...) with error handling.
internal/cmd/flags_test.go Updates tests to assert Cobra filename-extension annotations instead of custom completion funcs.
internal/cmd/completion.go Switches Bash completion generation to GenBashCompletionV2(..., true) for richer metadata.

Copilot's findings

Tip

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

  • Files reviewed: 7/7 changed files
  • Comments generated: 0

@lpcox lpcox merged commit 86fbb80 into main Jun 5, 2026
29 checks passed
@lpcox lpcox deleted the copilot/go-fan-review-spf13-cobra branch June 5, 2026 15:29
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.

[go-fan] Go Module Review: spf13/cobra

3 participants