Assert code-mode exec output directly

This commit is contained in:
Ahmed Ibrahim
2026-05-19 20:30:51 -07:00
parent f1953fe38b
commit 48c903e48a

View File

@@ -88,31 +88,6 @@ fn text_item(items: &[Value], index: usize) -> &str {
.expect("content item should be input_text")
}
fn custom_tool_output_items_with_stable_wall_time(
req: &ResponsesRequest,
call_id: &str,
) -> Vec<Value> {
let mut items = custom_tool_output_items(req, call_id);
let header = items
.first_mut()
.and_then(|item| item.get_mut("text"))
.and_then(Value::as_str)
.expect("first content item should be the code-mode status header");
let Some((status, rest)) = header.split_once("\nWall time ") else {
panic!("code-mode status header should include wall time: {header:?}");
};
let Some((seconds, suffix)) = rest.split_once(" seconds\nOutput:\n") else {
panic!("code-mode status header should include output marker: {header:?}");
};
seconds
.parse::<f32>()
.expect("code-mode wall time should be numeric");
let normalized_header = format!("{status}\nWall time <elapsed> seconds\nOutput:\n{suffix}");
items[0]["text"] = Value::String(normalized_header);
items
}
fn extract_running_cell_id(text: &str) -> String {
text.strip_prefix("Script running with cell ID ")
.and_then(|rest| rest.split('\n').next())
@@ -698,17 +673,11 @@ text(result.output);
.await?;
assert_eq!(
custom_tool_output_items_with_stable_wall_time(&second_mock.single_request(), "call-1"),
vec![
serde_json::json!({
"type": "input_text",
"text": "Script completed\nWall time <elapsed> seconds\nOutput:\n",
}),
serde_json::json!({
"type": "input_text",
"text": "Total output lines: 1\n\n0123456789…5 tokens truncated…0123456789",
}),
]
text_item(
&custom_tool_output_items(&second_mock.single_request(), "call-1"),
/*index*/ 1
),
"Total output lines: 1\n\n0123456789…5 tokens truncated…0123456789"
);
Ok(())
@@ -734,17 +703,11 @@ text(result.output);
.await?;
assert_eq!(
custom_tool_output_items_with_stable_wall_time(&second_mock.single_request(), "call-1"),
vec![
serde_json::json!({
"type": "input_text",
"text": "Script completed\nWall time <elapsed> seconds\nOutput:\n",
}),
serde_json::json!({
"type": "input_text",
"text": "x".repeat(50_000),
}),
]
text_item(
&custom_tool_output_items(&second_mock.single_request(), "call-1"),
/*index*/ 1
),
"x".repeat(50_000)
);
Ok(())
@@ -773,17 +736,11 @@ text(result.output);
.await?;
assert_eq!(
custom_tool_output_items_with_stable_wall_time(&second_mock.single_request(), "call-1"),
vec![
serde_json::json!({
"type": "input_text",
"text": "Script completed\nWall time <elapsed> seconds\nOutput:\n",
}),
serde_json::json!({
"type": "input_text",
"text": "x".repeat(50_000),
}),
]
text_item(
&custom_tool_output_items(&second_mock.single_request(), "call-1"),
/*index*/ 1
),
"x".repeat(50_000)
);
Ok(())
@@ -808,17 +765,11 @@ text(result.output);
.await?;
assert_eq!(
custom_tool_output_items_with_stable_wall_time(&second_mock.single_request(), "call-1"),
vec![
serde_json::json!({
"type": "input_text",
"text": "Script completed\nWall time <elapsed> seconds\nOutput:\n",
}),
serde_json::json!({
"type": "input_text",
"text": "x".repeat(50_000),
}),
]
text_item(
&custom_tool_output_items(&second_mock.single_request(), "call-1"),
/*index*/ 1
),
"x".repeat(50_000)
);
Ok(())
@@ -846,17 +797,11 @@ text(result.output);
.await?;
assert_eq!(
custom_tool_output_items_with_stable_wall_time(&second_mock.single_request(), "call-1"),
vec![
serde_json::json!({
"type": "input_text",
"text": "Script completed\nWall time <elapsed> seconds\nOutput:\n",
}),
serde_json::json!({
"type": "input_text",
"text": "x".repeat(50_000),
}),
]
text_item(
&custom_tool_output_items(&second_mock.single_request(), "call-1"),
/*index*/ 1
),
"x".repeat(50_000)
);
Ok(())
@@ -881,17 +826,11 @@ text(result.output);
.await?;
assert_eq!(
custom_tool_output_items_with_stable_wall_time(&second_mock.single_request(), "call-1"),
vec![
serde_json::json!({
"type": "input_text",
"text": "Script completed\nWall time <elapsed> seconds\nOutput:\n",
}),
serde_json::json!({
"type": "input_text",
"text": "Total output lines: 1\n\n0123456789…5 tokens truncated…0123456789",
}),
]
text_item(
&custom_tool_output_items(&second_mock.single_request(), "call-1"),
/*index*/ 1
),
"Total output lines: 1\n\n0123456789…5 tokens truncated…0123456789"
);
Ok(())