use workload_spec::ImageRef;
pub const YAH_IMAGE_REGISTRY: &str = "ghcr.io";
pub const YAH_IMAGE_OWNER: &str = "yah-ai";
pub const YAH_IMAGE_TAG: &str = "latest";
pub const YAH_BASE_DIGEST: Option<&str> = option_env!("YAH_BASE_DIGEST");
pub const YAH_RUST_DIGEST: Option<&str> = option_env!("YAH_RUST_DIGEST");
pub const YAH_RUST_BUN_DIGEST: Option<&str> = option_env!("YAH_RUST_BUN_DIGEST");
pub const YAH_WARDEN_DIGEST: Option<&str> = option_env!("YAH_WARDEN_DIGEST");
pub const YAH_MINIFLARE_DIGEST: Option<&str> = option_env!("YAH_MINIFLARE_DIGEST");
pub const DEFAULT_IMAGE_REPOSITORY: &str = "yah-ai/yah-rust-bun";
pub fn default_forge_image() -> ImageRef {
catalog_image("yah-rust-bun")
}
pub fn catalog_image(name: &str) -> ImageRef {
ImageRef {
registry: YAH_IMAGE_REGISTRY.into(),
repository: format!("{YAH_IMAGE_OWNER}/{name}"),
tag: YAH_IMAGE_TAG.into(),
digest: catalog_digest(name)
.map(Into::into)
.unwrap_or_else(workload_spec::testing::test_digest),
}
}
pub fn catalog_digest(name: &str) -> Option<&'static str> {
match name {
"yah-base" => YAH_BASE_DIGEST,
"yah-rust" => YAH_RUST_DIGEST,
"yah-rust-bun" => YAH_RUST_BUN_DIGEST,
"yah-yubaba" => YAH_WARDEN_DIGEST,
"yah-miniflare" => YAH_MINIFLARE_DIGEST,
_ => None,
}
}
#[cfg(test)]
mod default_image {
use super::*;
#[test]
fn struct_is_well_formed() {
let img = default_forge_image();
assert_eq!(img.registry, YAH_IMAGE_REGISTRY);
assert_eq!(img.repository, DEFAULT_IMAGE_REPOSITORY);
assert!(!img.tag.is_empty(), "tag must not be empty");
assert!(
img.digest.starts_with("sha256:"),
"digest must be sha256: prefixed, got {:?}",
img.digest
);
assert!(img.digest.len() > 7, "digest must not be empty after sha256: prefix");
}
#[test]
fn catalog_image_resolves_known_and_unknown_names() {
for known in ["yah-base", "yah-rust", "yah-rust-bun", "yah-yubaba", "yah-miniflare"] {
let img = catalog_image(known);
assert_eq!(img.registry, YAH_IMAGE_REGISTRY);
assert_eq!(img.repository, format!("{YAH_IMAGE_OWNER}/{known}"));
}
let unknown = catalog_image("yah-cuda-special");
assert_eq!(unknown.repository, format!("{YAH_IMAGE_OWNER}/yah-cuda-special"));
assert_eq!(
unknown.digest,
workload_spec::testing::TEST_DIGEST,
"unknown catalog name falls back to the test-fixture digest sentinel",
);
}
#[test]
fn catalog_digest_unknown_name_is_none() {
assert!(catalog_digest("does-not-exist").is_none());
}
#[test]
#[ignore]
fn pull() {
let img = default_forge_image();
assert_ne!(
img.digest,
workload_spec::testing::TEST_DIGEST,
"YAH_RUST_BUN_DIGEST must be set; \
recompile with: YAH_RUST_BUN_DIGEST=sha256:<hash> cargo test …",
);
let full_ref = format!("{}/{}@{}", img.registry, img.repository, img.digest);
let pull_status = std::process::Command::new("docker")
.args(["pull", &full_ref])
.status()
.expect("docker not found on PATH or daemon not running");
assert!(pull_status.success(), "docker pull failed for {full_ref}");
let cosign_status = std::process::Command::new("cosign")
.args([
"verify",
&full_ref,
"--certificate-oidc-issuer",
"https://token.actions.githubusercontent.com",
"--certificate-identity-regexp",
r"^https://github\.com/yah-ai/yah/\.github/workflows/release\.yml@",
])
.status()
.expect("cosign not found on PATH");
assert!(cosign_status.success(), "cosign verify failed for {full_ref}");
}
}