fix: more std::env::vars -> std::env::vars_os fixes

This commit is contained in:
Michael Bolin
2025-12-08 17:36:05 -08:00
parent cacfd003ac
commit 402db13d17
10 changed files with 58 additions and 17 deletions
+6 -2
View File
@@ -851,7 +851,9 @@ mod tests {
"-c".to_string(),
"sleep 60 & echo $!; sleep 60".to_string(),
];
let env: HashMap<String, String> = std::env::vars().collect();
let env: HashMap<String, String> = std::env::vars_os()
.filter_map(|(key, value)| Some((key.into_string().ok()?, value.into_string().ok()?)))
.collect();
let params = ExecParams {
command,
cwd: std::env::current_dir()?,
@@ -894,7 +896,9 @@ mod tests {
async fn process_exec_tool_call_respects_cancellation_token() -> Result<()> {
let command = long_running_command();
let cwd = std::env::current_dir()?;
let env: HashMap<String, String> = std::env::vars().collect();
let env: HashMap<String, String> = std::env::vars_os()
.filter_map(|(key, value)| Some((key.into_string().ok()?, value.into_string().ok()?)))
.collect();
let cancel_token = CancellationToken::new();
let cancel_tx = cancel_token.clone();
let params = ExecParams {
+5 -1
View File
@@ -12,7 +12,11 @@ use std::collections::HashSet;
/// The derivation follows the algorithm documented in the struct-level comment
/// for [`ShellEnvironmentPolicy`].
pub fn create_env(policy: &ShellEnvironmentPolicy) -> HashMap<String, String> {
populate_env(std::env::vars(), policy)
populate_env(
std::env::vars_os()
.filter_map(|(key, value)| Some((key.into_string().ok()?, value.into_string().ok()?))),
policy,
)
}
fn populate_env<I>(vars: I, policy: &ShellEnvironmentPolicy) -> HashMap<String, String>
+3 -1
View File
@@ -232,7 +232,9 @@ async fn java_home_finds_runtime_under_seatbelt() {
let command_cwd = std::env::current_dir().expect("getcwd");
let sandbox_cwd = command_cwd.clone();
let mut env: HashMap<String, String> = std::env::vars().collect();
let mut env: HashMap<String, String> = std::env::vars_os()
.filter_map(|(key, value)| Some((key.into_string().ok()?, value.into_string().ok()?)))
.collect();
env.remove("JAVA_HOME");
env.remove(CODEX_SANDBOX_ENV_VAR);