mirror of
https://github.com/NVIDIA/OpenShell.git
synced 2026-10-13 04:51:00 +08:00
feat(cli): format created_at as human-readable datetime in provider list JSON/YAML
Update provider_to_json() to format created_at_ms as a human-readable datetime string using format_epoch_ms(), matching the pattern used by sandbox_to_json(). Changes: - Field name: created_at_ms → created_at - Value format: Raw milliseconds → "YYYY-MM-DD HH:MM:SS" - Implementation: Use format_epoch_ms(meta.created_at_ms) This change: - Aligns provider list output with sandbox list output for consistency - Makes JSON/YAML output more human-readable for interactive use - Follows the established pattern across all *_to_json() functions Breaking change: Field renamed and type changed (number → string). However, this feature was just added in PR #1830 and hasn't been released yet, so no users are affected. Example output: Before: {"created_at_ms": 1234567890000} After: {"created_at": "2009-02-13 23:31:30"} Tests updated: - provider_to_json_includes_metadata_fields_when_present: Assert formatted string - provider_to_json_omits_zero_metadata_fields: Update field name - provider_to_json_formats_created_at_as_human_readable: New test validating format
This commit is contained in:
@@ -4815,8 +4815,8 @@ fn provider_to_json(provider: &Provider) -> serde_json::Value {
|
||||
}
|
||||
if meta.created_at_ms != 0 {
|
||||
obj.insert(
|
||||
"created_at_ms".to_string(),
|
||||
serde_json::json!(meta.created_at_ms),
|
||||
"created_at".to_string(),
|
||||
serde_json::json!(format_epoch_ms(meta.created_at_ms)),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -9414,7 +9414,7 @@ mod tests {
|
||||
id: "prov-123".to_string(),
|
||||
name: "test-provider".to_string(),
|
||||
resource_version: 42,
|
||||
created_at_ms: 1_234_567_890,
|
||||
created_at_ms: 1_234_567_890_000,
|
||||
labels,
|
||||
};
|
||||
|
||||
@@ -9429,7 +9429,7 @@ mod tests {
|
||||
let json = super::provider_to_json(&provider);
|
||||
|
||||
assert_eq!(json["resource_version"], 42);
|
||||
assert_eq!(json["created_at_ms"], 1_234_567_890);
|
||||
assert_eq!(json["created_at"], "2009-02-13 23:31:30");
|
||||
assert_eq!(json["labels"]["env"], "prod");
|
||||
}
|
||||
|
||||
@@ -9458,8 +9458,8 @@ mod tests {
|
||||
"zero resource_version should be omitted"
|
||||
);
|
||||
assert!(
|
||||
json.get("created_at_ms").is_none(),
|
||||
"zero created_at_ms should be omitted"
|
||||
json.get("created_at").is_none(),
|
||||
"zero created_at should be omitted"
|
||||
);
|
||||
assert!(
|
||||
json.get("labels").is_none(),
|
||||
@@ -9487,4 +9487,31 @@ mod tests {
|
||||
1_234_567_890
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn provider_to_json_formats_created_at_as_human_readable() {
|
||||
let metadata = ObjectMeta {
|
||||
id: "prov-123".to_string(),
|
||||
name: "test-provider".to_string(),
|
||||
created_at_ms: 1_609_459_200_000, // 2021-01-01 00:00:00
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let provider = Provider {
|
||||
metadata: Some(metadata),
|
||||
r#type: "anthropic".to_string(),
|
||||
credentials: std::collections::HashMap::new(),
|
||||
config: std::collections::HashMap::new(),
|
||||
credential_expires_at_ms: std::collections::HashMap::new(),
|
||||
};
|
||||
|
||||
let json = super::provider_to_json(&provider);
|
||||
|
||||
// Should format as human-readable datetime, not raw milliseconds
|
||||
assert_eq!(json["created_at"], "2021-01-01 00:00:00");
|
||||
assert!(
|
||||
json.get("created_at_ms").is_none(),
|
||||
"raw milliseconds field should not exist"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user