Skip to content

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

Open

Description

[agent] Filed by the scheduled architecture audit (audit-core). Register: register.

Kind: refactor. Register ID: A03.

Problem

The crate applies Go's default for "GOMODCACHE, else the first GOPATH entry's pkg/mod, else $HOME/go/pkg/mod" in two places, and the two copies differ:

  1. crawlers/go_crawler.rs#L185-L209 get_gomodcache takes the first non-empty GOPATH entry. If GOPATH has only empty entries (for example :), it falls through to fs::home_dir()/go/pkg/mod.
  2. utils/go_installed_tools.rs#L176-L186 builds gopaths, which comes out empty in the same case. It then gets user_cache = None and never falls back to the home default. It also re-filters go_env results with .filter(|v| !v.is_empty()), which does nothing because go_env already drops empty values.

So for the same environment, the crawler and the stale-installed-tool audit can disagree about which directory is the module cache.

Proposed change

  • Add pub(crate) fn gopath_entries(home: Option<&Path>) -> Vec<PathBuf> and pub(crate) fn gomodcache(home: Option<&Path>) -> Option<PathBuf> to utils/go_env.rs. That is about 20 lines, with one rule for empty entries and the home fallback.
  • Use them from both get_gomodcache and go_installed_tools, and delete the redundant empty filters.
  • Pick the behavior that matches go env GOMODCACHE for a GOPATH of only empty entries. Go treats it as unset, so fall back to the home default.

Size: 3 files, about +25/−25.

Acceptance criteria

  • No change for normal environments.
  • New unit tests on the helpers (injected env through go_env_with) cover: GOMODCACHE set, multi-entry GOPATH, GOPATH of only empty entries, and no GOPATH.
  • The existing go_crawler and go_installed_tools tests pass.

Activity

  1. added
    arch-auditFiled by a scheduled architecture audit routine (see the architecture review discussion)
    refactorStructural change: duplicated code or logic, missing abstraction, layering, dead code
    on Oct 29, 2026
  2. mikolalysenko commented on Oct 30, 2026

    @mikolalysenko
    CollaboratorAuthor

    [agent] Claiming this issue (shared root cause: the GOMODCACHE / GOPATH default is computed twice and the copies disagree on a GOPATH of only empty entries). Branch: agent/fix-go-modcache-default. Claim-ID: 2026-10-30T03:21:18Z-7c5386


    Generated by Claude Code

  3. mikolalysenko commented on Oct 30, 2026

    @mikolalysenko
    CollaboratorAuthor

    [agent] Draft PR: #1876


    Generated by Claude Code

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent:claimedagent:triagedarch-auditFiled by a scheduled architecture audit routine (see the architecture review discussion)priority:p2refactorStructural change: duplicated code or logic, missing abstraction, layering, dead code

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions