Skip to content

v0.5: sentinel errors, KDE Get/GetConfig, PAC in GetConfig, WithProxyMulti#9

Merged
github-actions[bot] merged 1 commit into
mainfrom
dev
Jul 4, 2026
Merged

v0.5: sentinel errors, KDE Get/GetConfig, PAC in GetConfig, WithProxyMulti#9
github-actions[bot] merged 1 commit into
mainfrom
dev

Conversation

@mar0ls

@mar0ls mar0ls commented Jul 4, 2026

Copy link
Copy Markdown
Owner

Summary

  • Bugfixes: darwin GetConfig returned SOCKS with http:// scheme instead of socks5://; WithProxy restored only HTTP — now snapshots and restores the full ProxyConfig (HTTP + HTTPS + SOCKS + NoProxy + PAC).
  • New API (additive, backwards compatible): sentinel errors (ErrProxyNotSet, ErrProxyNotEnabled, ErrUnsupportedPlatform, ErrToolMissing), RequiresElevation, ProxyConfig.PAC, WithProxyMulti.
  • KDE: Get / GetConfig via kreadconfig5/kreadconfig6, fallback po GNOME.
  • PAC read w GetConfig na wszystkich platformach (macOS -getautoproxyurl, Windows AutoConfigURL, GNOME autoconfig-url, KDE Proxy Config Script).
  • Fuzz tests dla URL surface (FuzzParse, FuzzValidateProxyURL, FuzzValidatePACURL).
  • internal/buildinfo coverage 0% → 100%; main package 74.7% → 75.4%.

Breaking changes

None. All new API is additive. Error messages for the "tool not found in PATH" case were reworded but now wrap ErrToolMissing — callers that were string-matching should switch to errors.Is.

Test plan

  • go test ./... -race -count=1 on darwin
  • GOOS={linux,windows,darwin,freebsd} go build ./...
  • golangci-lint run ./... — 0 issues
  • go test -fuzz Fuzz{Parse,ValidateProxyURL,ValidatePACURL} -fuzztime 3s each — pass
  • Smoke test on real KDE Plasma 5 (kioslaverc round-trip)
  • Smoke test on real Windows (PAC in GetConfig when AutoConfigURL set)
  • Smoke test on real macOS (SOCKS scheme in GetConfig output)

…Multi

Bugfixes:
- darwin: GetConfig returned SOCKS with http:// scheme instead of socks5://
- WithProxy restored only the HTTP field; now snapshots and restores the full
  ProxyConfig (HTTP, HTTPS, SOCKS, NoProxy, PAC) via GetConfig + SetMulti/SetPAC

New API (additive, backwards compatible):
- ErrProxyNotSet, ErrProxyNotEnabled, ErrUnsupportedPlatform, ErrToolMissing
  sentinel errors, matchable via errors.Is
- RequiresElevation(err) alongside IsNonCritical(err) — distinguishes
  "sudo would have helped" from generic partial success
- ProxyConfig.PAC — populated by GetConfig when the OS is in auto-proxy mode
  on all four platforms (macOS -getautoproxyurl, Windows AutoConfigURL,
  GNOME autoconfig-url, KDE Proxy Config Script)
- WithProxyMulti — multi-protocol variant of WithProxy with the same
  full-config restore semantics

KDE (Linux):
- getGlobalKDE / getGlobalConfigKDE via kreadconfig5 / kreadconfig6
- Falls back from GNOME when gsettings is unavailable or mode=none
- ProxyType mapping: 0=none, 1=manual, 2=PAC

Tests:
- FuzzParse, FuzzValidateProxyURL, FuzzValidatePACURL
- internal/buildinfo covered 0% -> 100%
- KDE normalize helpers, parseAutoProxyOutput,
  parseWindowsProxyServer / extractRegValue (moved to build-tag-free file so
  they run on every platform)
- Coverage: main package 74.7% -> 75.4%
Copilot AI review requested due to automatic review settings July 4, 2026 11:36
@github-actions github-actions Bot merged commit 4cd482b into main Jul 4, 2026
24 of 25 checks passed
@codecov

codecov Bot commented Jul 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 40.52632% with 113 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
kde_linux.go 22.22% 49 Missing ⚠️
sysproxy_linux.go 0.00% 47 Missing ⚠️
sysproxy.go 53.12% 8 Missing and 7 partials ⚠️
windows_parse.go 92.59% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

Copilot AI left a comment

Copy link
Copy Markdown

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 evolves sysproxy v0.5 by adding additive APIs (sentinel errors, ProxyConfig.PAC, WithProxyMulti, elevation classification), improving cross-desktop Linux support (KDE read-back), and enhancing GetConfig to surface PAC configuration across platforms while adding broader tests (unit + fuzz).

Changes:

  • Add sentinel errors (ErrProxyNotSet, ErrProxyNotEnabled, ErrUnsupportedPlatform, ErrToolMissing) plus RequiresElevation, and update callers/tests to use errors.Is.
  • Add ProxyConfig.PAC, implement PAC detection in GetConfig (macOS/Windows/GNOME/KDE), and add WithProxyMulti with full-config snapshot/restore.
  • Add KDE (Plasma 5/6) Get/GetConfig via kreadconfig{5,6}, plus new fuzz tests for parsing/validation surfaces.

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
windows_parse.go Introduces parsing helpers for Windows registry proxy values.
windows_parse_test.go Unit tests for Windows parsing helpers.
sysproxy.go Expands ProxyConfig with PAC and adds snapshot-based WithProxy* restore logic + WithProxyMulti.
sysproxy_windows.go Adds PAC read-back (AutoConfigURL) and sentinel error returns for Windows Get/GetConfig.
sysproxy_test.go Updates WithProxy tests to validate full snapshot/restore behavior, adds WithProxyMulti tests.
sysproxy_other.go Wraps unsupported-platform errors with sentinel ErrUnsupportedPlatform.
sysproxy_linux.go Adds KDE read-back fallback, sentinel errors, and GNOME auto-mode PAC support in GetConfig.
sysproxy_darwin.go Fixes SOCKS scheme in GetConfig and adds PAC read-back on macOS.
sysproxy_darwin_test.go Adds tests for parsing networksetup -getautoproxyurl output.
README.md Documents ProxyConfig.PAC, WithProxy full snapshot behavior, WithProxyMulti, and sentinel error usage.
kde_linux.go New KDE (kioslaverc) reader helpers for Get/GetConfig.
kde_linux_test.go Unit tests for KDE URL normalization helpers.
internal/buildinfo/buildinfo_test.go Adds coverage for buildinfo Summary() defaults/overrides.
fuzz_test.go Adds fuzz tests for parse/validation functions to ensure no panics and consistent acceptance.
errors.go Defines sentinel errors and elevation classification (RequiresElevation).
errors_test.go Tests sentinel distinctness and elevation classification helpers.
appconfig.go Wraps “tool missing” errors with ErrToolMissing for git/npm helpers.
appconfig_test.go Updates tests to assert errors.Is(err, ErrToolMissing) for missing tools.

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

Comment thread sysproxy.go
Comment on lines +289 to +303
if snap.PAC != "" {
if err := SetPAC(snap.PAC, scope); err != nil && !IsNonCritical(err) {
logf("WithProxy: restore SetPAC failed: %v", err)
}
return
}
if snap.HTTP == "" && snap.HTTPS == "" && snap.SOCKS == "" {
if err := Unset(scope); err != nil && !IsNonCritical(err) {
logf("WithProxy: restore Unset failed: %v", err)
}
return
}
if err := SetMulti(snap, scope); err != nil && !IsNonCritical(err) {
logf("WithProxy: restore SetMulti failed: %v", err)
}
Comment thread sysproxy_windows.go
Comment on lines +105 to 111
func readAutoConfigURL(ctx context.Context) (string, error) {
out, err := exec.CommandContext(normalizeContext(ctx), "reg", "query", regKey, "/v", "AutoConfigURL").Output()
if err != nil {
return "", nil //nolint:nilerr
}
return extractRegValue(string(out), "AutoConfigURL"), nil
}
Comment thread sysproxy_windows.go
Comment on lines 158 to 164
server := extractRegValue(string(out), "ProxyServer")
if server == "" {
return ProxyConfig{}, fmt.Errorf("sysproxy: proxy not set")
return ProxyConfig{}, ErrProxyNotSet
}
cfg := parseWindowsProxyServer(server)
cfg.PAC = pac

Comment thread sysproxy_darwin.go
Comment on lines +159 to +161
if pac, ok := readMacPAC(ctx, svc); ok {
cfg.PAC = pac
}
Comment thread sysproxy_linux.go
Comment on lines +79 to +80
return "", ErrProxyNotSet
}
Comment thread sysproxy_linux.go
Comment on lines +144 to +145
return ProxyConfig{}, ErrProxyNotSet
}
Comment thread README.md
Comment on lines 133 to +137
"proxy not set" / "proxy not enabled" even though PAC is active.

### Temporary proxy

`WithProxy` sets the proxy for the duration of `fn` and restores the previous state on return — even if `fn` returns an error.
`WithProxy` sets the proxy for the duration of `fn` and restores the previous state on return — even if `fn` returns an error. The snapshot covers the full `ProxyConfig` (HTTP + HTTPS + SOCKS + NoProxy + PAC), not just the HTTP field.
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.

2 participants