Lightweight coding agent that runs in your terminal
Rust
[codex] Initialize ICU data for code mode V8 (#17709)
pakrym-oaiad37389c18af
diff --git a/MODULE.bazel.lock b/MODULE.bazel.lockindex 2dfb03c3de..c270e6a9fa 100644--- a/MODULE.bazel.lock+++ b/MODULE.bazel.lock@@ -782,6 +782,7 @@"debugid_0.8.0": "{\"dependencies\":[{\"name\":\"serde\",\"optional\":true,\"req\":\"^1.0.85\"},{\"kind\":\"dev\",\"name\":\"serde_json\",\"req\":\"^1.0.37\"},{\"name\":\"uuid\",\"req\":\"^1.0.0\"}],\"features\":{}}","debugserver-types_0.5.0": "{\"dependencies\":[{\"name\":\"schemafy\",\"req\":\"^0.5.0\"},{\"features\":[\"derive\"],\"name\":\"serde\",\"req\":\"^1.0\"},{\"name\":\"serde_json\",\"req\":\"^1.0\"}],\"features\":{}}","deflate64_0.1.10": "{\"dependencies\":[{\"features\":[\"derive\"],\"kind\":\"dev\",\"name\":\"bytemuck\",\"req\":\"^1.13.1\"},{\"kind\":\"dev\",\"name\":\"proptest\",\"req\":\"^1.2.0\"},{\"kind\":\"dev\",\"name\":\"tempfile\",\"req\":\"^3.7.1\"}],\"features\":{}}",+ "deno_core_icudata_0.77.0": "{\"dependencies\":[],\"features\":{}}","der-parser_10.0.0": "{\"dependencies\":[{\"name\":\"asn1-rs\",\"req\":\"^0.7\"},{\"name\":\"bitvec\",\"optional\":true,\"req\":\"^1.0\"},{\"name\":\"cookie-factory\",\"optional\":true,\"req\":\"^0.3.0\"},{\"default_features\":false,\"name\":\"displaydoc\",\"req\":\"^0.2\"},{\"kind\":\"dev\",\"name\":\"hex-literal\",\"req\":\"^0.4\"},{\"name\":\"nom\",\"req\":\"^7.0\"},{\"name\":\"num-bigint\",\"optional\":true,\"req\":\"^0.4\"},{\"name\":\"num-traits\",\"req\":\"^0.2\"},{\"kind\":\"dev\",\"name\":\"pretty_assertions\",\"req\":\"^1.0\"},{\"name\":\"rusticata-macros\",\"req\":\"^4.0\"},{\"kind\":\"dev\",\"name\":\"test-case\",\"req\":\"^3.0\"}],\"features\":{\"as_bitvec\":[\"bitvec\"],\"bigint\":[\"num-bigint\"],\"default\":[\"std\"],\"serialize\":[\"std\",\"cookie-factory\"],\"std\":[],\"unstable\":[]}}","der_0.7.10": "{\"dependencies\":[{\"features\":[\"derive\"],\"name\":\"arbitrary\",\"optional\":true,\"req\":\"^1.3\"},{\"default_features\":false,\"name\":\"bytes\",\"optional\":true,\"req\":\"^1\"},{\"name\":\"const-oid\",\"optional\":true,\"req\":\"^0.9.2\"},{\"name\":\"der_derive\",\"optional\":true,\"req\":\"^0.7.2\"},{\"name\":\"flagset\",\"optional\":true,\"req\":\"^0.4.3\"},{\"kind\":\"dev\",\"name\":\"hex-literal\",\"req\":\"^0.4.1\"},{\"features\":[\"alloc\"],\"name\":\"pem-rfc7468\",\"optional\":true,\"req\":\"^0.7\"},{\"kind\":\"dev\",\"name\":\"proptest\",\"req\":\"^1\"},{\"default_features\":false,\"name\":\"time\",\"optional\":true,\"req\":\"^0.3.4\"},{\"default_features\":false,\"name\":\"zeroize\",\"optional\":true,\"req\":\"^1.5\"}],\"features\":{\"alloc\":[\"zeroize?/alloc\"],\"arbitrary\":[\"dep:arbitrary\",\"const-oid?/arbitrary\",\"std\"],\"bytes\":[\"dep:bytes\",\"alloc\"],\"derive\":[\"dep:der_derive\"],\"oid\":[\"dep:const-oid\"],\"pem\":[\"dep:pem-rfc7468\",\"alloc\",\"zeroize\"],\"real\":[],\"std\":[\"alloc\"]}}","deranged_0.5.5": "{\"dependencies\":[{\"name\":\"deranged-macros\",\"optional\":true,\"req\":\"=0.3.0\"},{\"default_features\":false,\"name\":\"num-traits\",\"optional\":true,\"req\":\"^0.2.15\"},{\"default_features\":false,\"name\":\"powerfmt\",\"optional\":true,\"req\":\"^0.2.0\"},{\"default_features\":false,\"name\":\"quickcheck\",\"optional\":true,\"req\":\"^1.0.3\"},{\"default_features\":false,\"name\":\"rand08\",\"optional\":true,\"package\":\"rand\",\"req\":\"^0.8.4\"},{\"kind\":\"dev\",\"name\":\"rand08\",\"package\":\"rand\",\"req\":\"^0.8.4\"},{\"default_features\":false,\"name\":\"rand09\",\"optional\":true,\"package\":\"rand\",\"req\":\"^0.9.0\"},{\"kind\":\"dev\",\"name\":\"rand09\",\"package\":\"rand\",\"req\":\"^0.9.0\"},{\"default_features\":false,\"name\":\"serde_core\",\"optional\":true,\"req\":\"^1.0.220\"},{\"kind\":\"dev\",\"name\":\"serde_json\",\"req\":\"^1.0.86\"}],\"features\":{\"alloc\":[],\"default\":[],\"macros\":[\"dep:deranged-macros\"],\"num\":[\"dep:num-traits\"],\"powerfmt\":[\"dep:powerfmt\"],\"quickcheck\":[\"dep:quickcheck\",\"alloc\"],\"rand\":[\"rand08\",\"rand09\"],\"rand08\":[\"dep:rand08\"],\"rand09\":[\"dep:rand09\"],\"serde\":[\"dep:serde_core\"]}}",diff --git a/codex-rs/Cargo.lock b/codex-rs/Cargo.lockindex 8f36814684..fc5c70e6b6 100644--- a/codex-rs/Cargo.lock+++ b/codex-rs/Cargo.lock@@ -1828,6 +1828,7 @@ name = "codex-code-mode"version = "0.0.0"dependencies = ["async-trait",+ "deno_core_icudata","pretty_assertions","serde","serde_json",@@ -3899,6 +3900,12 @@ version = "0.1.10"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "26bf8fc351c5ed29b5c2f0cbbac1b209b74f60ecd62e675a998df72c49af5204"+[[package]]+name = "deno_core_icudata"+version = "0.77.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "a9efff8990a82c1ae664292507e1a5c6749ddd2312898cdf9cd7cb1fd4bc64c6"+[[package]]name = "der"version = "0.7.10"diff --git a/codex-rs/Cargo.toml b/codex-rs/Cargo.tomlindex 007c57e97c..866d343fd9 100644--- a/codex-rs/Cargo.toml+++ b/codex-rs/Cargo.toml@@ -220,6 +220,7 @@ crossbeam-channel = "0.5.15"crossterm = "0.28.1"csv = "1.3.1"ctor = "0.6.3"+deno_core_icudata = "0.77.0"derive_more = "2"diffy = "0.4.2"dirs = "6"diff --git a/codex-rs/code-mode/Cargo.toml b/codex-rs/code-mode/Cargo.tomlindex e821ca0e4d..fa7ce63a42 100644--- a/codex-rs/code-mode/Cargo.toml+++ b/codex-rs/code-mode/Cargo.toml@@ -14,6 +14,7 @@ workspace = true[dependencies]async-trait = { workspace = true }+deno_core_icudata = { workspace = true }serde = { workspace = true, features = ["derive"] }serde_json = { workspace = true }tokio = { workspace = true, features = ["macros", "rt", "sync", "time"] }diff --git a/codex-rs/code-mode/src/runtime/mod.rs b/codex-rs/code-mode/src/runtime/mod.rsindex 411f81bddc..febe54216a 100644--- a/codex-rs/code-mode/src/runtime/mod.rs+++ b/codex-rs/code-mode/src/runtime/mod.rs@@ -104,6 +104,8 @@ pub(crate) fn spawn_runtime(request: ExecuteRequest,event_tx: mpsc::UnboundedSender<RuntimeEvent>,) -> Result<(std_mpsc::Sender<RuntimeCommand>, v8::IsolateHandle), String> {+ initialize_v8()?;+let (command_tx, command_rx) = std_mpsc::channel();let runtime_command_tx = command_tx.clone();let (isolate_handle_tx, isolate_handle_rx) = std_mpsc::sync_channel(1);@@ -164,15 +166,20 @@ pub(super) enum CompletionState {},}-fn initialize_v8() {- static PLATFORM: OnceLock<v8::SharedRef<v8::Platform>> = OnceLock::new();+fn initialize_v8() -> Result<(), String> {+ static PLATFORM: OnceLock<Result<v8::SharedRef<v8::Platform>, String>> = OnceLock::new();- let _ = PLATFORM.get_or_init(|| {+ match PLATFORM.get_or_init(|| {+ v8::icu::set_common_data_77(deno_core_icudata::ICU_DATA)+ .map_err(|error_code| format!("failed to initialize ICU data: {error_code}"))?;let platform = v8::new_default_platform(0, false).make_shared();v8::V8::initialize_platform(platform.clone());v8::V8::initialize();- platform- });+ Ok(platform)+ }) {+ Ok(_) => Ok(()),+ Err(error_text) => Err(error_text.clone()),+ }}fn run_runtime(@@ -182,8 +189,6 @@ fn run_runtime(isolate_handle_tx: std_mpsc::SyncSender<v8::IsolateHandle>,runtime_command_tx: std_mpsc::Sender<RuntimeCommand>,) {- initialize_v8();-let isolate = &mut v8::Isolate::new(v8::CreateParams::default());let isolate_handle = isolate.thread_safe_handle();if isolate_handle_tx.send(isolate_handle).is_err() {diff --git a/codex-rs/code-mode/src/service.rs b/codex-rs/code-mode/src/service.rsindex 5b67dd17b8..c14fee1957 100644--- a/codex-rs/code-mode/src/service.rs+++ b/codex-rs/code-mode/src/service.rs@@ -561,6 +561,85 @@ mod tests {);}+ #[tokio::test]+ async fn date_locale_string_formats_with_icu_data() {+ let service = CodeModeService::new();++ let response = service+ .execute(ExecuteRequest {+ source: r#"+const value = new Date("2025-01-02T03:04:05Z")+ .toLocaleString("fr-FR", {+ weekday: "long",+ month: "long",+ day: "numeric",+ hour: "2-digit",+ minute: "2-digit",+ second: "2-digit",+ hour12: false,+ timeZone: "UTC",+ });+text(value);+"#+ .to_string(),+ yield_time_ms: None,+ ..execute_request("")+ })+ .await+ .unwrap();++ assert_eq!(+ response,+ RuntimeResponse::Result {+ cell_id: "1".to_string(),+ content_items: vec![FunctionCallOutputContentItem::InputText {+ text: "jeudi 2 janvier \u{e0} 03:04:05".to_string(),+ }],+ stored_values: HashMap::new(),+ error_text: None,+ }+ );+ }++ #[tokio::test]+ async fn intl_date_time_format_formats_with_icu_data() {+ let service = CodeModeService::new();++ let response = service+ .execute(ExecuteRequest {+ source: r#"+const formatter = new Intl.DateTimeFormat("fr-FR", {+ weekday: "long",+ month: "long",+ day: "numeric",+ hour: "2-digit",+ minute: "2-digit",+ second: "2-digit",+ hour12: false,+ timeZone: "UTC",+});+text(formatter.format(new Date("2025-01-02T03:04:05Z")));+"#+ .to_string(),+ yield_time_ms: None,+ ..execute_request("")+ })+ .await+ .unwrap();++ assert_eq!(+ response,+ RuntimeResponse::Result {+ cell_id: "1".to_string(),+ content_items: vec![FunctionCallOutputContentItem::InputText {+ text: "jeudi 2 janvier \u{e0} 03:04:05".to_string(),+ }],+ stored_values: HashMap::new(),+ error_text: None,+ }+ );+ }+#[tokio::test]async fn output_helpers_return_undefined() {let service = CodeModeService::new();