Skip to content

Deduplicate integrity-level enums by centralizing canonical values in guard#5245

Merged
lpcox merged 3 commits into
mainfrom
copilot/fix-duplicate-code-pattern-another-one
May 7, 2026
Merged

Deduplicate integrity-level enums by centralizing canonical values in guard#5245
lpcox merged 3 commits into
mainfrom
copilot/fix-duplicate-code-pattern-another-one

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 7, 2026

Integrity-level values (none, unapproved, approved, merged) were duplicated across guard, config, and cmd, despite guard claiming to be the source of truth. This change makes guard authoritative and updates downstream usage to consume canonical values directly.

  • Canonical integrity values

    • Exported guard.AllowedIntegrityLevels from internal/guard/wasm_validate.go.
    • Built the internal validation set from that exported slice, so validation and exported values cannot drift.
  • CLI completion now uses canonical values

    • Updated allowonly-min-integrity shell completion in internal/cmd/flags.go to use guard.AllowedIntegrityLevels instead of inline literals.
    • Updated corresponding completion test to assert against the canonical slice.
  • Config error messages now derive valid values dynamically

    • Replaced hardcoded integrity value lists in:
      • internal/config/guard_policy_validation.go
      • internal/config/guard_policy_parse.go
    • Error text now formats valid values via strings.Join(guard.AllowedIntegrityLevels, ", ").
  • Focused test coverage for dedup behavior

    • Added an assertion in guard_policy_parse_test.go that invalid integrity errors render from the canonical list.
    • Kept existing integrity acceptance behavior unchanged.
return nil, fmt.Errorf(
    "min-integrity must be one of: %s",
    strings.Join(guard.AllowedIntegrityLevels, ", "),
)

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-build3081364729/b509/launcher.test /tmp/go-build3081364729/b509/launcher.test -test.testlogfile=/tmp/go-build3081364729/b509/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true g_.a internal/testcert/testcert.go x_amd64/vet --gdwarf-5 --64 -o x_amd64/vet -E g_.a -m64 x_amd64/compile /tmp/go-build392/opt/hostedtoolcache/go/1.25.9/x64/pkg/tool/linux_amd64/vet g/x/net/http/htt-atomic -fno-stack-prote-bool x_amd64/compile (dns block)
    • Triggering command: /tmp/go-build3323417617/b513/launcher.test /tmp/go-build3323417617/b513/launcher.test -test.testlogfile=/tmp/go-build3323417617/b513/testlog.txt -test.paniconexit0 -test.timeout=10m0s -uns�� -unreachable=false /tmp/go-build3081364729/b246/vet.cfg bash g_.a -trimpath x_amd64/vet /opt/hostedtoolc--others -ato�� submodules | head -n 10 -buildtags /tmp/go-build3081364729/b225/cmd.test -errorsas -ifaceassert -nilfunc /tmp/go-build3081364729/b225/cmd.test (dns block)
  • invalid-host-that-does-not-exist-12345.com
    • Triggering command: /tmp/go-build3081364729/b491/config.test /tmp/go-build3081364729/b491/config.test -test.testlogfile=/tmp/go-build3081364729/b491/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true uf@v1.36.11/internal/filetype/build.go -I x_amd64/vet --gdwarf-5 --64 -o x_amd64/vet -I g_.a -I x_amd64/vet --gdwarf-5 ateway/v2/utilit-atomic -o x_amd64/vet (dns block)
    • Triggering command: /tmp/go-build191210255/b276/config.test /tmp/go-build191210255/b276/config.test -test.testlogfile=/tmp/go-build191210255/b276/testlog.txt -test.paniconexit0 -test.timeout=10m0s (dns block)
    • Triggering command: /tmp/go-build2613079384/b487/config.test /tmp/go-build2613079384/b487/config.test -test.testlogfile=/tmp/go-build2613079384/b487/testlog.txt -test.paniconexit0 -test.timeout=10m0s /tmp�� /home/REDACTED/go/pkg/mod/go.opent-p /home/REDACTED/go/pkg/mod/go.opentgithub.com/github/gh-aw-mcpg/internal/tracing_test .cfg sor.go duration.go .13/x64/as ache/go/1.25.9/x64/pkg/tool/linu-goversion (dns block)
  • nonexistent.local
    • Triggering command: /tmp/go-build3081364729/b509/launcher.test /tmp/go-build3081364729/b509/launcher.test -test.testlogfile=/tmp/go-build3081364729/b509/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true g_.a internal/testcert/testcert.go x_amd64/vet --gdwarf-5 --64 -o x_amd64/vet -E g_.a -m64 x_amd64/compile /tmp/go-build392/opt/hostedtoolcache/go/1.25.9/x64/pkg/tool/linux_amd64/vet g/x/net/http/htt-atomic -fno-stack-prote-bool x_amd64/compile (dns block)
    • Triggering command: /tmp/go-build3323417617/b513/launcher.test /tmp/go-build3323417617/b513/launcher.test -test.testlogfile=/tmp/go-build3323417617/b513/testlog.txt -test.paniconexit0 -test.timeout=10m0s -uns�� -unreachable=false /tmp/go-build3081364729/b246/vet.cfg bash g_.a -trimpath x_amd64/vet /opt/hostedtoolc--others -ato�� submodules | head -n 10 -buildtags /tmp/go-build3081364729/b225/cmd.test -errorsas -ifaceassert -nilfunc /tmp/go-build3081364729/b225/cmd.test (dns block)
  • slow.example.com
    • Triggering command: /tmp/go-build3081364729/b509/launcher.test /tmp/go-build3081364729/b509/launcher.test -test.testlogfile=/tmp/go-build3081364729/b509/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true g_.a internal/testcert/testcert.go x_amd64/vet --gdwarf-5 --64 -o x_amd64/vet -E g_.a -m64 x_amd64/compile /tmp/go-build392/opt/hostedtoolcache/go/1.25.9/x64/pkg/tool/linux_amd64/vet g/x/net/http/htt-atomic -fno-stack-prote-bool x_amd64/compile (dns block)
    • Triggering command: /tmp/go-build3323417617/b513/launcher.test /tmp/go-build3323417617/b513/launcher.test -test.testlogfile=/tmp/go-build3323417617/b513/testlog.txt -test.paniconexit0 -test.timeout=10m0s -uns�� -unreachable=false /tmp/go-build3081364729/b246/vet.cfg bash g_.a -trimpath x_amd64/vet /opt/hostedtoolc--others -ato�� submodules | head -n 10 -buildtags /tmp/go-build3081364729/b225/cmd.test -errorsas -ifaceassert -nilfunc /tmp/go-build3081364729/b225/cmd.test (dns block)
  • this-host-does-not-exist-12345.com
    • Triggering command: /tmp/go-build3081364729/b518/mcp.test /tmp/go-build3081364729/b518/mcp.test -test.testlogfile=/tmp/go-build3081364729/b518/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true olang.org/grpc@v-errorsas -I x_amd64/vet ctor --64 E=3 x_amd64/vet .cfg�� 2347187/b392/_pkg_.a otection x_amd64/vet /tmp/go-build392/usr/libexec/docker/docker-init g/protobuf/inter--version x86_64-linux-gnu x_amd64/vet (dns block)
    • Triggering command: /tmp/go-build3323417617/b522/mcp.test /tmp/go-build3323417617/b522/mcp.test -test.testlogfile=/tmp/go-build3323417617/b522/testlog.txt -test.paniconexit0 -test.timeout=10m0s n-me�� -bool -buildtags ker/docker-init -errorsas -ifaceassert -nilfunc ker/docker-init -ato�� -bool -buildtags docker-buildx -errorsas -ifaceassert -nilfunc docker-buildx (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 integrity level values across packages Deduplicate integrity-level enums by centralizing canonical values in guard May 7, 2026
Copilot finished work on behalf of lpcox May 7, 2026 15:41
Copilot AI requested a review from lpcox May 7, 2026 15:41
@lpcox lpcox marked this pull request as ready for review May 7, 2026 15:44
Copilot AI review requested due to automatic review settings May 7, 2026 15:44
@lpcox lpcox merged commit 293a035 into main May 7, 2026
36 of 37 checks passed
@lpcox lpcox deleted the copilot/fix-duplicate-code-pattern-another-one branch May 7, 2026 15:47
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 centralizes the canonical integrity-level enum values (none, unapproved, approved, merged) in internal/guard and updates config validation error messages and CLI shell completions to derive from that canonical list, reducing duplication across packages.

Changes:

  • Exported guard.AllowedIntegrityLevels and derived the internal validation set from it.
  • Updated CLI completion for --allowonly-min-integrity (and its test) to use the canonical list.
  • Updated config guard-policy error messages (and a focused test) to format valid integrity values from the canonical list.
Show a summary per file
File Description
internal/guard/wasm_validate.go Exports canonical integrity-level list and derives the validation set and error rendering from it.
internal/config/guard_policy_validation.go Uses guard.AllowedIntegrityLevels to format integrity-related validation errors.
internal/config/guard_policy_parse.go Uses guard.AllowedIntegrityLevels to format BuildAllowOnlyPolicy invalid-integrity errors.
internal/config/guard_policy_parse_test.go Adds assertion that invalid integrity errors list canonical values.
internal/cmd/flags.go Uses guard.AllowedIntegrityLevels for shell completions on allowonly-min-integrity.
internal/cmd/flags_test.go Updates completion test to assert against guard.AllowedIntegrityLevels.

Copilot's findings

Tip

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

  • Files reviewed: 6/6 changed files
  • Comments generated: 1

Comment on lines +8 to +17
// AllowedIntegrityLevels is the single source of truth for valid integrity-level values.
var AllowedIntegrityLevels = []string{"none", "unapproved", "approved", "merged"}

var allowedIntegrityLevelSet = map[string]struct{}{
"none": {},
"unapproved": {},
"approved": {},
"merged": {},
}
var allowedIntegrityLevelSet = func() map[string]struct{} {
m := make(map[string]struct{}, len(AllowedIntegrityLevels))
for _, level := range AllowedIntegrityLevels {
m[level] = struct{}{}
}
return m
}()
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: Integrity Level Values Scattered Across guard, config, and cmd Packages

3 participants