use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct ArtifactRecord {
run_id: String,
key: String,
cas_hash: String,
size_bytes: u64,
created_at: DateTime<Utc>,
}
impl ArtifactRecord {
#[must_use]
pub fn new(
run_id: impl Into<String>,
key: impl Into<String>,
cas_hash: impl Into<String>,
size_bytes: u64,
) -> Self {
Self {
run_id: run_id.into(),
key: key.into(),
cas_hash: cas_hash.into(),
size_bytes,
created_at: Utc::now(),
}
}
#[must_use]
pub fn run_id(&self) -> &str {
&self.run_id
}
#[must_use]
pub fn key(&self) -> &str {
&self.key
}
#[must_use]
pub fn cas_hash(&self) -> &str {
&self.cas_hash
}
#[must_use]
pub const fn size_bytes(&self) -> u64 {
self.size_bytes
}
#[must_use]
pub const fn created_at(&self) -> DateTime<Utc> {
self.created_at
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_artifact_record_new() {
let artifact = ArtifactRecord::new("run-1", "model.pt", "sha256:abc123", 1000);
assert_eq!(artifact.run_id(), "run-1");
assert_eq!(artifact.key(), "model.pt");
assert_eq!(artifact.cas_hash(), "sha256:abc123");
assert_eq!(artifact.size_bytes(), 1000);
}
#[test]
fn test_artifact_cas_hash_format() {
let artifact = ArtifactRecord::new("run-1", "data.bin", "sha256:e3b0c44298fc1c14", 0);
assert!(artifact.cas_hash().starts_with("sha256:"));
}
}