Repository navigation
fix EnvironmentScope previous-value capture on windows - #18523
Conversation
The core gtest added in #18520 (EnvironmentTest.EnvironmentScopeRestoresPreviousValue) fails deterministically on Windows, turning the ide-os-windows pipeline red: EnvironmentScope captured the previous value with raw ::getenv, which reads the CRT's startup snapshot of the environment, while core::system::setenv writes the process environment block via SetEnvironmentVariableW. A variable set through core::system::setenv was therefore invisible to the scope, which unset it on destruction instead of restoring it. Add a core::system::getenv overload that reports whether the variable is set (preserving the unset vs set-but-empty distinction #18520 wanted) and reads the same store the setters write on both platforms, and use it in EnvironmentScope. This also removes the last raw ::getenv from the public header, along with the stdlib.h and EnvironmentLock.hpp includes it needed. The pre-existing Windows brokenness never had production impact: the only non-test EnvironmentScope user is Apple-only (SourceIndex.cpp), and XdgTests.cpp is compiled out on Windows -- the #18520 test was the first code to exercise EnvironmentScope there.
RStudio E2E - all platforms1 test(s) failed
View / download the full reportView report online -- opens in the browser, no download needed. Available for 14 days. Download playwright-report.zip -- extract and open
All platforms - commit |
Code review findingsNon-blocking. The fix itself looks right: reading through One suggestion:
|
- one-arg getenv now delegates to the two-arg overload instead of wrapping detail::getenv, removing the duplicated read loop and its byte-wise name widening - unsetenv goes through SetEnvironmentVariableW with a UTF-8 decoded name, matching setenv and getenv - log when the resize-retry read fails instead of silently reporting the variable as unset - add a round-trip test for non-ASCII variable names
|
Both applied in c5df09e:
Writing a round-trip test for the widening divergence turned up one more instance of the same class: |
Fixes the
ide-os-windows/mainbuild break introduced by #18520 (first red run: build 3710). The new core gtestEnvironmentTest.EnvironmentScopeRestoresPreviousValuefails deterministically on Windows:Root cause
EnvironmentScopecaptured the previous value with raw::getenv, butcore::system::setenvwrites throughSetEnvironmentVariableW. On Windows those are two different stores:::getenvreads the CRT's_environsnapshot taken at process start, whichSetEnvironmentVariablenever updates. Any variable set viacore::system::setenvwas invisible to the scope, so its destructor took the "was unset" path and deleted the variable instead of restoring it. On POSIX both calls hit the same libcenviron, which is why the test was green locally and on the other platforms.Fix
Add an existence-preserving accessor to
core::system:::getenvunder the environment lock,nullptr->false.GetEnvironmentVariableWunder the lock (the same store the setters write), withERROR_ENVVAR_NOT_FOUNDdistinguishing unset.EnvironmentScopenow captures the previous value through this overload, keeping the unset vs set-but-empty distinction #18520 introduced (on POSIX; that distinction does not exist on Windows, where setting a variable to the empty string deletes it). This also removes the last raw::getenvfrom the public header, along with thestdlib.handEnvironmentLock.hppincludes it needed -- every remainingEnvironmentLockuser includes that header directly.The Windows brokenness predates #18520 but never had production impact: the only non-test
EnvironmentScopeuser is Apple-only (SourceIndex.cpp), andXdgTests.cppis compiled out on Windows, so the new test was the first code to exerciseEnvironmentScopethere.Tests
EnvironmentTest.GetenvOverloadDistinguishesUnsetcovers unset/set round-trips throughsetenv(which on Windows exercises exactly the CRT-vs-process-block mismatch) plus the POSIX-only set-but-empty case.Win32Environment.cppneeds the Windows CI build; the failing test should flip to green on the nextide-os-windowsrun.