Render unknown environment shells

This commit is contained in:
pakrym-oai
2026-06-15 23:23:12 -07:00
parent ef025c5384
commit ea8950e32a
3 changed files with 26 additions and 71 deletions
@@ -14,6 +14,8 @@ use std::path::PathBuf;
use super::ContextualUserFragment;
const UNKNOWN_SHELL: &str = "unknown";
#[derive(Debug, Clone, PartialEq)]
pub(crate) struct EnvironmentContext {
pub(crate) environments: EnvironmentContextEnvironments,
@@ -28,11 +30,11 @@ pub(crate) struct EnvironmentContext {
pub(crate) struct EnvironmentContextEnvironment {
pub(crate) id: String,
pub(crate) cwd: AbsolutePathBuf,
pub(crate) shell: Option<String>,
pub(crate) shell: String,
}
impl EnvironmentContextEnvironment {
fn legacy(cwd: AbsolutePathBuf, shell: Option<String>) -> Self {
fn legacy(cwd: AbsolutePathBuf, shell: String) -> Self {
Self {
id: String::new(),
cwd,
@@ -46,10 +48,10 @@ impl EnvironmentContextEnvironment {
.map(|environment| Self {
id: environment.environment_id.clone(),
cwd: environment.cwd().clone(),
shell: environment
.shell()
.ok()
.map(|shell| shell.name().to_string()),
shell: environment.shell().map_or_else(
|_| UNKNOWN_SHELL.to_string(),
|shell| shell.name().to_string(),
),
})
.collect()
}
@@ -440,7 +442,8 @@ impl EnvironmentContext {
};
Self::new_with_environments(
EnvironmentContextEnvironments::from_vec(vec![EnvironmentContextEnvironment::legacy(
cwd, None,
cwd,
UNKNOWN_SHELL.to_string(),
)]),
turn_context_item.current_date.clone(),
turn_context_item.timezone.clone(),
@@ -541,9 +544,7 @@ impl ContextualUserFragment for EnvironmentContext {
" <cwd>{}</cwd>",
environment.cwd.to_string_lossy()
));
if let Some(shell) = &environment.shell {
lines.push(format!(" <shell>{shell}</shell>"));
}
lines.push(format!(" <shell>{}</shell>", environment.shell));
}
EnvironmentContextEnvironments::Multiple(environments) => {
lines.push(" <environments>".to_string());
@@ -553,9 +554,7 @@ impl ContextualUserFragment for EnvironmentContext {
" <cwd>{}</cwd>",
environment.cwd.to_string_lossy()
));
if let Some(shell) = &environment.shell {
lines.push(format!(" <shell>{shell}</shell>"));
}
lines.push(format!(" <shell>{}</shell>", environment.shell));
lines.push(" </environment>".to_string());
}
lines.push(" </environments>".to_string());
@@ -37,7 +37,7 @@ fn serialize_workspace_write_environment_context() {
vec![EnvironmentContextEnvironment {
id: "local".to_string(),
cwd: cwd.abs(),
shell: Some(fake_shell_name()),
shell: fake_shell_name(),
}],
Some("2026-02-26".to_string()),
Some("America/Los_Angeles".to_string()),
@@ -68,7 +68,7 @@ fn serialize_environment_context_with_network() {
vec![EnvironmentContextEnvironment {
id: "local".to_string(),
cwd: test_path_buf("/repo").abs(),
shell: Some(fake_shell_name()),
shell: fake_shell_name(),
}],
Some("2026-02-26".to_string()),
Some("America/Los_Angeles".to_string()),
@@ -130,7 +130,7 @@ fn serialize_environment_context_with_full_filesystem_profile() {
vec![EnvironmentContextEnvironment {
id: "local".to_string(),
cwd: test_path_buf("/repo").abs(),
shell: Some(fake_shell_name()),
shell: fake_shell_name(),
}],
/*current_date*/ None,
/*timezone*/ None,
@@ -235,7 +235,7 @@ fn equals_except_shell_compares_cwd() {
vec![EnvironmentContextEnvironment {
id: "local".to_string(),
cwd: test_abs_path("/repo"),
shell: Some(fake_shell_name()),
shell: fake_shell_name(),
}],
/*current_date*/ None,
/*timezone*/ None,
@@ -246,7 +246,7 @@ fn equals_except_shell_compares_cwd() {
vec![EnvironmentContextEnvironment {
id: "local".to_string(),
cwd: test_abs_path("/repo"),
shell: Some(fake_shell_name()),
shell: fake_shell_name(),
}],
/*current_date*/ None,
/*timezone*/ None,
@@ -262,7 +262,7 @@ fn equals_except_shell_compares_cwd_differences() {
vec![EnvironmentContextEnvironment {
id: "local".to_string(),
cwd: test_abs_path("/repo1"),
shell: Some(fake_shell_name()),
shell: fake_shell_name(),
}],
/*current_date*/ None,
/*timezone*/ None,
@@ -273,7 +273,7 @@ fn equals_except_shell_compares_cwd_differences() {
vec![EnvironmentContextEnvironment {
id: "local".to_string(),
cwd: test_abs_path("/repo2"),
shell: Some(fake_shell_name()),
shell: fake_shell_name(),
}],
/*current_date*/ None,
/*timezone*/ None,
@@ -290,7 +290,7 @@ fn equals_except_shell_ignores_shell() {
vec![EnvironmentContextEnvironment {
id: "local".to_string(),
cwd: test_abs_path("/repo"),
shell: Some("bash".to_string()),
shell: "bash".to_string(),
}],
/*current_date*/ None,
/*timezone*/ None,
@@ -301,7 +301,7 @@ fn equals_except_shell_ignores_shell() {
vec![EnvironmentContextEnvironment {
id: "other".to_string(),
cwd: test_abs_path("/repo"),
shell: Some("zsh".to_string()),
shell: "zsh".to_string(),
}],
/*current_date*/ None,
/*timezone*/ None,
@@ -318,7 +318,7 @@ fn serialize_environment_context_with_subagents() {
vec![EnvironmentContextEnvironment {
id: "local".to_string(),
cwd: test_path_buf("/repo").abs(),
shell: Some(fake_shell_name()),
shell: fake_shell_name(),
}],
Some("2026-02-26".to_string()),
Some("America/Los_Angeles".to_string()),
@@ -352,12 +352,12 @@ fn serialize_environment_context_with_multiple_selected_environments() {
EnvironmentContextEnvironment {
id: "local".to_string(),
cwd: local_cwd.abs(),
shell: Some("bash".to_string()),
shell: "bash".to_string(),
},
EnvironmentContextEnvironment {
id: "remote".to_string(),
cwd: remote_cwd.abs(),
shell: Some("bash".to_string()),
shell: "bash".to_string(),
},
],
Some("2026-02-26".to_string()),
@@ -397,12 +397,12 @@ fn serialize_environment_context_prefers_environment_shell_when_present() {
EnvironmentContextEnvironment {
id: "local".to_string(),
cwd: local_cwd.abs(),
shell: Some("powershell".to_string()),
shell: "powershell".to_string(),
},
EnvironmentContextEnvironment {
id: "remote".to_string(),
cwd: remote_cwd.abs(),
shell: Some("cmd".to_string()),
shell: "cmd".to_string(),
},
],
/*current_date*/ None,
-44
View File
@@ -7300,50 +7300,6 @@ async fn build_settings_update_items_emits_environment_item_for_network_changes(
));
}
#[tokio::test]
async fn environment_context_omits_shell_when_environment_shell_is_absent() {
let (_session, mut turn_context) = make_session_and_context().await;
for environment in &mut turn_context.environments.turn_environments {
*environment = TurnEnvironment::new(
environment.environment_id.clone(),
Arc::clone(&environment.environment),
environment.cwd().clone(),
Err("not configured for test".to_string()),
);
}
let environment_context =
crate::context::EnvironmentContext::from_turn_context(&turn_context).render();
assert!(
!environment_context.contains("<shell>"),
"{environment_context}"
);
let primary_environment = turn_context
.environments
.turn_environments
.first()
.cloned()
.expect("primary environment");
let primary_cwd = primary_environment.cwd().clone();
turn_context.environments.turn_environments[0] = TurnEnvironment::new(
primary_environment.environment_id,
primary_environment.environment,
primary_cwd,
Ok(crate::shell::Shell {
shell_type: crate::shell::ShellType::Cmd,
shell_path: PathBuf::from("cmd"),
}),
);
let environment_context =
crate::context::EnvironmentContext::from_turn_context(&turn_context).render();
assert!(
environment_context.contains("<shell>cmd</shell>"),
"{environment_context}"
);
}
#[tokio::test]
async fn build_settings_update_items_emits_environment_item_for_time_changes() {
let (session, previous_context) = make_session_and_context().await;