Skip to content

Commit a4f61d2

Browse files
committed
truncate
1 parent a4be4d7 commit a4f61d2

File tree

4 files changed

+297
-347
lines changed

4 files changed

+297
-347
lines changed

codex-rs/core/src/codex.rs

Lines changed: 2 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -2254,10 +2254,6 @@ mod tests {
22542254
use crate::state::TaskKind;
22552255
use crate::tasks::SessionTask;
22562256
use crate::tasks::SessionTaskContext;
2257-
use crate::tools::MODEL_FORMAT_HEAD_LINES;
2258-
use crate::tools::MODEL_FORMAT_MAX_BYTES;
2259-
use crate::tools::MODEL_FORMAT_MAX_LINES;
2260-
use crate::tools::MODEL_FORMAT_TAIL_LINES;
22612257
use crate::tools::ToolRouter;
22622258
use crate::tools::context::ToolInvocation;
22632259
use crate::tools::context::ToolOutput;
@@ -2344,94 +2340,8 @@ mod tests {
23442340
assert_eq!(expected, got);
23452341
}
23462342

2347-
#[test]
2348-
fn model_truncation_head_tail_by_lines() {
2349-
// Build 400 short lines so line-count limit, not byte budget, triggers truncation
2350-
let lines: Vec<String> = (1..=400).map(|i| format!("line{i}")).collect();
2351-
let full = lines.join("\n");
2352-
2353-
let exec = ExecToolCallOutput {
2354-
exit_code: 0,
2355-
stdout: StreamOutput::new(String::new()),
2356-
stderr: StreamOutput::new(String::new()),
2357-
aggregated_output: StreamOutput::new(full),
2358-
duration: StdDuration::from_secs(1),
2359-
timed_out: false,
2360-
};
2361-
2362-
let out = format_exec_output_str(&exec);
2363-
2364-
// Strip truncation header if present for subsequent assertions
2365-
let body = out
2366-
.strip_prefix("Total output lines: ")
2367-
.and_then(|rest| rest.split_once("\n\n").map(|x| x.1))
2368-
.unwrap_or(out.as_str());
2369-
2370-
// Expect elision marker with correct counts
2371-
let omitted = 400 - MODEL_FORMAT_MAX_LINES; // 144
2372-
let marker = format!("\n[... omitted {omitted} of 400 lines ...]\n\n");
2373-
assert!(out.contains(&marker), "missing marker: {out}");
2374-
2375-
// Validate head and tail
2376-
let parts: Vec<&str> = body.split(&marker).collect();
2377-
assert_eq!(parts.len(), 2, "expected one marker split");
2378-
let head = parts[0];
2379-
let tail = parts[1];
2380-
2381-
let expected_head: String = (1..=MODEL_FORMAT_HEAD_LINES)
2382-
.map(|i| format!("line{i}"))
2383-
.collect::<Vec<_>>()
2384-
.join("\n");
2385-
assert!(head.starts_with(&expected_head), "head mismatch");
2386-
2387-
let expected_tail: String = ((400 - MODEL_FORMAT_TAIL_LINES + 1)..=400)
2388-
.map(|i| format!("line{i}"))
2389-
.collect::<Vec<_>>()
2390-
.join("\n");
2391-
assert!(tail.ends_with(&expected_tail), "tail mismatch");
2392-
}
2393-
2394-
#[test]
2395-
fn model_truncation_respects_byte_budget() {
2396-
// Construct a large output (about 100kB) so byte budget dominates
2397-
let big_line = "x".repeat(100);
2398-
let full = std::iter::repeat_n(big_line, 1000)
2399-
.collect::<Vec<_>>()
2400-
.join("\n");
2401-
2402-
let exec = ExecToolCallOutput {
2403-
exit_code: 0,
2404-
stdout: StreamOutput::new(String::new()),
2405-
stderr: StreamOutput::new(String::new()),
2406-
aggregated_output: StreamOutput::new(full.clone()),
2407-
duration: StdDuration::from_secs(1),
2408-
timed_out: false,
2409-
};
2410-
2411-
let out = format_exec_output_str(&exec);
2412-
// Keep strict budget on the truncated body (excluding header)
2413-
let body = out
2414-
.strip_prefix("Total output lines: ")
2415-
.and_then(|rest| rest.split_once("\n\n").map(|x| x.1))
2416-
.unwrap_or(out.as_str());
2417-
assert!(body.len() <= MODEL_FORMAT_MAX_BYTES, "exceeds byte budget");
2418-
assert!(out.contains("omitted"), "should contain elision marker");
2419-
2420-
// Ensure head and tail are drawn from the original
2421-
assert!(full.starts_with(body.chars().take(8).collect::<String>().as_str()));
2422-
assert!(
2423-
full.ends_with(
2424-
body.chars()
2425-
.rev()
2426-
.take(8)
2427-
.collect::<String>()
2428-
.chars()
2429-
.rev()
2430-
.collect::<String>()
2431-
.as_str()
2432-
)
2433-
);
2434-
}
2343+
// Truncation tests have moved to conversation_history where
2344+
// the model-facing formatting now lives.
24352345

24362346
#[test]
24372347
fn includes_timed_out_message() {

0 commit comments

Comments
 (0)