use crate::harness_runtime::{Artifact, Delivery, Previous, Shape, Software};
pub(crate) const ARTIFACTS: &[Artifact] = &[
Artifact {
platform: "linux/arm64",
url: "https://github.com/earendil-works/pi/releases/download/v0.99.1/pi-linux-arm64.tar.gz",
bytes: 42_712_503,
sha256: "sha256:e632a9e55bc86525ffd0f71d09185d630883f64b9cfc858f731d1edc92716954",
shape: Shape::GzipTar,
member: "pi/pi",
},
Artifact {
platform: "linux/x86_64",
url: "https://github.com/earendil-works/pi/releases/download/v0.99.1/pi-linux-x64.tar.gz",
bytes: 42_608_802,
sha256: "sha256:c81b9a367bb2985fa45a2c0d4f12b147acc43655683910a5abf937fe22208425",
shape: Shape::GzipTar,
member: "pi/pi",
},
Artifact {
platform: "macos/arm64",
url: "https://github.com/earendil-works/pi/releases/download/v0.99.1/pi-darwin-arm64.tar.gz",
bytes: 31_069_587,
sha256: "sha256:4692aba1dcd48219b61edb4ecebc3c33f6199ebe65299228fce5ba69c31a23a6",
shape: Shape::GzipTar,
member: "pi/pi",
},
Artifact {
platform: "macos/x86_64",
url: "https://github.com/earendil-works/pi/releases/download/v0.99.1/pi-darwin-x64.tar.gz",
bytes: 33_524_290,
sha256: "sha256:9ad6fc356f4d08b9d10e8a6f929ac1ba4908dd533544ba989c54c73b92b53e13",
shape: Shape::GzipTar,
member: "pi/pi",
},
Artifact {
platform: "windows/arm64",
url: "https://github.com/earendil-works/pi/releases/download/v0.99.1/pi-windows-arm64.zip",
bytes: 43_737_495,
sha256: "sha256:a16cfd489dbbf9d6c60033cae3d15b035e7b4a5c1260f833f84c4b37f58706fc",
shape: Shape::Zip,
member: "pi.exe",
},
Artifact {
platform: "windows/x86_64",
url: "https://github.com/earendil-works/pi/releases/download/v0.99.1/pi-windows-x64.zip",
bytes: 45_102_770,
sha256: "sha256:7e5c2971c0be6019a8b89edc5e3f0efb4cbdeb0ac236fd3a3307c1f62057528f",
shape: Shape::Zip,
member: "pi.exe",
},
];
pub(crate) const PREVIOUS_ARTIFACTS: &[Artifact] = &[
Artifact {
platform: "linux/arm64",
url: "https://github.com/earendil-works/pi/releases/download/v0.87.1/pi-linux-arm64.tar.gz",
bytes: 42_217_308,
sha256: "sha256:364b4a9f8491450b27a4857d4e3c780dbaf696790821c176a873e860cbbc3b89",
shape: Shape::GzipTar,
member: "pi/pi",
},
Artifact {
platform: "linux/x86_64",
url: "https://github.com/earendil-works/pi/releases/download/v0.87.1/pi-linux-x64.tar.gz",
bytes: 42_120_827,
sha256: "sha256:80d78dd62d50049a006b981d994c61255bcc10e730b0c278d4ea0a755909764c",
shape: Shape::GzipTar,
member: "pi/pi",
},
Artifact {
platform: "macos/arm64",
url: "https://github.com/earendil-works/pi/releases/download/v0.87.1/pi-darwin-arm64.tar.gz",
bytes: 30_563_988,
sha256: "sha256:4f8d288b78c9768d3a4ac6f61f06cd34394b82ac17d5b42d1e44a437add401b7",
shape: Shape::GzipTar,
member: "pi/pi",
},
Artifact {
platform: "macos/x86_64",
url: "https://github.com/earendil-works/pi/releases/download/v0.87.1/pi-darwin-x64.tar.gz",
bytes: 33_033_993,
sha256: "sha256:01d8ee28d7114fec4f4eeedbb7561f790853040e9bfbdeebe79437ab66ea51f5",
shape: Shape::GzipTar,
member: "pi/pi",
},
Artifact {
platform: "windows/arm64",
url: "https://github.com/earendil-works/pi/releases/download/v0.87.1/pi-windows-arm64.zip",
bytes: 43_250_108,
sha256: "sha256:2e0d544999a765018ee5c2ff1a8b1a7e0f5d5b6b1e00b32d8c025d6c1dbcc833",
shape: Shape::Zip,
member: "pi.exe",
},
Artifact {
platform: "windows/x86_64",
url: "https://github.com/earendil-works/pi/releases/download/v0.87.1/pi-windows-x64.zip",
bytes: 44_615_504,
sha256: "sha256:aab2ba67baf8ff97a52d05b62d88e9e65a840c6ea8fa1029a28d62d210d4e5fc",
shape: Shape::Zip,
member: "pi.exe",
},
];
pub(crate) const SOFTWARE: Software = Software {
version: "0.99.1",
command: "pi",
delivery: Delivery::Artifacts(ARTIFACTS),
unsupported: &[],
previous: Some(Previous {
version: "0.87.1",
artifacts: PREVIOUS_ARTIFACTS,
}),
};
#[cfg(test)]
mod tests {
#![allow(clippy::unwrap_used, clippy::panic)]
use crate::harness_runtime::{Delivery, Shape};
use super::SOFTWARE;
fn measured() -> serde_json::Value {
let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
.join("../../references/pi-baseline.json");
serde_json::from_str(&std::fs::read_to_string(path).unwrap()).unwrap()
}
#[test]
fn every_artifact_compiled_in_is_the_one_the_baseline_measured() {
let block = &measured()["software_artifacts"];
assert_eq!(block["version"], SOFTWARE.version);
assert_eq!(block["command"], SOFTWARE.command);
let Delivery::Artifacts(compiled) = SOFTWARE.delivery else {
assert_eq!(block["shape"], "manager");
assert!(block["platforms"].as_object().unwrap().is_empty());
return;
};
let published = block["platforms"].as_object().unwrap();
assert_eq!(
compiled.len(),
published.len(),
"the table and the baseline disagree on how many platforms exist"
);
for artifact in compiled {
let entry = &published[artifact.platform];
assert_eq!(entry["url"], artifact.url, "{}", artifact.platform);
assert_eq!(entry["bytes"], artifact.bytes, "{}", artifact.platform);
assert_eq!(entry["sha256"], artifact.sha256, "{}", artifact.platform);
let member = entry.get("member").and_then(serde_json::Value::as_str);
assert_eq!(
member.unwrap_or(""),
artifact.member,
"{} names a different member",
artifact.platform
);
assert_eq!(
artifact.shape == Shape::Raw,
member.is_none(),
"{} disagrees about whether the bytes are the program",
artifact.platform
);
}
}
#[test]
fn the_version_this_build_can_move_between_is_the_one_measured_before_it() {
let baseline = measured();
let recorded = baseline.get("previous_software_artifacts");
let Some(earlier) = SOFTWARE.previous else {
assert!(
recorded.is_none(),
"the baseline records a previous release and this build names none"
);
return;
};
let block = recorded.unwrap_or_else(|| {
panic!("this build names a previous release the baseline does not record")
});
assert_eq!(block["version"], earlier.version);
assert_ne!(
earlier.version, SOFTWARE.version,
"a second pin equal to the first is one version wearing two names"
);
let published = block["platforms"].as_object().unwrap();
assert_eq!(
earlier.artifacts.len(),
published.len(),
"the previous table and the baseline disagree on how many platforms exist"
);
for artifact in earlier.artifacts {
let entry = &published[artifact.platform];
assert_eq!(entry["url"], artifact.url, "{}", artifact.platform);
assert_eq!(entry["bytes"], artifact.bytes, "{}", artifact.platform);
assert_eq!(entry["sha256"], artifact.sha256, "{}", artifact.platform);
}
}
#[test]
fn a_platform_the_vendor_does_not_publish_is_listed_rather_than_missing() {
let block = &measured()["software_artifacts"];
let unpublished: Vec<&str> = block
.get("unpublished")
.and_then(serde_json::Value::as_array)
.map(|entries| {
entries
.iter()
.filter_map(serde_json::Value::as_str)
.collect()
})
.unwrap_or_default();
assert_eq!(unpublished, SOFTWARE.unsupported);
}
#[test]
fn no_release_calls_a_platform_both_published_and_unpublished() {
let baseline = measured();
for name in ["software_artifacts", "previous_software_artifacts"] {
let Some(block) = baseline.get(name) else {
continue;
};
let published = block["platforms"].as_object().unwrap();
let unpublished = block
.get("unpublished")
.and_then(serde_json::Value::as_array)
.into_iter()
.flatten()
.filter_map(serde_json::Value::as_str);
for platform in unpublished {
assert!(
!published.contains_key(platform),
"{name}: {platform} is both published and unpublished"
);
}
}
}
}