v0.3.0: GetConfig, validation improvements, CLI tests#3
v0.3.0: GetConfig, validation improvements, CLI tests#3github-actions[bot] merged 3 commits intomainfrom
Conversation
- backend.go: globalBackend interface + activeBackend; platform adapters register via init(), tests swap via useMockBackend - mock_test.go: mockBackend test double for all backend methods - GetConfig / GetConfigContext: per-protocol proxy read (HTTP/HTTPS/SOCKS/NoProxy) implemented on macOS (networksetup), Linux (gsettings), Windows (registry) - validate.go: specific error messages (missing scheme/host, port out of range) - cmd/sysproxy: CLI with set/get/unset/pac/check/version, --scope, --json, --timeout, exit codes 0/1/2 - internal/buildinfo: version/commit/date injected via ldflags
Welcome to Codecov 🎉Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests. ℹ️ You can also turn on project coverage checks and project coverage reporting on Pull Request comment Thanks for integrating Codecov - We've got you covered ☂️ |
There was a problem hiding this comment.
Pull request overview
This PR prepares the v0.3.0 release by extending the core proxy-management library with GetConfig/GetConfigContext, refactoring platform-specific global operations behind a backend interface, and adding a new cmd/sysproxy CLI plus supporting tests/docs/build updates.
Changes:
- Added backend-based global proxy operations and exposed
GetConfig/GetConfigContextfor per-protocol reads. - Introduced a standalone
sysproxyCLI, build metadata support, Makefile targets, and CI artifact/coverage updates. - Expanded tests and documentation around validation, CLI behavior, per-platform parsing, and new APIs.
Reviewed changes
Copilot reviewed 21 out of 22 changed files in this pull request and generated 12 comments.
Show a summary per file
| File | Description |
|---|---|
| validate.go | Refines proxy/PAC validation errors. |
| sysproxy.go | Adds ProxyScope.String, GetConfig, and backend dispatch. |
| sysproxy_windows.go | Implements Windows GetGlobalConfig and backend registration. |
| sysproxy_test.go | Adds mock-backend coverage for new public API paths. |
| sysproxy_other.go | Adds unsupported-platform backend stub. |
| sysproxy_linux.go | Implements Linux GetGlobalConfig and backend registration. |
| sysproxy_darwin.go | Implements macOS GetGlobalConfig, parsing helper, and backend registration. |
| sysproxy_darwin_test.go | Adds macOS parser unit tests. |
| README.md | Documents GetConfig, CLI usage, badges, and support matrix updates. |
| rcfile_unix_test.go | Adds Unix ScopeUser/rcfile tests. |
| mock_test.go | Introduces backend mock helper for tests. |
| Makefile | Adds CLI/build/test/lint/dist targets and build metadata flags. |
| logger.go | Clarifies logger concurrency note. |
| internal/buildinfo/buildinfo.go | Adds build metadata summary helper for CLI output. |
| cmd/sysproxy/main.go | Adds the new CLI entrypoint and command handling. |
| cmd/sysproxy/main_test.go | Adds CLI smoke/integration-style tests. |
| check_test.go | Loosens validation-error assertion for updated messages. |
| backend.go | Defines the global backend interface and active backend handle. |
| appconfig.go | Expands cancellation behavior documentation. |
| .golangci.yml | Adjusts lint configuration and gosec exclusions. |
| .gitignore | Ignores new generated output paths. |
| .github/workflows/test.yml | Expands matrix testing, coverage upload, and CLI artifact builds. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if err != nil { | ||
| if jsonOut { | ||
| printJSON(map[string]any{"error": "proxy not set"}) | ||
| } else { | ||
| fmt.Fprintln(os.Stderr, "proxy not set") | ||
| } | ||
| os.Exit(2) |
| for i := 0; i < len(args); i++ { | ||
| switch args[i] { | ||
| case "--scope": | ||
| i++ | ||
| if i >= len(args) { | ||
| die("--scope requires a value: shell|user|global") | ||
| } | ||
| scopeStr = args[i] | ||
| case "--json": | ||
| jsonOut = true | ||
| case "--timeout": | ||
| i++ | ||
| if i >= len(args) { | ||
| die("--timeout requires a duration value, e.g. 5s") | ||
| } | ||
| timeoutStr = args[i] | ||
| default: | ||
| positional = append(positional, args[i]) | ||
| } |
| flag string | ||
| dest *string | ||
| }{ | ||
| {"-getwebproxy", &cfg.HTTP}, | ||
| {"-getsecurewebproxy", &cfg.HTTPS}, | ||
| {"-getsocksfirewallproxy", &cfg.SOCKS}, | ||
| } { | ||
| out, err := exec.CommandContext(ctx, "networksetup", q.flag, svc).Output() //nolint:gosec | ||
| if err == nil { | ||
| h, p, ok := parseNSProxyOutput(string(out)) | ||
| if ok && h != "" && p != "0" { | ||
| *q.dest = "http://" + h + ":" + p |
| if !strings.Contains(server, "=") { | ||
| cfg.HTTP = "http://" + server | ||
| cfg.HTTPS = "http://" + server | ||
| cfg.SOCKS = "socks5://" + server |
| out, _ = exec.CommandContext(normalizeContext(ctx), "reg", "query", regKey, "/v", "ProxyOverride").Output() | ||
| cfg.NoProxy = extractRegValue(string(out), "ProxyOverride") |
| CGO_ENABLED: '0' | ||
| GOOS: ${{ matrix.goos }} | ||
| GOARCH: ${{ matrix.goarch }} | ||
| run: go build -o dist/${{ matrix.binary }} ./cmd/sysproxy |
| CGO_ENABLED: '0' | ||
| GOOS: ${{ matrix.goos }} | ||
| GOARCH: ${{ matrix.goarch }} | ||
| run: go build -o dist/${{ matrix.binary }} ./cmd/sysproxy |
| } | ||
| } | ||
|
|
||
| // TestVersionJSON checks --json flag on version (unsupported; just ensure no panic). |
| scope, err := parseScope(scopeStr) | ||
| if err != nil { | ||
| die(err.Error()) | ||
| } | ||
|
|
||
| timeout, err := time.ParseDuration(timeoutStr) | ||
| if err != nil { | ||
| die("invalid --timeout value: " + err.Error()) | ||
| } |
| gosec: | ||
| excludes: | ||
| - G705 | ||
| - G101 # false positive on example URLs in usage strings |
Changes
GetConfig()/GetConfigContext()— returns full per-protocolProxyConfigGetGlobalConfigon all platforms (macOS, Linux, Windows, stub)cmd/sysproxy/main_test.go)TestGetConfig_*andTestParseNSProxyOutputunit tests.exeextension for test binary on Windows