Conversation
…AgentLabelsResult helper, fix broken references from partial #2364 fix Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com> Agent-Logs-Url: https://github.com/github/gh-aw-mcpg/sessions/50f05b82-77da-4197-a262-fe882453850a
There was a problem hiding this comment.
Pull request overview
This PR cleans up several DIFC guard and CLI/config issues: it fixes misattributed NoopGuard logging, removes duplicated empty-label construction across guards, and finishes a partial refactor by updating env-default call sites and removing duplicated tests.
Changes:
- Fix NoopGuard to log via
guard:nooplogger instead of theguard:contextlogger. - Extract
emptyAgentLabelsResult(mode)helper and use it from NoopGuard and WriteSinkGuard. - Replace removed
getDefault*call sites withos.Getenv(...)and delete duplicate tests left behind by the partial refactor.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/guard/write_sink.go | Uses shared helper for empty agent labels in LabelAgent. |
| internal/guard/noop.go | Fixes logger usage and uses shared empty-label helper. |
| internal/guard/guard.go | Introduces emptyAgentLabelsResult helper. |
| internal/config/validation_env_test.go | Removes duplicated tests (container ID + gateway port env). |
| internal/config/config_test.go | Removes duplicated TestLoadFromFile_MultipleServers. |
| internal/cmd/root.go | Updates env-derived AllowOnly policy building call site after helper removal. |
| internal/cmd/proxy.go | Updates proxy --policy default to read from env directly after helper removal. |
| internal/cmd/flags_difc_test.go | Updates tests after helper removal (but now includes tautological env assertions). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| assert.NotEmpty(t, os.Getenv("MCP_GATEWAY_GUARD_POLICY_JSON")) | ||
| assert.True(t, getDefaultAllowOnlyScopePublic()) | ||
| assert.Equal(t, "lpcox", getDefaultAllowOnlyScopeOwner()) | ||
| assert.Equal(t, "gh-aw-mcpg", getDefaultAllowOnlyScopeRepo()) | ||
| assert.Equal(t, "unapproved", getDefaultAllowOnlyMinIntegrity()) | ||
| assert.Equal(t, "lpcox", os.Getenv("MCP_GATEWAY_ALLOWONLY_SCOPE_OWNER")) | ||
| assert.Equal(t, "gh-aw-mcpg", os.Getenv("MCP_GATEWAY_ALLOWONLY_SCOPE_REPO")) | ||
| assert.Equal(t, "unapproved", os.Getenv("MCP_GATEWAY_ALLOWONLY_MIN_INTEGRITY")) | ||
| } |
There was a problem hiding this comment.
TestGetDefaultGuardPolicyInputs is now effectively testing only environment variable plumbing (os.Getenv) rather than any gateway/defaulting logic. Either repurpose it to validate the actual behavior you care about (e.g., flag defaults after registration or resolveGuardPolicyOverride precedence) or remove it to avoid giving a false sense of coverage.
See below for a potential fix:
| cmd.Flags().StringVar(&proxyGuardWasm, "guard-wasm", defaultGuard, guardHelp) | ||
| cmd.Flags().StringVar(&proxyPolicy, "policy", getDefaultGuardPolicyJSON(), "Guard policy JSON") | ||
| cmd.Flags().StringVar(&proxyPolicy, "policy", os.Getenv("MCP_GATEWAY_GUARD_POLICY_JSON"), "Guard policy JSON") | ||
| cmd.Flags().StringVar(&proxyToken, "github-token", "", "Fallback GitHub API token (default: forwards client Authorization header)") |
There was a problem hiding this comment.
This flag default is pulled directly from os.Getenv, which diverges from the repo’s documented getDefault*() helper pattern for env-overridable defaults (see internal/cmd/flags.go). To keep env override behavior consistent (and easier to test), consider introducing/using a small getDefaultGuardPolicyJSON() helper (or an envutil.GetEnvString wrapper) here instead of reading the env var inline.
| getDefaultAllowOnlyScopePublic(), | ||
| getDefaultAllowOnlyScopeOwner(), | ||
| getDefaultAllowOnlyScopeRepo(), | ||
| getDefaultAllowOnlyMinIntegrity(), | ||
| os.Getenv("MCP_GATEWAY_ALLOWONLY_SCOPE_OWNER"), | ||
| os.Getenv("MCP_GATEWAY_ALLOWONLY_SCOPE_REPO"), | ||
| os.Getenv("MCP_GATEWAY_ALLOWONLY_MIN_INTEGRITY"), | ||
| ) |
There was a problem hiding this comment.
These env-driven defaults are now read inline via os.Getenv, which makes env override behavior less consistent with the codebase’s getDefault*() helper pattern for flags/env defaults (documented in internal/cmd/flags.go). Consider reintroducing small getDefaultAllowOnlyScopeOwner/Repo/MinIntegrity() helpers (or envutil wrappers) and using them here so validation/defaulting stays centralized and testable.
| os.Unsetenv("MCP_GATEWAY_GUARDS_SINK_SERVER_IDS") | ||
| assert.Equal(t, "", getDefaultDIFCSinkServerIDs()) | ||
| assert.Equal(t, "", os.Getenv("MCP_GATEWAY_GUARDS_SINK_SERVER_IDS")) | ||
|
|
||
| os.Setenv("MCP_GATEWAY_GUARDS_SINK_SERVER_IDS", "safeoutputs,github") | ||
| assert.Equal(t, "safeoutputs,github", getDefaultDIFCSinkServerIDs()) | ||
| assert.Equal(t, "safeoutputs,github", os.Getenv("MCP_GATEWAY_GUARDS_SINK_SERVER_IDS")) | ||
| } |
There was a problem hiding this comment.
TestGetDefaultDIFCSinkServerIDs no longer exercises any production code (it only asserts that os.Getenv reflects os.Setenv). This makes the test tautological and it won’t catch regressions in flag defaulting/registration. Consider rewriting it to assert the default value of the --guards-sink-server-ids flag after flag registration (or remove this test if that behavior is already covered elsewhere).
Three duplicate-code issues in the guard package and cmd flags: a misattributed logger bug, structural duplication in
LabelAgentimplementations, and broken call sites left by a partial inlining refactor.NoopGuard wrong logger (bug)
noop.godeclaredlogNoop = logger.New("guard:noop")but all four log calls used the package-levellogfromcontext.go(guard:context), makinglogNoopdead code and silently misattributing all NoopGuard logs.Extracted
emptyAgentLabelsResulthelperNoopGuard.LabelAgentandWriteSinkGuard.LabelAgentduplicated the sameAgentLabelsPayload{Secrecy: []string{}, Integrity: []string{}}construction, differing only inDIFCMode. Extracted toguard.go:Both guards now call
emptyAgentLabelsResult(difc.ModeStrict/ModeFilter).Completed partial refactor (broken build)
A prior commit removed
getDefaultGuardPolicyJSON,getDefaultAllowOnlyScopeOwner/Repo/MinIntegrityfromflags_difc.gobut left call sites unupdated and introduced duplicate test functions across config test files:os.Getenv(...)calls inproxy.goandroot.goflags_difc_test.goto useos.GetenvdirectlyTestLoadFromFile_MultipleServers(now inconfig_core_test.go),TestValidateContainerIDandTestGetGatewayPortFromEnv(now indocker_helpers_and_env_test.go) from their respective filesWarning
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/tmp/go-build3683465988/b333/launcher.test /tmp/go-build3683465988/b333/launcher.test -test.testlogfile=/tmp/go-build3683465988/b333/testlog.txt -test.paniconexit0 -test.timeout=10m0s /tmp/go-build3683465988/b299/vet.cfg g_.a 7198098/b151/ x_amd64/vet /tmp/go-build128/opt/hostedtoolcache/go/1.25.8/x64/pkg/tool/linux_amd64/vet ternal/engine/wa-unsafeptr=false(dns block)invalid-host-that-does-not-exist-12345.com/tmp/go-build3683465988/b318/config.test /tmp/go-build3683465988/b318/config.test -test.testlogfile=/tmp/go-build3683465988/b318/testlog.txt -test.paniconexit0 -test.timeout=10m0s go_.�� 64/src/net -trimpath x_amd64/vet 7198098/b157/ ions =0 x_amd64/vet swit�� ; then \ $GOPATH/bin/golangci-lint run --timeout=5m || echo "��� Warning: golangci-lint failed /opt/hostedtoolcache/go/1.25.8/x64/pkg/tool/linux_amd64/vet 7198098/b151/ 64/pkg/tool/linux_amd64/vet --gdwarf-5 --64 -o 64/pkg/tool/linu/tmp/go-build3683465988/b204/vet.cfg(dns block)nonexistent.local/tmp/go-build3683465988/b333/launcher.test /tmp/go-build3683465988/b333/launcher.test -test.testlogfile=/tmp/go-build3683465988/b333/testlog.txt -test.paniconexit0 -test.timeout=10m0s /tmp/go-build3683465988/b299/vet.cfg g_.a 7198098/b151/ x_amd64/vet /tmp/go-build128/opt/hostedtoolcache/go/1.25.8/x64/pkg/tool/linux_amd64/vet ternal/engine/wa-unsafeptr=false(dns block)slow.example.com/tmp/go-build3683465988/b333/launcher.test /tmp/go-build3683465988/b333/launcher.test -test.testlogfile=/tmp/go-build3683465988/b333/testlog.txt -test.paniconexit0 -test.timeout=10m0s /tmp/go-build3683465988/b299/vet.cfg g_.a 7198098/b151/ x_amd64/vet /tmp/go-build128/opt/hostedtoolcache/go/1.25.8/x64/pkg/tool/linux_amd64/vet ternal/engine/wa-unsafeptr=false(dns block)this-host-does-not-exist-12345.com/tmp/go-build3683465988/b342/mcp.test /tmp/go-build3683465988/b342/mcp.test -test.testlogfile=/tmp/go-build3683465988/b342/testlog.txt -test.paniconexit0 -test.timeout=10m0s 7198�� cfg -I 64/pkg/tool/linu-nilfunc --gdwarf-5 --64 /config 64/pkg/tool/linu-tests cfg /tmp/go-build1287198098/b185/_pkg_.a -trimpath x_amd64/vet -p 7198098/b288/ -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:
📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.