Return file sizes from fs/getMetadata (#62653)

## What changed

Add `sizeBytes` to the app server's metadata response so clients can
read a file's size in bytes from its metadata. The field reports the
target file's size for symlinks to regular files and is `null` for
paths that resolve to directories or other non-regular files. The
protocol schemas and generated Python SDK model accept responses from
older servers that omit the field.

## Testing

Cover byte counts for regular files and symlinks to files, explicit
`null` for directories, and decoding responses that omit `sizeBytes`.

GitOrigin-RevId: fcc7bda9e55bd0584c1eff4af059422af282da9f
This commit is contained in:
Felipe Coury
2026-11-20 02:42:43 +00:00
committed by copyberry
parent 2c1b4c7c35
commit e787cf7024
12 changed files with 90 additions and 25 deletions
@@ -126,6 +126,7 @@ impl FsRequestProcessor {
is_symlink: metadata.is_symlink,
created_at_ms: metadata.created_at_ms,
modified_at_ms: metadata.modified_at_ms,
size_bytes: metadata.is_file.then_some(metadata.size),
})
}
+24 -21
View File
@@ -70,7 +70,7 @@ fn absolute_path(path: PathBuf) -> AbsolutePathBuf {
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn fs_get_metadata_returns_only_used_fields() -> Result<()> {
async fn fs_get_metadata_returns_file_size() -> Result<()> {
let codex_home = TempDir::new()?;
let file_path = codex_home.path().join("note.txt");
std::fs::write(&file_path, "hello")?;
@@ -87,23 +87,6 @@ async fn fs_get_metadata_returns_only_used_fields() -> Result<()> {
)
.await??;
let result = response
.result
.as_object()
.context("fs/getMetadata result should be an object")?;
let mut keys = result.keys().cloned().collect::<Vec<_>>();
keys.sort();
assert_eq!(
keys,
vec![
"createdAtMs".to_string(),
"isDirectory".to_string(),
"isFile".to_string(),
"isSymlink".to_string(),
"modifiedAtMs".to_string(),
]
);
let stat: FsGetMetadataResponse = to_response(response)?;
assert_eq!(
stat,
@@ -113,6 +96,7 @@ async fn fs_get_metadata_returns_only_used_fields() -> Result<()> {
is_symlink: false,
created_at_ms: stat.created_at_ms,
modified_at_ms: stat.modified_at_ms,
size_bytes: Some(5),
}
);
assert!(
@@ -120,6 +104,18 @@ async fn fs_get_metadata_returns_only_used_fields() -> Result<()> {
"modifiedAtMs should be populated for existing files"
);
let request_id = mcp
.send_fs_get_metadata_request(codex_app_server_protocol::FsGetMetadataParams {
path: absolute_path(codex_home.path().to_path_buf()),
})
.await?;
let response = timeout(
DEFAULT_READ_TIMEOUT,
mcp.read_stream_until_response_message(RequestId::Integer(request_id)),
)
.await??;
assert_eq!(response.result.get("sizeBytes"), Some(&json!(null)));
Ok(())
}
@@ -168,9 +164,16 @@ async fn fs_get_metadata_reports_symlink() -> Result<()> {
.await??;
let stat: FsGetMetadataResponse = to_response(response)?;
assert_eq!(stat.is_directory, false);
assert_eq!(stat.is_file, true);
assert_eq!(stat.is_symlink, true);
assert_eq!(
stat,
FsGetMetadataResponse {
is_directory: false,
is_file: true,
is_symlink: true,
size_bytes: Some(5),
..stat
}
);
Ok(())
}