Fix view_image tests for remote executor semantics

This commit is contained in:
pakrym-oai
2026-03-20 09:22:07 -07:00
parent 6057884765
commit daa39c6d2e
2 changed files with 19 additions and 45 deletions

View File

@@ -1,11 +1,8 @@
#![allow(clippy::expect_used, clippy::unwrap_used)]
use anyhow::Result;
use base64::Engine;
use base64::engine::general_purpose::STANDARD as BASE64_STANDARD;
use codex_core::config::types::McpServerConfig;
use codex_core::config::types::McpServerTransportConfig;
use codex_exec_server::CreateDirectoryOptions;
use codex_features::Feature;
use codex_protocol::dynamic_tools::DynamicToolCallOutputContentItem;
use codex_protocol::dynamic_tools::DynamicToolResponse;
@@ -15,7 +12,6 @@ use codex_protocol::protocol::EventMsg;
use codex_protocol::protocol::Op;
use codex_protocol::protocol::SandboxPolicy;
use codex_protocol::user_input::UserInput;
use codex_utils_absolute_path::AbsolutePathBuf;
use core_test_support::assert_regex_match;
use core_test_support::responses;
use core_test_support::responses::ResponseMock;
@@ -1810,26 +1806,13 @@ async fn code_mode_can_use_view_image_result_with_image_helper() -> Result<()> {
});
let test = builder.build_remote_aware(&server).await?;
let image_bytes = BASE64_STANDARD.decode(
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR4nGP4z8DwHwAFAAH/iZk9HQAAAABJRU5ErkJggg==",
)?;
let image_path = test.config.cwd.join("code_mode_view_image.png");
if let Some(parent) = image_path.parent() {
test.fs()
.create_directory(
&AbsolutePathBuf::try_from(parent.to_path_buf())?,
CreateDirectoryOptions { recursive: true },
)
.await?;
}
test.fs()
.write_file(&AbsolutePathBuf::try_from(image_path.clone())?, image_bytes)
.await?;
let image_path_json = serde_json::to_string(&image_path.to_string_lossy().to_string())?;
let code = format!(
r#"
const out = await tools.view_image({{ path: {image_path_json}, detail: "original" }});
const pngBase64 = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR4nGP4z8DwHwAFAAH/iZk9HQAAAABJRU5ErkJggg==";
await tools.exec_command({{
cmd: "printf '%s' '" + pngBase64 + "' | base64 --decode > code_mode_view_image.png"
}});
const out = await tools.view_image({{ path: "code_mode_view_image.png", detail: "original" }});
image(out);
"#
);

View File

@@ -146,17 +146,12 @@ async fn user_turn_with_local_image_attaches_image() -> anyhow::Result<()> {
..
} = &test;
let rel_path = "user-turn/example.png";
let original_width = 2304;
let original_height = 864;
let abs_path = write_workspace_png(
&test,
rel_path,
original_width,
original_height,
[20u8, 40, 60, 255],
)
.await?;
let local_image_dir = tempfile::tempdir()?;
let abs_path = local_image_dir.path().join("example.png");
let image = ImageBuffer::from_pixel(original_width, original_height, Rgba([20u8, 40, 60, 255]));
image.save(&abs_path)?;
let response = sse(vec![
ev_response_created("resp-1"),
@@ -888,14 +883,12 @@ async fn js_repl_emit_image_attaches_local_image() -> anyhow::Result<()> {
let call_id = "js-repl-view-image";
let js_input = r#"
const fs = await import("node:fs/promises");
const path = await import("node:path");
const imagePath = path.join(codex.tmpDir, "js-repl-view-image.png");
const png = Buffer.from(
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR4nGP4z8DwHwAFAAH/iZk9HQAAAABJRU5ErkJggg==",
"base64"
);
await fs.writeFile(imagePath, png);
const pngBase64 = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR4nGP4z8DwHwAFAAH/iZk9HQAAAABJRU5ErkJggg==";
const imagePath = path.join(codex.cwd, "js-repl-view-image.png");
await codex.tool("shell_command", {
command: `mkdir -p ${JSON.stringify(path.dirname(imagePath))} && printf '%s' '${pngBase64}' | base64 --decode > ${JSON.stringify(imagePath)}`,
});
const out = await codex.tool("view_image", { path: imagePath });
await codex.emitImage(out);
"#;
@@ -1008,14 +1001,12 @@ async fn js_repl_view_image_requires_explicit_emit() -> anyhow::Result<()> {
let call_id = "js-repl-view-image-no-emit";
let js_input = r#"
const fs = await import("node:fs/promises");
const path = await import("node:path");
const imagePath = path.join(codex.tmpDir, "js-repl-view-image-no-emit.png");
const png = Buffer.from(
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR4nGP4z8DwHwAFAAH/iZk9HQAAAABJRU5ErkJggg==",
"base64"
);
await fs.writeFile(imagePath, png);
const pngBase64 = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR4nGP4z8DwHwAFAAH/iZk9HQAAAABJRU5ErkJggg==";
const imagePath = path.join(codex.cwd, "js-repl-view-image-no-emit.png");
await codex.tool("shell_command", {
command: `mkdir -p ${JSON.stringify(path.dirname(imagePath))} && printf '%s' '${pngBase64}' | base64 --decode > ${JSON.stringify(imagePath)}`,
});
const out = await codex.tool("view_image", { path: imagePath });
console.log(out.type);
"#;