mirror of
https://github.com/openai/codex.git
synced 2026-04-30 11:21:34 +03:00
Trim app-server test JSON-RPC logs
This commit is contained in:
@@ -87,6 +87,7 @@ pub struct McpProcess {
|
||||
}
|
||||
|
||||
pub const DEFAULT_CLIENT_NAME: &str = "codex-app-server-tests";
|
||||
const MAX_LOGGED_JSONRPC_MESSAGE_CHARS: usize = 512;
|
||||
|
||||
impl McpProcess {
|
||||
pub async fn new(codex_home: &Path) -> anyhow::Result<Self> {
|
||||
@@ -921,11 +922,14 @@ impl McpProcess {
|
||||
}
|
||||
|
||||
async fn send_jsonrpc_message(&mut self, message: JSONRPCMessage) -> anyhow::Result<()> {
|
||||
eprintln!("writing message to stdin: {message:?}");
|
||||
let Some(stdin) = self.stdin.as_mut() else {
|
||||
anyhow::bail!("mcp stdin closed");
|
||||
};
|
||||
let payload = serde_json::to_string(&message)?;
|
||||
eprintln!(
|
||||
"writing message to stdin: {}",
|
||||
truncate_log_message(&payload)
|
||||
);
|
||||
stdin.write_all(payload.as_bytes()).await?;
|
||||
stdin.write_all(b"\n").await?;
|
||||
stdin.flush().await?;
|
||||
@@ -935,8 +939,8 @@ impl McpProcess {
|
||||
async fn read_jsonrpc_message(&mut self) -> anyhow::Result<JSONRPCMessage> {
|
||||
let mut line = String::new();
|
||||
self.stdout.read_line(&mut line).await?;
|
||||
eprintln!("read message from stdout: {}", truncate_log_message(&line));
|
||||
let message = serde_json::from_str::<JSONRPCMessage>(&line)?;
|
||||
eprintln!("read message from stdout: {message:?}");
|
||||
Ok(message)
|
||||
}
|
||||
|
||||
@@ -1080,6 +1084,20 @@ impl McpProcess {
|
||||
}
|
||||
}
|
||||
|
||||
fn truncate_log_message(message: &str) -> String {
|
||||
let trimmed = message.trim_end();
|
||||
let total_chars = trimmed.chars().count();
|
||||
if total_chars <= MAX_LOGGED_JSONRPC_MESSAGE_CHARS {
|
||||
return trimmed.to_string();
|
||||
}
|
||||
|
||||
let preview = trimmed
|
||||
.chars()
|
||||
.take(MAX_LOGGED_JSONRPC_MESSAGE_CHARS)
|
||||
.collect::<String>();
|
||||
format!("{preview}... [truncated, {total_chars} chars total]")
|
||||
}
|
||||
|
||||
impl Drop for McpProcess {
|
||||
fn drop(&mut self) {
|
||||
// These tests spawn a `codex-app-server` child process.
|
||||
|
||||
Reference in New Issue
Block a user