mirror of
https://github.com/openai/codex.git
synced 2026-11-21 22:50:37 +00:00
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:
@@ -2414,8 +2414,10 @@ mod tests {
|
||||
// These are only allowed in *Params types, except additive stable fields
|
||||
// that older servers omit and newer servers may return as null.
|
||||
let legacy_optional_nullable_field = (path
|
||||
== Path::new("v2/GetAccountTokenUsageResponse.ts")
|
||||
&& field_prefix.trim() == "threadUsage?")
|
||||
== Path::new("v2/FsGetMetadataResponse.ts")
|
||||
&& field_prefix.trim() == "sizeBytes?")
|
||||
|| (path == Path::new("v2/GetAccountTokenUsageResponse.ts")
|
||||
&& field_prefix.trim() == "threadUsage?")
|
||||
|| (path == Path::new("v2/ThreadUsage.ts")
|
||||
&& field_prefix.trim() == "nativeUsageUsdMicros?")
|
||||
|| (path == Path::new("v2/ThreadItem.ts")
|
||||
|
||||
@@ -107,6 +107,9 @@ pub struct FsGetMetadataResponse {
|
||||
/// File modification time in Unix milliseconds when available, otherwise `0`.
|
||||
#[ts(type = "number")]
|
||||
pub modified_at_ms: i64,
|
||||
/// Size in bytes if the path resolves to a regular file, otherwise null. Older servers omit this field.
|
||||
#[ts(type = "number | null", optional)]
|
||||
pub size_bytes: Option<u64>,
|
||||
}
|
||||
|
||||
/// List direct child names for a directory.
|
||||
|
||||
@@ -1271,6 +1271,7 @@ fn fs_get_metadata_response_round_trips_minimal_fields() {
|
||||
is_symlink: false,
|
||||
created_at_ms: 123,
|
||||
modified_at_ms: 456,
|
||||
size_bytes: Some(5),
|
||||
};
|
||||
|
||||
let value = serde_json::to_value(&response).expect("serialize fs/getMetadata response");
|
||||
@@ -1282,12 +1283,28 @@ fn fs_get_metadata_response_round_trips_minimal_fields() {
|
||||
"isSymlink": false,
|
||||
"createdAtMs": 123,
|
||||
"modifiedAtMs": 456,
|
||||
"sizeBytes": 5,
|
||||
})
|
||||
);
|
||||
|
||||
let decoded = serde_json::from_value::<FsGetMetadataResponse>(value)
|
||||
let decoded = serde_json::from_value::<FsGetMetadataResponse>(value.clone())
|
||||
.expect("deserialize fs/getMetadata response");
|
||||
assert_eq!(decoded, response);
|
||||
|
||||
let mut legacy_value = value;
|
||||
legacy_value
|
||||
.as_object_mut()
|
||||
.expect("metadata object")
|
||||
.remove("sizeBytes");
|
||||
let legacy = serde_json::from_value::<FsGetMetadataResponse>(legacy_value)
|
||||
.expect("deserialize fs/getMetadata response from an older server");
|
||||
assert_eq!(
|
||||
legacy,
|
||||
FsGetMetadataResponse {
|
||||
size_bytes: None,
|
||||
..response
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user