Skip to content

Commit 66858e4

Browse files
fix tests
1 parent 78aafa4 commit 66858e4

File tree

2 files changed

+17
-26
lines changed

2 files changed

+17
-26
lines changed

codex-rs/core/src/environment_context.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -227,20 +227,21 @@ impl From<EnvironmentContext> for ResponseItem {
227227
// Restrict Operating System Info to Windows and Linux inside WSL for now
228228
#[cfg(target_os = "windows")]
229229
fn operating_system_info_impl() -> Option<OperatingSystemInfo> {
230-
let os_info = os_info::get();
230+
let info = os_info::get();
231231
Some(OperatingSystemInfo {
232-
name: os_info.os_type().to_string(),
233-
version: os_info.version().to_string(),
232+
name: info.os_type().to_string(),
233+
version: info.version().to_string(),
234234
is_likely_windows_subsystem_for_linux: Some(has_wsl_env_markers()),
235235
})
236236
}
237237

238238
#[cfg(all(unix, not(target_os = "macos")))]
239239
fn operating_system_info_impl() -> Option<OperatingSystemInfo> {
240+
let info = os_info::get();
240241
match has_wsl_env_markers() {
241242
true => Some(OperatingSystemInfo {
242-
name: "Windows Subsystem for Linux".to_string(),
243-
version: "".to_string(),
243+
name: info.os_type().to_string(),
244+
version: info.version().to_string(),
244245
is_likely_windows_subsystem_for_linux: Some(true),
245246
}),
246247
false => None,
@@ -307,10 +308,11 @@ mod tests {
307308
#[test]
308309
fn operating_system_info_matches_wsl_detection_on_unix() {
309310
let info = operating_system_info_impl();
311+
let os_details = os_info::get();
310312
if has_wsl_env_markers() {
311313
let info = info.expect("expected WSL operating system info");
312-
assert_eq!(info.name, "Windows Subsystem for Linux");
313-
assert_eq!(info.version, "");
314+
assert_eq!(info.name, os_details.os_type().to_string());
315+
assert_eq!(info.version, os_details.version().to_string());
314316
assert_eq!(info.is_likely_windows_subsystem_for_linux, Some(true));
315317
} else {
316318
assert_eq!(info, None);

codex-rs/core/tests/suite/prompt_caching.rs

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,18 @@ fn operating_system_context_block() -> String {
5050
let name = info.os_type().to_string();
5151
let version = info.version().to_string();
5252
let is_wsl = has_wsl_env_markers();
53-
return format!(
53+
format!(
5454
" <operating_system>\n <name>{name}</name>\n <version>{version}</version>\n <is_likely_windows_subsystem_for_linux>{is_wsl}</is_likely_windows_subsystem_for_linux>\n </operating_system>\n"
55-
);
55+
)
5656
}
5757

5858
#[cfg(all(unix, not(target_os = "macos")))]
5959
{
6060
if has_wsl_env_markers() {
61-
return " <operating_system>\n <name>Windows Subsystem for Linux</name>\n <version></version>\n <is_likely_windows_subsystem_for_linux>true</is_likely_windows_subsystem_for_linux>\n </operating_system>\n".to_string();
61+
" <operating_system>\n <name>{name}</name>\n <version></version>\n <is_likely_windows_subsystem_for_linux>true</is_likely_windows_subsystem_for_linux>\n </operating_system>\n".to_string()
62+
} else {
63+
String::new()
6264
}
63-
return String::new();
6465
}
6566

6667
#[cfg(target_os = "macos")]
@@ -374,22 +375,10 @@ async fn prefixes_context_and_instructions_once_and_consistently_across_requests
374375

375376
let shell = default_user_shell().await;
376377

377-
let expected_env_text = format!(
378-
r#"<environment_context>
379-
<cwd>{}</cwd>
380-
<approval_policy>on-request</approval_policy>
381-
<sandbox_mode>read-only</sandbox_mode>
382-
<network_access>restricted</network_access>
383-
{}</environment_context>"#,
384-
cwd.path().to_string_lossy(),
385-
match shell.name() {
386-
Some(name) => format!(" <shell>{name}</shell>\n"),
387-
None => String::new(),
388-
}
389-
);
378+
let cwd_str = cwd.path().to_string_lossy().into_owned();
379+
let expected_env_text = default_env_context_str(&cwd_str, &shell);
390380
let expected_ui_text = format!(
391-
"# AGENTS.md instructions for {}\n\n<INSTRUCTIONS>\nbe consistent and helpful\n</INSTRUCTIONS>",
392-
cwd.path().to_string_lossy()
381+
"# AGENTS.md instructions for {cwd_str}\n\n<INSTRUCTIONS>\nbe consistent and helpful\n</INSTRUCTIONS>"
393382
);
394383

395384
let expected_env_msg = serde_json::json!({

0 commit comments

Comments
 (0)