Skip to content

Deduplicate guards-mode CLI completions with canonical DIFC mode list#5244

Merged
lpcox merged 3 commits into
mainfrom
copilot/fix-duplicate-code-enforcement-modes
May 7, 2026
Merged

Deduplicate guards-mode CLI completions with canonical DIFC mode list#5244
lpcox merged 3 commits into
mainfrom
copilot/fix-duplicate-code-enforcement-modes

Conversation

Copilot AI commented May 7, 2026

Copy link
Copy Markdown
Contributor

The CLI shell completions for --guards-mode redefined DIFC enforcement modes in multiple places instead of using the canonical list from internal/difc. That made completions easy to drift from the actual supported modes.

  • Use the canonical DIFC mode list

    • Replace hardcoded []string{"strict", "filter", "propagate"} completions in:
      • internal/cmd/flags.go
      • internal/cmd/proxy.go
    • Wire both sites to difc.ValidModes
  • Align completion tests with the shared source of truth

    • Update the root command and proxy command completion tests to assert against difc.ValidModes instead of duplicating the mode literals again
  • Result

    • Adding or changing a DIFC enforcement mode in internal/difc now automatically updates shell completion behavior in both CLI entry points
cmd.RegisterFlagCompletionFunc("guards-mode", cobra.FixedCompletions(
	difc.ValidModes, cobra.ShellCompDirectiveNoFileComp))

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • example.com
    • Triggering command: /tmp/go-build4079301644/b509/launcher.test /tmp/go-build4079301644/b509/launcher.test -test.testlogfile=/tmp/go-build4079301644/b509/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true /internal/httpcommon/ascii.go /internal/httpcommon/headermap.go x_amd64/vet --gdwarf-5 ct/protoregistry-atomic =0 x_amd64/vet swit�� g_.a 8049330/b150/ x_amd64/vet -dynout gr/logr/funcr p=/opt/hostedtoo-bool x_amd64/vet (dns block)
    • Triggering command: /tmp/go-build80479181/b513/launcher.test /tmp/go-build80479181/b513/launcher.test -test.testlogfile=/tmp/go-build80479181/b513/testlog.txt -test.paniconexit0 -test.timeout=10m0s /tmp/go-build80479181/b506/vet.cfg /tmp/go-build3676587456/b093/vet.cfg -goversion x_amd64/compile -c=4 -nolocalimports -importcfg x_amd64/compile (dns block)
  • invalid-host-that-does-not-exist-12345.com
    • Triggering command: /tmp/go-build4079301644/b491/config.test /tmp/go-build4079301644/b491/config.test -test.testlogfile=/tmp/go-build4079301644/b491/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true 1.80.0/status/status.go om/tetratelabs/wazero@v1.11.0/internal/wasip1/clgoogle.golang.org/protobuf/internal/encoding/jso-atomic x_amd64/vet --gdwarf-5 ternal/engine/wa-unsafeptr=false -o x_amd64/vet 3MdK�� g_.a --debug-prefix-map x_amd64/vet abis binarylog -I x_amd64/vet (dns block)
    • Triggering command: /tmp/go-build80479181/b495/config.test /tmp/go-build80479181/b495/config.test -test.testlogfile=/tmp/go-build80479181/b495/testlog.txt -test.paniconexit0 -test.timeout=10m0s 6587�� /tmp/go-build1708049330/b433/_pkg_.a .cfg 64/pkg/tool/linux_amd64/vet -p golang.org/x/net--norc -lang=go1.25 64/pkg/tool/linux_amd64/vet 6587�� HwxzEigtvtf4iKtLrGai/HwxzEigtvtf4iKtLrGai -goversion 64/pkg/tool/linux_amd64/vet -c=4 -nolocalimports -importcfg 64/pkg/tool/linuorigin (dns block)
  • nonexistent.local
    • Triggering command: /tmp/go-build4079301644/b509/launcher.test /tmp/go-build4079301644/b509/launcher.test -test.testlogfile=/tmp/go-build4079301644/b509/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true /internal/httpcommon/ascii.go /internal/httpcommon/headermap.go x_amd64/vet --gdwarf-5 ct/protoregistry-atomic =0 x_amd64/vet swit�� g_.a 8049330/b150/ x_amd64/vet -dynout gr/logr/funcr p=/opt/hostedtoo-bool x_amd64/vet (dns block)
    • Triggering command: /tmp/go-build80479181/b513/launcher.test /tmp/go-build80479181/b513/launcher.test -test.testlogfile=/tmp/go-build80479181/b513/testlog.txt -test.paniconexit0 -test.timeout=10m0s /tmp/go-build80479181/b506/vet.cfg /tmp/go-build3676587456/b093/vet.cfg -goversion x_amd64/compile -c=4 -nolocalimports -importcfg x_amd64/compile (dns block)
  • slow.example.com
    • Triggering command: /tmp/go-build4079301644/b509/launcher.test /tmp/go-build4079301644/b509/launcher.test -test.testlogfile=/tmp/go-build4079301644/b509/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true /internal/httpcommon/ascii.go /internal/httpcommon/headermap.go x_amd64/vet --gdwarf-5 ct/protoregistry-atomic =0 x_amd64/vet swit�� g_.a 8049330/b150/ x_amd64/vet -dynout gr/logr/funcr p=/opt/hostedtoo-bool x_amd64/vet (dns block)
    • Triggering command: /tmp/go-build80479181/b513/launcher.test /tmp/go-build80479181/b513/launcher.test -test.testlogfile=/tmp/go-build80479181/b513/testlog.txt -test.paniconexit0 -test.timeout=10m0s /tmp/go-build80479181/b506/vet.cfg /tmp/go-build3676587456/b093/vet.cfg -goversion x_amd64/compile -c=4 -nolocalimports -importcfg x_amd64/compile (dns block)
  • this-host-does-not-exist-12345.com
    • Triggering command: /tmp/go-build4079301644/b518/mcp.test /tmp/go-build4079301644/b518/mcp.test -test.testlogfile=/tmp/go-build4079301644/b518/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true .cfg olang.org/grpc@v-ifaceassert x_amd64/vet _amd64.s --gdwarf2 --64 x_amd64/vet .cfg�� 8049330/b392/_pkg_.a -I x_amd64/vet --gdwarf-5 g/protobuf/inter/usr/bin/runc -o x_amd64/vet (dns block)
    • Triggering command: /tmp/go-build80479181/b522/mcp.test /tmp/go-build80479181/b522/mcp.test -test.testlogfile=/tmp/go-build80479181/b522/testlog.txt -test.paniconexit0 -test.timeout=10m0s estl�� se .com/github/gh-aw-mcpg/sessions/b4704323-4863-49cd-8abb-630e0c2a0430 .cfg ppb/timestamp.pbrunc user.email ache/go/1.25.9/x-lang=go1.24 ache/go/1.25.9/x64/pkg/tool/linux_amd64/vet (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Fix duplicate code pattern for enforcement mode constants Deduplicate guards-mode CLI completions with canonical DIFC mode list May 7, 2026
Copilot AI requested a review from lpcox May 7, 2026 15:48
Copilot finished work on behalf of lpcox May 7, 2026 15:48
@lpcox

lpcox commented May 7, 2026

Copy link
Copy Markdown
Collaborator

@copilot merge main

…-code-enforcement-modes

# Conflicts:
#	internal/cmd/flags.go
#	internal/cmd/flags_test.go

Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>

Copilot AI commented May 7, 2026

Copy link
Copy Markdown
Contributor Author

@copilot merge main

Merged main into this branch in 368e6c6 and verified the merged result with go test ./internal/cmd plus make agent-finished.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • example.com
    • Triggering command: /tmp/go-build1846201469/b513/launcher.test /tmp/go-build1846201469/b513/launcher.test -test.testlogfile=/tmp/go-build1846201469/b513/testlog.txt -test.paniconexit0 -test.timeout=10m0s -qui�� elemetry.io/otel-c=4 .cfg 64/pkg/tool/linu-importcfg . (dns block)
  • invalid-host-that-does-not-exist-12345.com
    • Triggering command: /tmp/go-build1846201469/b495/config.test /tmp/go-build1846201469/b495/config.test -test.testlogfile=/tmp/go-build1846201469/b495/testlog.txt -test.paniconexit0 -test.timeout=10m0s -w g_.a -o/tmp/go-build2275347390/b173//-ifaceassert x_amd64/vet -c /v1.27.0 /tmp/go-build2275347390/b173/ x_amd64/vet -W Z9sV672Nj .cfg 64/pkg/tool/linux_amd64/vet . .io/auto/sdk --64 64/pkg/tool/linux_amd64/vet (dns block)
  • nonexistent.local
    • Triggering command: /tmp/go-build1846201469/b513/launcher.test /tmp/go-build1846201469/b513/launcher.test -test.testlogfile=/tmp/go-build1846201469/b513/testlog.txt -test.paniconexit0 -test.timeout=10m0s -qui�� elemetry.io/otel-c=4 .cfg 64/pkg/tool/linu-importcfg . (dns block)
  • slow.example.com
    • Triggering command: /tmp/go-build1846201469/b513/launcher.test /tmp/go-build1846201469/b513/launcher.test -test.testlogfile=/tmp/go-build1846201469/b513/testlog.txt -test.paniconexit0 -test.timeout=10m0s -qui�� elemetry.io/otel-c=4 .cfg 64/pkg/tool/linu-importcfg . (dns block)
  • this-host-does-not-exist-12345.com
    • Triggering command: /tmp/go-build1846201469/b522/mcp.test /tmp/go-build1846201469/b522/mcp.test -test.testlogfile=/tmp/go-build1846201469/b522/testlog.txt -test.paniconexit0 -test.timeout=10m0s -o 5347390/b420/_pkg_.a pkg/mod/go.opentelemetry.io/otel@v1.43.0/attribu-ifaceassert x_amd64/vet -p g/grpc/credentiainspect -lang=go1.25 x_amd64/vet (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of lpcox May 7, 2026 15:58
@lpcox lpcox marked this pull request as ready for review May 7, 2026 15:59
Copilot AI review requested due to automatic review settings May 7, 2026 15:59

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

This PR deduplicates the --guards-mode shell completion values by sourcing them from the canonical DIFC mode list in internal/difc, preventing CLI completions from drifting from supported enforcement modes.

Changes:

  • Replace hardcoded []string{"strict", "filter", "propagate"} completions with difc.ValidModes in both root flag completions and the proxy subcommand.
  • Update completion tests to assert against difc.ValidModes rather than duplicating literals.
Show a summary per file
File Description
internal/cmd/proxy.go Use difc.ValidModes as the --guards-mode completion source for the proxy subcommand.
internal/cmd/proxy_test.go Align proxy completion test expectations with difc.ValidModes.
internal/cmd/flags.go Use difc.ValidModes as the canonical completion source for root --guards-mode.
internal/cmd/flags_test.go Align root flag completion test expectations with difc.ValidModes.

Copilot's findings

Tip

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

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

@lpcox lpcox merged commit e1434fb into main May 7, 2026
20 checks passed
@lpcox lpcox deleted the copilot/fix-duplicate-code-enforcement-modes branch May 7, 2026 16:11
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.

[duplicate-code] Duplicate Code Pattern: DIFC Enforcement Mode Constants Hardcoded in CLI Flag Completions

3 participants