fix(activate): unset inherited hook session vars in IDE env resolution#660
fix(activate): unset inherited hook session vars in IDE env resolution#660
Conversation
Agent-Logs-Url: https://github.com/version-fox/vfox/sessions/eb1376c6-75a6-4fc0-8963-99d748132fa2 Co-authored-by: bytemain <13938334+bytemain@users.noreply.github.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #660 +/- ##
==========================================
- Coverage 25.03% 24.13% -0.91%
==========================================
Files 82 82
Lines 5667 7088 +1421
==========================================
+ Hits 1419 1711 +292
- Misses 4072 5201 +1129
Partials 176 176 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR fixes a VS Code/IDE integrated-terminal activation bug caused by hook session variables leaking into IDE environment resolution shells, leading to reuse of a parent shell’s cached PATH/session state instead of recomputing per-project activation.
Changes:
- In IDE environment resolution mode, explicitly emit unsets for
__VFOX_SHELL,__VFOX_PID, and__VFOX_CURTMPPATH(vianilvalues inenv.Vars) instead of merely omitting them. - Update the IDE-resolution activation test to assert
unset KEY;is present and that the keys are not re-exported.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| cmd/commands/activate.go | Ensures IDE env-resolution output explicitly unsets inherited hook session variables before returning export-only script. |
| cmd/commands/activate_test.go | Tightens assertions to require explicit unset statements and prevent re-export of hook session vars. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Agent-Logs-Url: https://github.com/version-fox/vfox/sessions/ccde2a17-bb9e-45b2-88f5-5728e70126b4 Co-authored-by: bytemain <13938334+bytemain@users.noreply.github.com>
|
@aooohan 我验证了这个修复没有问题 |
In VSCode integrated terminals, project-scope SDK versions still aren't activated on 1.0.10 —
vfox currentreports the project version butnode -vresolves to the global one.Root cause
VSCode resolves the shell environment by spawning a login shell with
VSCODE_RESOLVING_ENVIRONMENT=1, inheriting its ownprocess.envinto that shell. When VSCode is launched from a terminal where vfox was already activated,__VFOX_PID/__VFOX_SHELL/__VFOX_CURTMPPATH(and on PowerShell,__VFOX_INITIALIZED) ride along.renderActivateScript's IDE-resolution branch only omitted these vars from its output — it never unset them. So:vfox activatesees__VFOX_PID, treats it as a live hook session, andenv.GetPid()returns the parent shell's PID.SessionSdkDirandenv-state.jsonare therefore the parent shell's — the precmd hook returns the parent's cached PATH (typically global-only) instead of recomputing for the project.__VFOX_INITIALIZEDadditionally causes integrated terminals to skip prompt-hook registration entirely.This explains the asymmetry:
vfox currentreads.vfox.tomldirectly, whilenoderesolves through the leaked cached PATH.Changes
internal/env/flag.go: addInitializedFlagconstant for__VFOX_INITIALIZEDso the hook session keys live in one place.cmd/commands/activate.go: in theIsIDEEnvironmentResolution()branch ofrenderActivateScript, explicitly emitnil(→unset) forenv.HookFlag,env.PidFlag,env.InitializedFlag, andpathmeta.HookCurTmpPathinstead of just dropping them from the map. The resolution shell exits with a sanitized environment, so each integrated terminal starts a fresh hook session bound to its own PID and session dir, and PowerShell hook registration runs as expected.cmd/commands/activate_test.go: tightenTestRenderActivateScriptForIDEEnvironmentResolutionSkipsHookSessionStateto assertunset KEY;is present (and the keys are never re-exported) for all four hook session vars rather than merely absent.