use uuid::Uuid;
use crate::entities::{Artifact, ArtifactLookup, NewArtifact};
use crate::store::StoreFuture;
pub trait ArtifactStore: Send + Sync {
fn create_artifact(&self, artifact: NewArtifact) -> StoreFuture<'_, Artifact>;
fn get_artifact(&self, step_id: Uuid, name: &str) -> StoreFuture<'_, Option<Artifact>>;
fn list_artifacts_for_run(&self, run_id: Uuid) -> StoreFuture<'_, Vec<Artifact>>;
fn find_artifact_for_input(&self, lookup: ArtifactLookup) -> StoreFuture<'_, Option<Artifact>>;
}
#[cfg(test)]
mod tests {
use uuid::Uuid;
use crate::entities::{ArtifactLookup, NewArtifact};
#[test]
fn new_artifact_carries_its_own_id() {
let id = Uuid::now_v7();
let req = NewArtifact {
id,
run_id: Uuid::now_v7(),
step_id: Uuid::now_v7(),
name: "a.txt".to_string(),
storage_key: format!("artifacts/x/y/{id}"),
content_type: "text/plain".to_string(),
size_bytes: 1,
sha256: "0".repeat(64),
};
assert!(req.storage_key.ends_with(&id.to_string()));
}
#[test]
fn lookup_is_scoped_to_a_run_and_attempt() {
let lookup = ArtifactLookup {
run_id: Uuid::now_v7(),
attempt: 2,
before_position: 0,
step_name: "build".to_string(),
name: "a.txt".to_string(),
};
assert_eq!(lookup.attempt, 2);
assert_eq!(lookup.before_position, 0);
}
}