Skip to content

Commit a5f59ce

Browse files
committed
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
1 parent 703169c commit a5f59ce

1 file changed

Lines changed: 33 additions & 6 deletions

File tree

  • crates/openshell-cli/src

‎crates/openshell-cli/src/run.rs‎

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4815,8 +4815,8 @@ fn provider_to_json(provider: &Provider) -> serde_json::Value {
48154815
}
48164816
if meta.created_at_ms != 0 {
48174817
obj.insert(
4818-
"created_at_ms".to_string(),
4819-
serde_json::json!(meta.created_at_ms),
4818+
"created_at".to_string(),
4819+
serde_json::json!(format_epoch_ms(meta.created_at_ms)),
48204820
);
48214821
}
48224822
}
@@ -9414,7 +9414,7 @@ mod tests {
94149414
id: "prov-123".to_string(),
94159415
name: "test-provider".to_string(),
94169416
resource_version: 42,
9417-
created_at_ms: 1_234_567_890,
9417+
created_at_ms: 1_234_567_890_000,
94189418
labels,
94199419
};
94209420

@@ -9429,7 +9429,7 @@ mod tests {
94299429
let json = super::provider_to_json(&provider);
94309430

94319431
assert_eq!(json["resource_version"], 42);
9432-
assert_eq!(json["created_at_ms"], 1_234_567_890);
9432+
assert_eq!(json["created_at"], "2009-02-13 23:31:30");
94339433
assert_eq!(json["labels"]["env"], "prod");
94349434
}
94359435

@@ -9458,8 +9458,8 @@ mod tests {
94589458
"zero resource_version should be omitted"
94599459
);
94609460
assert!(
9461-
json.get("created_at_ms").is_none(),
9462-
"zero created_at_ms should be omitted"
9461+
json.get("created_at").is_none(),
9462+
"zero created_at should be omitted"
94639463
);
94649464
assert!(
94659465
json.get("labels").is_none(),
@@ -9487,4 +9487,31 @@ mod tests {
94879487
1_234_567_890
94889488
);
94899489
}
9490+
9491+
#[test]
9492+
fn provider_to_json_formats_created_at_as_human_readable() {
9493+
let metadata = ObjectMeta {
9494+
id: "prov-123".to_string(),
9495+
name: "test-provider".to_string(),
9496+
created_at_ms: 1_609_459_200_000, // 2021-01-01 00:00:00
9497+
..Default::default()
9498+
};
9499+
9500+
let provider = Provider {
9501+
metadata: Some(metadata),
9502+
r#type: "anthropic".to_string(),
9503+
credentials: std::collections::HashMap::new(),
9504+
config: std::collections::HashMap::new(),
9505+
credential_expires_at_ms: std::collections::HashMap::new(),
9506+
};
9507+
9508+
let json = super::provider_to_json(&provider);
9509+
9510+
// Should format as human-readable datetime, not raw milliseconds
9511+
assert_eq!(json["created_at"], "2021-01-01 00:00:00");
9512+
assert!(
9513+
json.get("created_at_ms").is_none(),
9514+
"raw milliseconds field should not exist"
9515+
);
9516+
}
94909517
}

0 commit comments

Comments
 (0)