jdx / mise

dev tools, env vars, task runner
https://mise.jdx.dev
MIT License
8.07k stars 211 forks source link

Some tools installed via Go backend result in incorrect installed versions reported #2253

Closed stuarthicks closed 3 weeks ago

stuarthicks commented 1 month ago

Describe the bug

There appears to be some sort of plugin/toolset naming issue when using the Go backend. It impacts some Go tools but not others (I'm not sure what exactly the trigger is), and results in some mise commands showing multiple toolsets, with some entries being invalid.

To Reproduce

mise use -g go:github.com/oligot/go-mod-upgrade@latest

Then look at mise ls (I've removed lines from other installed tools to keep the output tidier, but the full list of tools is in the mise doctor output below, if relevant):

❯ mise ls
Plugin                                     Version           Config Source              Requested
go:github.com/oligot/go-mod-upgrade        0.10.0            ~/.config/mise/config.toml latest
go:github.com/oligot/go/mod/upgrade        0.10.0

The go-mod-upgrade tool has been added twice, and mise prune will incorrectly attempt to remove the "inactive" version (which then removes both entries).

Expected behavior I expected only a single entry to be installed, matching this line:

go:github.com/oligot/go-mod-upgrade        0.10.0            ~/.config/mise/config.toml latest

mise doctor output

version: 2024.6.1 macos-arm64 (2024-06-03)
activated: yes
shims_on_path: no

build_info: 
  Target: aarch64-apple-darwin
  Features: DEFAULT, NATIVE_TLS
  Built: Mon, 3 Jun 2024 22:51:04 +0000
  Rust Version: rustc 1.78.0 (9b00956e5 2024-04-29) (Homebrew)
  Profile: release

shell: 
  /bin/zsh
  zsh 5.9 (x86_64-apple-darwin23.0)

dirs: 
  data: ~/.local/share/mise
  config: ~/.config/mise
  cache: ~/Library/Caches/mise
  state: ~/.local/state/mise
  shims: ~/.local/share/mise/shims

config_files: 
  ~/.config/mise/config.toml

backends: 
  cargo
  core
  go
  npm
  pipx
  spm
  ubi

plugins: 
  bun     (core)
  deno    (core)
  erlang  (core)
  go      (core)
  java    (core)
  node    (core)
  poetry  https://github.com/mise-plugins/mise-poetry.git#431c335
  python  (core)
  ruby    (core)
  rust    https://github.com/code-lever/asdf-rust.git#95acf4f
  usage   https://github.com/jdx/mise-usage.git#fe3888a
  zig     (core)

toolset: 
  cargo:cargo-binstall@1.6.7  
  cargo:rustreleaser@0.1.6  
  go:github.com/maruel/panicparse/v2/cmd/pp@2.3.1  
  go:github.com/oligot/go-mod-upgrade@0.10.0  
  npm:prettier@3.2.5    
  pipx:terminaltexteffects@0.9.3  
  go@1.22.3             
  node@22.2.0           
  python@3.12.3         
  ruby@3.3.2            
  rust@1.78.0           
  usage@0.3.0           

env_vars: 
  MISE_SHELL=zsh

settings: 
  activate_aggressive = false
  all_compile = false
  always_keep_download = false
  always_keep_install = false
  asdf_compat = false
  cargo_binstall = true
  color = true
  disable_default_shorthands = false
  disable_tools = []
  experimental = true
  go_default_packages_file = "~/.default-go-packages"
  go_download_mirror = "https://dl.google.com/go"
  go_repo = "https://github.com/golang/go"
  go_set_gopath = false
  go_set_goroot = true
  go_skip_checksum = false
  http_timeout = 30
  jobs = 4
  legacy_version_file = true
  legacy_version_file_disable_tools = []
  node_compile = false
  not_found_auto_install = true
  paranoid = false
  plugin_autoupdate_last_check_duration = "7d"
  python_default_packages_file = "/Users/stuart/.default-python-packages"
  python_pyenv_repo = "https://github.com/pyenv/pyenv.git"
  raw = false
  trusted_config_paths = []
  quiet = false
  verbose = false
  yes = false
  ci = false
  debug = false
  trace = false
  log_level = "info"
  python_venv_auto_create = false

  [status]
  missing_tools = "if_other_versions_installed"
  show_env = false
  show_tools = false

No warnings found
No problems found

Additional context

❯ mise use -g go:github.com/oligot/go-mod-upgrade@latest --debug --trace
[DEBUG] ARGS: /opt/homebrew/bin/mise use -g go:github.com/oligot/go-mod-upgrade@latest --debug --trace
[DEBUG] Config {
    Config Files: [
        "~/.config/mise/config.toml",
    ],
}
[DEBUG] ToolRequestSet.build(58.708µs): ToolRequestSet: cargo:cargo-binstall@latest cargo:rustreleaser@latest go:github.com/maruel/panicparse/v2/cmd/pp@latest go:github.com/oligot/go-mod-upgrade@latest npm:prettier@latest pipx:terminaltexteffects@latest go@latest node@latest python@latest ruby@latest rust@latest usage@latest

[DEBUG] Toolset (1.12475ms): cargo:cargo-binstall@latest, cargo:rustreleaser@latest, go:github.com/maruel/panicparse/v2/cmd/pp@latest, go:github.com/oligot/go-mod-upgrade@latest, npm:prettier@latest, pipx:terminaltexteffects@latest, go@latest, node@latest, python@latest, ruby@latest, rust@latest, usage@latest
[DEBUG] install_versions: go:github.com/oligot/go-mod-upgrade@latest
[DEBUG] $ go install github.com/oligot/go-mod-upgrade@v0.10.0
mise go:github.com/oligot/go-mod-upgrade@0.10.0 ✓ installed
[DEBUG] Toolset (397.708µs): cargo:cargo-binstall@latest, cargo:rustreleaser@latest, go:github.com/maruel/panicparse/v2/cmd/pp@latest, go:github.com/oligot/go-mod-upgrade@latest, npm:prettier@latest, pipx:terminaltexteffects@latest, go@latest, node@latest, python@latest, ruby@latest, rust@latest, usage@latest
mise ~/.config/mise/config.toml tools: go:github.com/oligot/go-mod-upgrade@0.10.0

No obvious cause in the --debug or --trace output. The installed tool works correctly, so this is purely a presentation issue. For what it's worth, while I've raised this issue from macOS, the same behaviour reproduces on my other machine, which is Fedora Linux (via Windows Subsystem for Linux).

roele commented 3 weeks ago

It seems that i am not able to reproduce this via mise use -g go:github.com/oligot/go-mod-upgrade@latest. As i recall such entries are not cached but it might not hurt trying to clear the cache via mise cache clear.

What you describe could stem from old behaviour. Backends (e.g. Go modules) are renamed when downloaded to ~/.local/share/mise/installs. Slashes and other special characters are replaced with dashes, so github.com/oligot/go-mod-upgrade becomes go-github-com-oligot-go-mod-upgrade. With this renaming mise cannot derive the plugin name from the generated directory name especially for module names with dashes. For this reason a meta file has been introduced. When listing backends mise should read from this meta file or falls back to old behaviour trying to derive from the directory name which might lead to the behaviour you see.

Can you check if that meta file exists and has expected content?

cat ~/.local/share/mise/installs/go-github-com-oligot-go-mod-upgrade/.mise.backend.json
{"id":"go:github.com/oligot/go-mod-upgrade","name":"github.com/oligot/go-mod-upgrade","backend_type":"go"}

Removing and re-installing the tool should fix the issue.

stuarthicks commented 3 weeks ago

Hmm. I don't see a .mise.backend.json:

❯ cat ~/.local/share/mise/installs/go-github-com-oligot-go-mod-upgrade/.mise.backend.json

cat: /Users/stuart/.local/share/mise/installs/go-github-com-oligot-go-mod-upgrade/.mise.backend.json: No such file or directory
zsh: exit 1     cat

However, I do see two directories in the install dir for that tool, and both contain a .mise.forge.json file:

❯ cat ~/.local/share/mise/installs/go-github-com-oligot-go-mod-upgrade/.mise.forge.json
{"id":"go:github.com/oligot/go-mod-upgrade","name":"github.com/oligot/go-mod-upgrade","forge_type":"go"}                 

❯ cat ~/.local/share/mise/installs/go-github.com-oligot-go-mod-upgrade/.mise.forge.json
{"id":"go:github.com/oligot/go-mod-upgrade","name":"github.com/oligot/go-mod-upgrade","forge_type":"go"}                                                                               

Uninstalling and then reinstalling the tool in this state does not seem to fix the issue:

❯ mise ls |& grep upgrade
go:github.com/oligot/go/mod/upgrade        0.10.0
go:github/com/oligot/go/mod/upgrade        0.10.0

❯ mise uninstall go:github.com/oligot/go-mod-upgrade
mise go:github.com/oligot/go-mod-upgrade@0.10.0 ✓ uninstalled                                                                                                                              

❯ mise ls |& grep upgrade
zsh: done       mise ls 2>&1 |
zsh: exit 1     grep upgrade

❯ mise install go:github.com/oligot/go-mod-upgrade@0.10.0
mise go:github.com/oligot/go-mod-upgrade@0.10.0 ✓ installed                                                                                                                                

❯ mise ls |& grep upgrade
go:github.com/oligot/go-mod-upgrade        0.10.0
go:github.com/oligot/go/mod/upgrade        0.10.0

I've also attempted mise cache clear (with the tool uninstalled as well), and that also did not fix the issue, the duplicate tool entry reappears as soon as the tool is reinstalled (the forge json files and those two install dirs continue to exist).

From your description, it certainly sounds plausible that go-mod-upgrade was installed initially with a previous version of mise with a different install directory name, and at some point the new install directory has been created.

I've managed to resolve this by uninstalling the tool, manually deleting all the install directories for it, and then reinstalling it, although it would be helpful I guess if mise were able to identify/clear that invalid state itself (either clear it with mise cache clear or report it in mise doctor).

As a strategy for identifying this issue, seeing if there are multiple forge json files that contain the same metadata seems to work reliably. eg in bash:

❯ find ~/.local/share/mise/installs -maxdepth 2 -type f -name .mise.forge.json | while read -r forge; do jq -r '[.forge_type, .id, .name] | @tsv' "${forge}"; done | sort | uniq -c | sort -nr | grep -v '^\s*1' | column -t
2  go  go:github.com/oligot/go-mod-upgrade        github.com/oligot/go-mod-upgrade
2  go  go:github.com/maruel/panicparse/v2/cmd/pp  github.com/maruel/panicparse/v2/cmd/pp

The go-mod-upgrade tool (and the panicparse tool) were both in this state on my machine (before I fixed it by clearing out these dirs myself):

❯ ls -1 .local/share/mise/installs | grep -E '(upgrade|panicparse)'
go-github-com-maruel-panicparse-v2-cmd-pp
go-github-com-oligot-go-mod-upgrade
go-github.com-maruel-panicparse-v2-cmd-pp
go-github.com-oligot-go-mod-upgrade

Sorry for the wall of text. I understand if you decide this isn't a bug since it only occurs with state from old mise versions. If nothing else, perhaps this issue will show in in search results for anyone else who finds this same thing happening with their mise setup.

Thanks for your help!

roele commented 3 weeks ago

It seems some refactoring changes came in meanwhile with changes in the directory and meta data file naming, leading to this issue. So cleaning out these directories manually, is as of now the best way to resolve this. Given backends are still experimental i don't think its worth the effort to deal with potential upgrade paths and cleanups in the code at this point.

stuarthicks commented 3 weeks ago

Totally reasonable. I'll close this. Thanks again!