Pewarta Proxy

📋 Server Request & Proxy Logs

Loading active proxy settings...
Developed by Khairul Adha (adhexa.id)
Mengambil log server...

⚙️ Pengaturan Proxy Target

Skip to content

Fix Go module cache default read two ways (#1834) - #1876

Open
Mikola Lysenko (mikolalysenko) wants to merge 3 commits into
mainfrom
agent/fix-go-modcache-default
Open

Mikola Lysenko (mikolalysenko) wants to merge 3 commits into
mainfrom
agent/fix-go-modcache-default

Conversation

@mikolalysenko

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

Copy link
Copy Markdown
Collaborator

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

Fixes #1834

Summary

Before this PR, the Go crawler (GoCrawler::get_gomodcache, which apply, scan and the workspace graph reader use) and the stale-installed-tool audit (go_installed_tools::bin_dirs_with) each worked out the module cache from GOMODCACHE / GOPATH themselves. The two copies disagreed with each other and with go:

Setting go 1.24 GOMODCACHE crawler before audit before now
GOPATH=/a:/b /a/pkg/mod /a/pkg/mod /a/pkg/mod /a/pkg/mod
GOPATH=:/a none ("module cache not found") /a/pkg/mod /a/pkg/mod none
GOPATH=: none $HOME/go/pkg/mod none none
GOMODCACHE=rel refused ("must be absolute path") ./rel under CWD rel none
GOPATH=/a:rel or /a:~/x go refuses to run /a/pkg/mod /a/pkg/mod none
unset $HOME/go/pkg/mod same same same

Every "go" cell was checked with real go 1.24.7, using go env GOMODCACHE and a go mod download from a file GOPROXY.

The issue proposed falling back to the home default for a GOPATH of only empty entries. go doesn't do that. cfg.gopathDir reads only list[0], and an empty entry there means go has no module cache. So this PR follows go instead.

Change

  • utils/go_env.rs: gopath_entries (go's GOPATH list, with the $HOME/go default) and gomodcache (the rules in the table) are now the only implementation.
  • GoCrawler::get_gomodcache and bin_dirs_with call them. The redundant empty filters on go_env results are gone. bin_dirs_with keeps one filter at its injected-lookup boundary, because it's pub.
  • No wrapper changes: npm/, pypi/ and gem/ only dispatch to the binary.

Tests (red → green)

Facet Test main this PR
Crawler: an empty first GOPATH entry (:/a, :) gives no cache, and a relative GOMODCACHE gives no cache go_crawler::tests::test_get_gomodcache_empty_env_fallback_chain FAIL: left: Some("/tmp/.tmp…/pkg/mod") right: None pass
Audit: GOPATH=:/b puts no copy in the user's cache, so GOBIN isn't searched go_installed_tools::tests::bin_dirs_follow_gobin_then_gopath_then_home_and_the_cache_root FAIL: left: ["/gobin", "/b/bin"] right: ["/b/bin"] pass
Helpers: GOMODCACHE set, multi-entry GOPATH, empty entries, no GOPATH, relative and ~ entries go_env::tests::gomodcache_follows_go (new helper) pass

Case A of the crawler test used to assert that an empty first entry is skipped in favor of the next one. That was the divergence the issue describes, so the test now asserts what go does. Its original guarantee, never a path relative to CWD, still holds.

Commands run locally:

  • cargo fmt --all -- --check: clean
  • cargo clippy --workspace --all-features -- -D warnings: clean
  • cargo test -p socket-patch-core --all-features --lib: 6995 pass. The 4 failures are the known root-sandbox permission tests the other agent PRs also see (copy_tree::relax_loop_must_not_traverse_symlinked_root, vlt_heal::an_unremovable_hidden_lock_keeps_every_store_entry, pypi_poetry::wire_write_failure_…, pypi_requirements::wire_failure_rolls_back_…). None of them touches Go.
  • cargo test -p socket-patch-cli --all-features --lib --bins: 940 pass
  • cargo test -p socket-patch-core --test crawler_go_e2e: 19 pass
  • The go-compatibility workflow's real-go suites with go 1.24.7: e2e_golang_build 31, e2e_golang_hosted_build 25, e2e_golang_workspace_build 31, e2e_vendor_golang_build 44, e2e_vex_lockfile golang:: 24, all pass.
  • The rest of the CLI integration suites didn't fit in this sandbox's disk allowance, so CI runs them.

Per-issue checklist

  • Resolve GOPATH and GOMODCACHE through one go_env helper instead of two drifting copies #1834: one helper pair in utils/go_env.rs, used by both callers, with the redundant filters removed. Covered by gomodcache_follows_go, test_get_gomodcache_empty_env_fallback_chain and bin_dirs_follow_gobin_then_gopath_then_home_and_the_cache_root.
  • Normal environments are unchanged: the existing crawler, workspace and installed-tool tests and the real-go e2e suites pass as-is.

/code-review high

Fixed in cc81e3b:

  • An empty GOBIN or GOMODCACHE / GOPATH from an injected lookup counted as set. The helpers now treat it as unset whatever lookup they're given.
  • A relative or ~ GOPATH entry after the first was accepted, though go refuses the whole setting.
  • A stale doc comment in tests/crawler_go_e2e.rs.

Not changed:

  • No diagnostic when go has no module cache. GOPATH=:/b now crawls nothing instead of /b/pkg/mod. go itself can't download into or build from a cache there, so nothing in the build came from it. Adding a warning would be a separate UX change.
  • Every GOPATH entry's bin is still searched for stale tools. That predates this PR, and searching more directories only widens the audit.
  • bin_dirs_with resolves GOPATH twice, once directly and once inside gomodcache. That's one small extra env-file read per audit, which I kept in exchange for a single shared rule.

https://claude.ai/code/session_011f9aePZXiQWURg2M6sbh88


Generated by Claude Code

Assisted-by: Claude Code:claude-opus-5-5
The crawler and the installed-tool audit each worked out the Go
module cache from GOMODCACHE and GOPATH, and the two copies
disagreed with each other and with go. With GOPATH=":/a" the
crawler patched /a/pkg/mod, and with GOPATH=":" it fell back to
~/go/pkg/mod, but go itself reads only the first GOPATH entry, so
both settings leave go with no module cache at all. A relative
GOMODCACHE, which go refuses, was crawled under the working
directory.

Both callers now use go_env::gomodcache and gopath_entries, which
follow go's cfg.gopathDir (checked against go 1.24's go env and
go mod download).

Assisted-by: Claude Code:claude-opus-5-5
go exits when any GOPATH entry is relative or starts with ~, even
with GOMODCACHE set, so there is no module cache to crawl or audit
then. Empty settings count as unset in the shared helpers and in
the installed-tool audit, whatever lookup the caller passes.

Assisted-by: Claude Code:claude-opus-5-5
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review October 30, 2026 04:01
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

BugBot review


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 cc81e3b. Configure here.

@mikolalysenko Mikola Lysenko (mikolalysenko) added the Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review label Oct 30, 2026
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

Ready for review (burn-down agent).

  • Head: cc81e3b, mergeable with no conflicts against main 5ca5623
  • CI: 32/32 checks green (50 skipped by the lean PR matrix), no failures
  • Bugbot: reviewed cc81e3b, no findings; no open review threads
  • What to check: behaviour change. A GOPATH whose first entry is empty (:/a), or a relative GOMODCACHE, now resolves to no module cache, matching go 1.24. Before, it fell back to a later entry.
  • Slack: not announced. The Slack send action wasn't available in this run.

Generated by Claude Code

@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

Burn-down agent: labeled Ready for review at cc81e3b.

  • CI: 82/82 checks green on this head; no main-wide failures.
  • Bugbot: reviewed cc81e3b, no findings; no open review threads.
  • Mergeable: yes, no conflicts with main.

Generated by Claude Code

@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

Final review brief (cc81e3b)

What it does: Go module-cache resolution used to live in two places: the crawler's get_gomodcache and the stale-tool audit's bin_dirs_with. This PR replaces both with shared gopath_entries and gomodcache helpers that follow go's own rule. GOMODCACHE wins; otherwise the first GOPATH entry is used, otherwise $HOME/go. Setups that go itself rejects now resolve to no cache instead of a guessed path: an empty first GOPATH entry, a relative or ~ entry, or a relative GOMODCACHE.

Risk: low. Ordinary setups (unset, an absolute GOPATH with one or several entries, an absolute GOMODCACHE) resolve exactly as on main. The only behaviour changes are the invalid configurations listed in the PR's table. For example, GOPATH=:/a no longer crawls /a/pkg/mod.

Look here:

  • go_env.rs:43-78: the new shared helpers.
  • go_crawler.rs:187-192:`` the crawler now calls the helper.
  • go_installed_tools.rs:176-188:``` bin_dirs_with now treats an empty value as unset.
  • Tests: go_env.rs:227-268 and go_crawler.rs:1541-1591.````

Verified:

  • Targeted lib tests (gomodcache, bin_dirs, go_env): 9 passed. crawler_go_e2e: 19 passed.
  • Red check: with main's source for both functions and the PR's tests, 2 tests fail (test_get_gomodcache_empty_env_fallback_chain, bin_dirs_follow_gobin_then_gopath_then_home_and_the_cache_root). The tests catch the bug.
  • CI is 82/82 green (32 success, 50 skipped). Bugbot is clean on this head.
  • CHANGELOG.md is untouched, there is no debug code, and the scope is the 4 files.

Open questions (non-blocking):

  • gomodcache_follows_go is #[cfg(unix)], so the Windows ; separator isn't unit-tested. split_paths and is_absolute should match go there.
  • When go has no module cache, the crawler now silently finds nothing. The PR defers adding a warning; this may be worth a follow-up.

Auto-merge is armed, so approving sends this PR straight to the merge queue.


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Resolve GOPATH and GOMODCACHE through one go_env helper instead of two drifting copies

2 participants