Skip to content

Honor Go settings written with go env -w (#344) - #1356

Merged
Mikola Lysenko (mikolalysenko) merged 3 commits into
mainfrom
agent/v5-go-env-file
Oct 9, 2026
Merged

Mikola Lysenko (mikolalysenko) merged 3 commits into
mainfrom
agent/v5-go-env-file

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator

LLM Description written by Claude Code:claude-opus-5-5

Fixes #344

Summary

socket-patch now reads Go settings saved with go env -w the same way the go command does. Before this, GOPRIVATE, GOPROXY and GOMODCACHE set that way were ignored, so:

  • private module paths were requested from proxy.golang.org
  • a configured mirror was bypassed
  • a relocated module cache was not found (apply reported "matched no installed package")

Root cause

goproxy_base (vendor/registry_fetch.rs), gosumdb_base (patch/redirect/upstream/client.rs) and the crawler's get_gomodcache / workspace_in_effect (crawlers/go_crawler.rs) all used std::env::var only. go resolves each setting from the environment, then from the Go environment file, then from its default.

Fix

New utils::go_env resolver, ported from cmd/go/internal/cfg:

  • A non-empty environment variable wins. An empty one falls through, as in go's cfg.Getenv.
  • Otherwise the value comes from the GOENV file: $GOENV when set (GOENV=off disables the file), else os.UserConfigDir()/go/env. That is $XDG_CONFIG_HOME or ~/.config on Linux, ~/Library/Application Support on macOS, and %AppData% on Windows.
  • The file is parsed like go's readEnvFile: KEY=VALUE lines, the last one for a key wins, and comments and lowercase lines are skipped.
  • Otherwise the caller's default applies.

All of GOPROXY, GONOPROXY, GOPRIVATE, GOSUMDB, GONOSUMDB, GOMODCACHE, GOPATH and GOWORK now go through it. CLI_CONTRACT.md documents the resolution order.

Out of scope: $GOROOT/go.env (Go 1.21+, the lowest layer). Upstream Go ships it with the built-in defaults, and finding it means running go.

Tests (red → green)

Commands run

  • cargo test -p socket-patch-core --lib -- go_crawler registry_fetch upstream::client go_env: green
  • cargo test -p socket-patch-cli --test e2e_golang --test spawn_env_hygiene: green
  • cargo clippy --workspace --all-features -- -D warnings: clean
  • cargo fmt --check: the changed files are clean

🤖 Generated with Claude Code


Note

Medium Risk
Changes how private modules, proxies, and module-cache paths are resolved for Go scan/patch and upstream restore; mis-parsing could leak private paths to public proxies or miss modules, but behavior is aligned with go and heavily tested.

Overview
Go settings from go env -w are now honored (#344), matching how the go toolchain resolves configuration instead of reading only process environment variables.

A new utils::go_env resolver applies env → $GOENV user file (GOENV=off disables; otherwise os.UserConfigDir()/go/env) → caller defaults, with go-style KEY=VALUE parsing. GOMODCACHE, GOPATH, GOWORK, GOPROXY / GONOPROXY / GOPRIVATE, and GOSUMDB / GONOSUMDB now route through it in the Go crawler, module-proxy upstream fetch, and checksum-database restore paths. CLI_CONTRACT.md documents this resolution order for registry-related Go knobs.

Tests add resolver and integration coverage (including an e2e scan that finds modules when GOMODCACHE lives only in the go env file); existing precedence tests pin GOENV=off so local developer files do not leak.

Reviewed by Cursor Bugbot for commit 9825ccf. Configure here.


Generated by Claude Code

socket-patch read GOPRIVATE, GOPROXY, GOMODCACHE and the other Go
settings only from the process environment. go itself also reads the
per-user file `go env -w` writes ($GOENV, default
os.UserConfigDir()/go/env), which is where the Go docs tell users to
put them. So a private module path set that way was requested from
proxy.golang.org, a configured mirror was bypassed, and a relocated
module cache was not found (apply: "matched no installed package").

A new utils::go_env resolver follows go's order: a non-empty
environment variable, then the GOENV file (GOENV=off disables it),
then the caller's default. goproxy_base, gosumdb_base, the crawler's
GOMODCACHE/GOPATH lookup and the GOWORK check now use it.

Fixes #344

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

BugBot review

@cursor cursor Bot 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.

Stale Bugbot comment from a previous run.

Comment thread crates/socket-patch-core/src/vendor/registry_fetch.rs
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

bugbot run


Generated by Claude Code

@cursor cursor Bot 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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 9825ccf. Configure here.

@mikolalysenko
Mikola Lysenko (mikolalysenko) added this pull request to the merge queue Oct 9, 2026
Merged via the queue into main with commit 1438b1a Oct 9, 2026
53 checks passed
@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the agent/v5-go-env-file branch October 9, 2026 22:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants