message: Add WT_SESSION to WSLENV so it propagates into WSL
  This makes sure that things running inside WSL can see `WT_SESSION`.
  Closes
diff: @@ -88,6 +88,18 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation
  std::wstring cmdline{ wil::ExpandEnvironmentStringsW<std::wstring>(_commandline.c_str()) }; // mutable copy -- required for CreateProcessW
  Utils::EnvironmentVariableMapW environment;
  + auto zeroEnvMap = wil::scope_exit([&] {
  + // Can't zero the keys, but at least we can zero the values.
  + for (auto& [name, value] : environment)
  + {
  + ::SecureZeroMemory(value.data(), value.size() * sizeof(decltype(value.begin())::value_type));
  + }
  +
  + environment.clear();
  + });
  +
  + // Populate the environment map with the current environment.
  + RETURN_IF_FAILED(Utils::UpdateEnvironmentMapW(environment));
  {
  // Convert connection Guid to string and ignore the enclosing '{}'.
  @@ -97,7 +109,13 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation
  const auto guidSubStr = std::wstring_view{ wsGuid }.substr(1);
  // Ensure every connection has the unique identifier in the environment.
  - environment.emplace(L"WT_SESSION", guidSubStr.data());
  + environment.insert_or_assign(L"WT_SESSION", guidSubStr.data());
  +
  + auto wslEnv = environment[L"WSLENV"]; // We always want to load something, even if it's blank.
  + // WSLENV is a colon-delimited list of environment variables (+flags) that should appear inside WSL
  + // https://devblogs.microsoft.com/commandline/share-environment-vars-between-wsl-and-windows/
  + wslEnv = L"WT_SESSION:" + wslEnv; // prepend WT_SESSION to make sure it's visible inside WSL.
  + environment.insert_or_assign(L"WSLENV", wslEnv);
  }
  std::vector<wchar_t> newEnvVars;
  @@ -106,17 +124,6 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation
  newEnvVars.size() * sizeof(decltype(newEnvVars.begin())::value_type));
  });
  - auto zeroEnvMap = wil::scope_exit([&] {
  - // Can't zero the keys, but at least we can zero the values.
  - for (auto& [name, value] : environment)
  - {
  - ::SecureZeroMemory(value.data(), value.size() * sizeof(decltype(value.begin())::value_type));
  - }
  -
  - environment.clear();
  - });
  -
  - RETURN_IF_FAILED(Utils::UpdateEnvironmentMapW(environment));
  RETURN_IF_FAILED(Utils::EnvironmentMapToEnvironmentStringsW(environment, newEnvVars));
  LPWCH lpEnvironment = newEnvVars.empty() ? nullptr : newEnvVars.data();
  