mirror of
https://github.com/codewhale-hq/Codewhale.git
synced 2026-11-08 08:04:25 -10:00
Merge pull request #6834 from Guan0923/codex/fix-python-output-encoding
fix(tui): preserve UTF-8 Python output on Windows
This commit is contained in:
2 files changed
+31
No files matched your search
@@ -1634,6 +1634,8 @@ pub(super) async fn execute_code_execution_tool(
|
||||
let budget = Duration::from_secs(120);
|
||||
let mut cmd =
|
||||
crate::tools::shell::sandboxed_runner_command(context, &program, args, workspace, budget)?;
|
||||
// Match the UTF-8 decoder below, including Windows Python's piped output.
|
||||
cmd.env("PYTHONIOENCODING", "utf-8");
|
||||
let output = tokio::time::timeout(
|
||||
budget,
|
||||
crate::process_tree::contained_output_with_input(&mut cmd, code.as_bytes().to_vec()),
|
||||
|
||||
@@ -34,6 +34,35 @@ fn code_execution_description_does_not_claim_process_sandboxing() {
|
||||
assert!(!CODE_EXECUTION_DESCRIPTION.contains("sandbox"));
|
||||
}
|
||||
|
||||
/// Python output must match our UTF-8 decoder even with non-UTF-8 parent stdio.
|
||||
#[tokio::test]
|
||||
async fn code_execution_returns_utf8_stdout_and_stderr() {
|
||||
use crate::dependencies::ExternalTool as _;
|
||||
use crate::test_support::{EnvVarGuard, lock_test_env};
|
||||
|
||||
let _env_lock = lock_test_env();
|
||||
if !crate::dependencies::Python::available() {
|
||||
return;
|
||||
}
|
||||
let _encoding = EnvVarGuard::set("PYTHONIOENCODING", "gbk");
|
||||
let tmp = tempfile::tempdir().expect("tempdir");
|
||||
let result = super::execute_code_execution_tool(
|
||||
&json!({"code": r#"import sys; print("\u4e2d\u6587"); print("\u9519\u8bef", file=sys.stderr)"#}),
|
||||
tmp.path(),
|
||||
&crate::tools::spec::ToolContext::new(tmp.path()),
|
||||
)
|
||||
.await
|
||||
.expect("code execution should run");
|
||||
let payload = result.metadata.expect("payload");
|
||||
assert_eq!(
|
||||
(
|
||||
payload["stdout"].as_str().map(str::trim_end),
|
||||
payload["stderr"].as_str().map(str::trim_end),
|
||||
),
|
||||
(Some("中文"), Some("错误")),
|
||||
);
|
||||
}
|
||||
|
||||
/// The published synthetic-name list and the predicate that classifies a
|
||||
/// catalog entry as synthetic must agree. A name that appears in the list
|
||||
/// but is not classified synthetic would let the request projection report
|
||||
|
||||
Reference in new issue
Block a user