use std::path::Path;
fn release_yml() -> String {
let path = Path::new(env!("CARGO_MANIFEST_DIR")).join(".github/workflows/release.yml");
std::fs::read_to_string(&path).unwrap_or_else(|e| panic!("read {}: {e}", path.display()))
}
fn winget_job() -> String {
release_yml()
.split_once("winget-publish:")
.expect("release.yml must define the winget-publish job")
.1
.to_string()
}
#[test]
fn release_workflow_publishes_to_winget() {
let job = winget_job();
assert!(
job.contains("komac update kbrdn1.gwm"),
"winget-publish must run `komac update` for the kbrdn1.gwm package"
);
assert!(
job.contains("gwm-${TAG}-x86_64-pc-windows-msvc.zip"),
"winget-publish must submit the windows .zip release asset"
);
assert!(
job.contains("${TAG#v}"),
"winget-publish must strip the tag's v prefix to match the winget version"
);
}
#[test]
fn komac_is_pinned_and_digest_anchored() {
let job = winget_job();
assert!(
job.contains("KOMAC_VERSION: 2.16.0"),
"komac must be pinned to an explicit version"
);
let digest = job
.split_once("KOMAC_SHA256:")
.expect("komac must be pinned to an expected sha256")
.1
.split_whitespace()
.next()
.expect("KOMAC_SHA256 has a value");
assert_eq!(digest.len(), 64, "KOMAC_SHA256 must be a 64-hex sha256, got `{digest}`");
assert!(
digest.chars().all(|c| c.is_ascii_hexdigit()),
"KOMAC_SHA256 must be hex, got `{digest}`"
);
assert!(
job.contains("sha256sum -c"),
"the pinned komac download must be checked against KOMAC_SHA256"
);
assert!(
!job.contains("--pattern SHA256SUMS"),
"must not re-fetch upstream SHA256SUMS — that is not an independent anchor"
);
}
#[test]
fn winget_publish_does_not_use_the_unpinned_releaser_action() {
let yml = release_yml();
assert!(
!yml.contains("uses: vedantmgoyal9/winget-releaser"),
"winget-publish must run komac directly, not the winget-releaser action"
);
}
#[test]
fn winget_publish_is_stable_only_and_advisory() {
let job = winget_job();
assert!(job.contains("-rc."), "winget-publish must gate out -rc. pre-releases");
assert!(
job.contains("continue-on-error: true"),
"winget-publish must be advisory while WINGET_TOKEN / the first manifest are pending"
);
assert!(
job.contains("${{ secrets.WINGET_TOKEN }}"),
"winget-publish must read the token from the WINGET_TOKEN secret"
);
}