-
Notifications
You must be signed in to change notification settings - Fork 28
[Repo Assist] refactor(cmd): add getDefault helpers for all DIFC flag env vars #2569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -145,20 +145,43 @@ func TestValidDIFCModes(t *testing.T) { | |||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| func TestGetDefaultDIFCSinkServerIDs(t *testing.T) { | ||||||||||||||||||||||||||||||||
| originalEnv := os.Getenv("MCP_GATEWAY_GUARDS_SINK_SERVER_IDS") | ||||||||||||||||||||||||||||||||
| defer func() { | ||||||||||||||||||||||||||||||||
| if originalEnv != "" { | ||||||||||||||||||||||||||||||||
| os.Setenv("MCP_GATEWAY_GUARDS_SINK_SERVER_IDS", originalEnv) | ||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||
| os.Unsetenv("MCP_GATEWAY_GUARDS_SINK_SERVER_IDS") | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| }() | ||||||||||||||||||||||||||||||||
| tests := []struct { | ||||||||||||||||||||||||||||||||
| name string | ||||||||||||||||||||||||||||||||
| envValue string | ||||||||||||||||||||||||||||||||
| setEnv bool | ||||||||||||||||||||||||||||||||
| expected string | ||||||||||||||||||||||||||||||||
| }{ | ||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||
| name: "no env var - returns empty string", | ||||||||||||||||||||||||||||||||
| setEnv: false, | ||||||||||||||||||||||||||||||||
| expected: "", | ||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||
| name: "env var set - returns value", | ||||||||||||||||||||||||||||||||
| envValue: "safeoutputs,github", | ||||||||||||||||||||||||||||||||
| setEnv: true, | ||||||||||||||||||||||||||||||||
| expected: "safeoutputs,github", | ||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||
| name: "empty env var - returns empty string", | ||||||||||||||||||||||||||||||||
| envValue: "", | ||||||||||||||||||||||||||||||||
| setEnv: true, | ||||||||||||||||||||||||||||||||
| expected: "", | ||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| os.Unsetenv("MCP_GATEWAY_GUARDS_SINK_SERVER_IDS") | ||||||||||||||||||||||||||||||||
| assert.Equal(t, "", os.Getenv("MCP_GATEWAY_GUARDS_SINK_SERVER_IDS")) | ||||||||||||||||||||||||||||||||
| for _, tt := range tests { | ||||||||||||||||||||||||||||||||
| t.Run(tt.name, func(t *testing.T) { | ||||||||||||||||||||||||||||||||
| if tt.setEnv { | ||||||||||||||||||||||||||||||||
| t.Setenv("MCP_GATEWAY_GUARDS_SINK_SERVER_IDS", tt.envValue) | ||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||
| t.Setenv("MCP_GATEWAY_GUARDS_SINK_SERVER_IDS", "") | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
| t.Setenv("MCP_GATEWAY_GUARDS_SINK_SERVER_IDS", "") | |
| // Ensure the env var is truly unset for this test case. | |
| const envKey = "MCP_GATEWAY_GUARDS_SINK_SERVER_IDS" | |
| origValue, hadEnv := os.LookupEnv(envKey) | |
| // Restore previous state after the subtest completes. | |
| t.Cleanup(func() { | |
| if hadEnv { | |
| _ = os.Setenv(envKey, origValue) | |
| } else { | |
| _ = os.Unsetenv(envKey) | |
| } | |
| }) | |
| _ = os.Unsetenv(envKey) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defaultAllowOnlyMinIntegrityis defined as an empty string and only used once; this constant doesn’t add meaning and slightly increases indirection. Consider inlining the empty string default, or (if you expect non-empty defaults later) defining defaults consistently for all new DIFC env-backed string flags in this file.