Surface unified exec output omissions

This commit is contained in:
jif-oai
2026-07-09 18:40:08 +01:00
parent 9b9ac9c28a
commit 645c392924
5 changed files with 29 additions and 3 deletions
@@ -326,7 +326,7 @@ async fn resolve_aggregated_output(
return fallback;
}
String::from_utf8_lossy(&guard.to_bytes()).to_string()
String::from_utf8_lossy(&guard.to_bytes_with_omission_marker()).to_string()
}
#[cfg(test)]
@@ -116,6 +116,26 @@ impl HeadTailBuffer {
out
}
/// Return the retained output with an explicit marker between the head and
/// tail when bytes were omitted.
pub(crate) fn to_bytes_with_omission_marker(&self) -> Vec<u8> {
if self.omitted_bytes == 0 {
return self.to_bytes();
}
let omitted_bytes = self.omitted_bytes;
let marker = format!("\n... {omitted_bytes} bytes omitted ...\n");
let mut out = Vec::with_capacity(self.retained_bytes().saturating_add(marker.len()));
for chunk in self.head.iter() {
out.extend_from_slice(chunk);
}
out.extend_from_slice(marker.as_bytes());
for chunk in self.tail.iter() {
out.extend_from_slice(chunk);
}
out
}
/// Drain all retained chunks from the buffer and reset its state.
///
/// The drained chunks are returned in head-then-tail order. Omitted bytes
@@ -16,6 +16,10 @@ fn keeps_prefix_and_suffix_when_over_budget() {
let rendered = String::from_utf8_lossy(&buf.to_bytes()).to_string();
assert!(rendered.starts_with("01234"));
assert!(rendered.ends_with("89ab"));
assert_eq!(
String::from_utf8_lossy(&buf.to_bytes_with_omission_marker()),
"01234\n... 2 bytes omitted ...\n789ab"
);
}
#[test]
@@ -1285,7 +1285,7 @@ impl UnifiedExecProcessManager {
}
}
collected.to_bytes()
collected.to_bytes_with_omission_marker()
}
async fn extend_deadlines_while_paused(
@@ -278,8 +278,10 @@ async fn output_collection_stays_bounded_across_repeated_drains() {
let (collected, ()) = tokio::join!(collect, produce);
let head_bytes = crate::unified_exec::UNIFIED_EXEC_OUTPUT_MAX_BYTES / 2;
let tail_bytes = crate::unified_exec::UNIFIED_EXEC_OUTPUT_MAX_BYTES - head_bytes;
let omitted_bytes = 2 * crate::unified_exec::UNIFIED_EXEC_OUTPUT_MAX_BYTES;
let mut expected = vec![b'a'; head_bytes];
expected.resize(head_bytes + tail_bytes, b'c');
expected.extend_from_slice(format!("\n... {omitted_bytes} bytes omitted ...\n").as_bytes());
expected.resize(expected.len() + tail_bytes, b'c');
assert_eq!(collected, expected);
}