mirror of
https://github.com/openai/codex.git
synced 2026-10-20 17:38:45 +00:00
## What changed - Add `otel.tool_result.max_bytes`, defaulting to 2048 bytes, to control the text included in `codex.tool_result` logs independently of model-visible output limits. - Apply truncation centrally when emitting telemetry, preserve UTF-8 boundaries, and report whether the logged output was truncated. - Record typed tool names and namespaces, agent names, and process-local result sequence numbers while keeping tool arguments and output out of trace events. ## Testing - Cover configuration propagation, UTF-8-safe truncation, raw tool-output logging, and log/trace event routing and fields. GitOrigin-RevId: 89ca76e55f1a09b729e7770ce01f2e4d98f9a22d
68 lines
2.1 KiB
Rust
68 lines
2.1 KiB
Rust
use super::*;
|
|
use pretty_assertions::assert_eq;
|
|
|
|
#[test]
|
|
fn telemetry_preview_returns_original_within_limits() {
|
|
// A literal marker in the tool's own output must not imply telemetry truncation.
|
|
for content in ["", "first\r\nsecond\r\n", TRUNCATION_NOTICE] {
|
|
let preview = telemetry_preview(content, ToolResultLogConfig::default());
|
|
assert!(matches!(preview.text, Cow::Borrowed(_)));
|
|
assert_eq!(
|
|
preview,
|
|
ToolResultPreview {
|
|
text: Cow::Borrowed(content),
|
|
truncated: false
|
|
}
|
|
);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn telemetry_preview_truncates_by_bytes() {
|
|
let limits = ToolResultLogConfig::default();
|
|
let content = "x".repeat(limits.max_bytes + 8);
|
|
let preview = telemetry_preview(&content, limits);
|
|
assert!(preview.truncated);
|
|
assert!(preview.text.contains(TRUNCATION_NOTICE));
|
|
assert!(preview.text.len() <= limits.max_bytes + TRUNCATION_NOTICE.len() + 1);
|
|
assert_eq!(
|
|
telemetry_preview(
|
|
&content,
|
|
ToolResultLogConfig {
|
|
max_bytes: content.len(),
|
|
}
|
|
),
|
|
ToolResultPreview {
|
|
text: Cow::Borrowed(&content),
|
|
truncated: false
|
|
}
|
|
);
|
|
assert_eq!(
|
|
telemetry_preview("éé", ToolResultLogConfig { max_bytes: 3 }),
|
|
ToolResultPreview {
|
|
text: Cow::Owned(format!("é\n{TRUNCATION_NOTICE}")),
|
|
truncated: true
|
|
}
|
|
);
|
|
for (content, max_bytes, expected, truncated) in [
|
|
("", 0, "".to_string(), false),
|
|
("\nsecret", 0, TRUNCATION_NOTICE.to_string(), true),
|
|
(
|
|
"first\r\nsecond",
|
|
7,
|
|
format!("first\r\n{TRUNCATION_NOTICE}"),
|
|
true,
|
|
),
|
|
("first\r\n", 7, "first\r\n".to_string(), false),
|
|
("\n\nsecret", 1, format!("\n{TRUNCATION_NOTICE}"), true),
|
|
] {
|
|
assert_eq!(
|
|
telemetry_preview(content, ToolResultLogConfig { max_bytes }),
|
|
ToolResultPreview {
|
|
text: Cow::Owned(expected),
|
|
truncated
|
|
}
|
|
);
|
|
}
|
|
}
|