[BUG]: `vfox env` serves the cached output after a `cd`: a .nvmrc / .node-version is ignored on the way in and kept on the way out
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- Mezza giornata
- Idoneità per principianti
- 45/100
Direzione di ricerca
Start in envFlag in cmd/commands/env.go, where the cache check happens after loadToolChain in cmd/commands/tool_resolution.go has resolved the legacy file. Then read ConfigState.HasChanged in internal/env/state.go to see which inputs it compares. Choosing between the working-directory and resolved-tool-set options is a design call for maintainers. Done when cd between a .nvmrc directory and a plain directory switches node -v at once, and a test covers that transition.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Version
vfox 1.0.13 (release binary) and main at cdf0747 (2026-11-02, RuntimeVersion is still 1.0.13), with the nodejs plugin 0.5.3 from the registry. The two builds print the same lines in everything below.
OS
Linux (Ubuntu 26.04.1 on WSL2), bash 5.3.9, in a scratch HOME started with env -i. I ran only bash on Linux and only the nodejs plugin. The code involved depends on neither the shell nor the OS, and other plugins that declare legacyFilenames go through the same ParseLegacyFile call, so I expect the same elsewhere, but I have not tried.
Describe the bug
A legacy version file such as .nvmrc or .node-version takes effect when a shell starts in its directory, but not when you cd into that directory from a running shell. And a shell that started in such a directory stays on the file's version when you cd out of it, instead of going back to the global one. A .vfox.toml has neither problem.
At every prompt in such a directory vfox env still calls the plugin's ParseLegacyFile, so vfox does learn what the file says (Found [email protected] below). That answer is not what decides whether the cached output can be reused, so vfox prints the output it cached for the previous directory.
Steps to reproduce
legacyVersionFile.enable is true and legacyVersionFile.strategy is specified, the defaults.
$ vfox add nodejs
$ vfox install [email protected]
$ vfox install [email protected]
$ vfox use -g [email protected]
$ mkdir -p ~/demo/plain ~/demo/with-nvmrc ~/demo/with-toml
$ printf '18.20.8\n' > ~/demo/with-nvmrc/.nvmrc
$ printf '[tools]\nnodejs = "18.20.8"\n' > ~/demo/with-toml/.vfox.toml
Going in: a bash that starts in plain, then cds into the directory with the .nvmrc. The directory with the .vfox.toml switches right away, for comparison:
$ cd ~/demo/plain
$ eval "$(vfox activate bash)"
$ node -v
v26.13.0
$ cd ../with-nvmrc
$ cat .nvmrc
18.20.8
$ node -v
v26.13.0
$ vfox --debug env -s bash 2>&1 | grep -o -E "Parsing legacy file [^ ]+|Found nodejs@[0-9.]+|Config changed: [a-z]+|Using cached output"
Parsing legacy file /home/me/demo/with-nvmrc/.nvmrc
Found [email protected]
Config changed: false
Using cached output
$ cd ../with-toml
$ cat .vfox.toml
[tools]
nodejs = "18.20.8"
$ node -v
v18.20.8
Going out: a bash that starts in the directory with the .nvmrc, then cds to plain:
$ cd ~/demo/with-nvmrc
$ eval "$(vfox activate bash)"
$ node -v
v18.20.8
$ cd ../plain
$ node -v
v18.20.8
$ vfox --debug env -s bash 2>&1 | grep -o -E "Parsing legacy file [^ ]+|Found nodejs@[0-9.]+|Config changed: [a-z]+|Using cached output"
Config changed: false
Using cached output
Root cause
envFlag (cmd/commands/env.go#L147-L197) decides whether it can reuse the output it cached for this shell:
- It first calls
loadToolChain(cmd/commands/tool_resolution.go#L31-L52), which reads the config files and callsParseLegacyFilefor the current directory. A legacy result only goes into the in-memory project config. configPathsthen lists only the vfox config files that exist (L154-L164). A directory with only a.nvmrchas no project config file, so the project entry is empty on both sides of thecd.ConfigState.HasChanged(internal/env/state.go#L112-L164) compares that project path with the last one,PATHwith the cachedPATH, and the modification time of each tracked file with the stored one. In the transcripts none of the three differs (Config changed: false), andenvFlagprints the cached output (L189-L197).
So the version file, and the directory it is read from, are inputs of the output that the cache does not know about. AGENTS.md already states the principle for path.mode: the cached output is keyed by the PATH policy "because config.yaml is not among the files whose modification time is tracked; a setting that changes the PATH order has to be part of that key" (L113), and it says that loadToolChain "reads the version files, legacy ones included, for env, activate and doctor" (L90).
Expected behavior
After cd ../with-nvmrc, node -v prints v18.20.8, and after cd ../plain from there it prints v26.13.0 again, as the directory with the .vfox.toml does.
Possible fix
env runs at every prompt (AGENTS.md), so both ideas below are comparisons of values that envFlag already has:
- Keep the working directory in the state, the way
CachedPathPolicykeeps the PATH policy, and count a different directory as a change. I tried this on v1.0.13: 55 added lines with a test (ConfigState.DirChangedandSetDir, used inenvFlag). A shell that went into a.nvmrcdirectory, a.node-versiondirectory, a plain directory, two.vfox.tomldirectories and a plain directory again came out right at every step, going out included, also with plugin 0.5.3. It does not notice an edit of the version file in the directory the shell is already in. - Keep what
loadToolChainresolved (the tool and version pairs, legacy ones included) and count a different set as a change.envFlaghas it before the cache check, so it needs no list of files per plugin, and it should also catch an edit in place. I have not tried this one.
- Lingua principale
- Go
- Stelle
- 4k
- Fork
- 167
- Merge medio
- 2g 10h
- PR unite (30g)
- 8
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di version-fox/vfox
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
version-fox/vfox#746 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement help wanted
Difficoltà 3/5 1-2 giorni Idoneità per principianti 70/100
version-fox/vfox#743 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Follow-ups of #736: plugin updates, the path.mode default and vfox configForse già presa @linghengqian l’ha presa 14 giorni fa. Apertaplan plugin
version-fox/vfox#737 · 1 commento · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
[Feature]: Improve the E2E experience for certain plugin repositories on Windows containersForse già presa @linghengqian l’ha presa 15 giorni fa. Apertaenhancement
version-fox/vfox#733 · 2 commenti · 2 reazioni · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
[BUG]: On Windows, `vfox use java@X` doesn't change `java` when a JDK is in the system PATH and a global SDK is setForse già presa @linghengqian l’ha presa 14 giorni fa. Apertabug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 47/100
version-fox/vfox#732 · 2 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di version-fox/vfox
Issue simili
-
needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
enhancement needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
valkey-io/valkey-operator#610 ·
I maintainer di solito rispondono entro 3 giorni
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
-
WriterSetTimes: the UTIME_NOW check fails when the kernel uses its coarse clockForse già presa @JakeChampion l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
JakeChampion/lang#14224 ·
I maintainer di solito rispondono entro 1 giorno
-
agent-butler-finding bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
jordansmall/spindrift#6391 ·
I maintainer di solito rispondono entro 1 giorno