2026-09-20 08:57:14 +00:00
|
|
|
//! The check stage's contract: a `ReleaseSource` says what a package's
|
|
|
|
|
//! latest release is and where its releases API lives, and
|
|
|
|
|
//! `version_from_tag` turns the resulting tag into a version string. Each
|
|
|
|
|
//! hosting service implements the trait in its own module (`github`,
|
|
|
|
|
//! `forgejo`) so per-host logic doesn't accumulate here;
|
|
|
|
|
//! `source::for_package` picks the implementation for a package.
|
|
|
|
|
|
|
|
|
|
use anyhow::Result;
|
|
|
|
|
|
|
|
|
|
/// A hosting service a package's releases are published on. `Debug` so a
|
|
|
|
|
/// `Box<dyn ReleaseSource>` can sit in a `Result` that tests unwrap.
|
|
|
|
|
pub trait ReleaseSource: std::fmt::Debug {
|
|
|
|
|
/// The latest release tag for `repo`.
|
|
|
|
|
fn latest_release(&self, client: &reqwest::blocking::Client, repo: &str) -> Result<String>;
|
|
|
|
|
|
|
|
|
|
/// The releases API root, which `fetcher` and `verifier` build their
|
|
|
|
|
/// own paths under. GitHub and Forgejo both serve
|
|
|
|
|
/// `/repos/{owner}/{repo}/releases/tags/{tag}` there with the same
|
|
|
|
|
/// `assets[].{name, browser_download_url}` shape, which is why those
|
|
|
|
|
/// stages need only this and not the source itself.
|
|
|
|
|
fn api(&self) -> &str;
|
2026-09-17 07:00:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Strips a leading `v` from a release tag, e.g. `v2.62.0` -> `2.62.0`.
|
|
|
|
|
///
|
|
|
|
|
/// Some projects (uv) tag releases with the bare version and use it
|
|
|
|
|
/// verbatim in asset filenames; others (scaleway-cli) tag `vX.Y.Z` but
|
|
|
|
|
/// still use the bare version in filenames. This is the version string
|
|
|
|
|
/// substituted into `{version}` placeholders in `asset_pattern` /
|
|
|
|
|
/// `checksum_asset_pattern`, not the tag used for API/attestation calls.
|
|
|
|
|
pub fn version_from_tag(tag: &str) -> &str {
|
|
|
|
|
tag.strip_prefix('v').unwrap_or(tag)
|
First working iteration: check -> fetch -> verify for a real package
Rust PoC (cargo, packages.d/*.toml config) that checks astral-sh/uv's
GitHub Atom feed for a new release, fetches the matching asset via the
GitHub API, and verifies it. Confirmed live against the real repo: uv
actually ships GitHub build-provenance attestations (sigstore bundle) on
every release, so it's a tier-2 package, not the tier-4 same-origin-sha256
guessed in the original spec draft. Verified via `gh attestation verify`
rather than reimplementing sigstore in Rust. State persists across runs so
a second run correctly reports "up to date."
Also folds the finding back into SPEC.md: updates the uv example to
tier 2, derives tier from verification method instead of storing both
(avoids a tier/method mismatch that would mean nothing), marks the
packages.d/ layout question resolved, and updates Architecture/Status to
say what's actually implemented vs. still sketch (build/publish/review
queue, same-origin-sha256 against a live repo, scheduling, non-GitHub
sources, minisign are all still open).
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A2FEut5tVMNjeVjqhgVZbr
2026-09-11 08:04:48 +00:00
|
|
|
}
|
Add shift-left quality gates: cognitive complexity, coverage, dependency fix
Adds two new gates to the existing format/lint/test/audit pipeline
(Makefile.toml `cargo make ci`, .forgejo/workflows/ci.yml):
- Cognitive complexity via clippy's nursery cognitive_complexity lint
(clippy.toml, threshold 15), scoped to --bins so test code's naturally
higher branch count doesn't get gated. Went with this over the closest
real cyclomatic-complexity tool (rust-code-analysis-cli) because that
crate hasn't shipped a release since Jan 2023.
- Test coverage via cargo-llvm-cov, chosen over cargo-tarpaulin for
friendlier behavior in containerized/dind CI (no ptrace). Report-only
for now (no --fail-under-lines) since a real threshold needs real usage
data first — see below. main.rs is excluded: it's orchestration glue
exercised by the real end-to-end `cargo run`, not unit tests.
Getting both gates running required writing pkgwatch's first tests
(previously zero). To make the GitHub-facing modules unit-testable
without hitting real github.com/api.github.com, added `GithubEndpoints`
(src/github.rs) so checker/fetcher/verifier take injectable base URLs,
and added mockito + tempfile as dev-dependencies. Result: 27 tests,
94% region / 96% line coverage excluding main.rs.
Also: cargo audit (now wired into `cargo make ci`) immediately caught a
real, currently-open advisory (RUSTSEC-2026-0285, published days ago) in
the transitive rustls dependency — bumped 0.23.44 -> 0.23.45 to clear it.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-17 07:16:14 +00:00
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
mod tests {
|
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn version_from_tag_strips_leading_v() {
|
|
|
|
|
assert_eq!(version_from_tag("v2.62.0"), "2.62.0");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn version_from_tag_leaves_bare_version_unchanged() {
|
|
|
|
|
assert_eq!(version_from_tag("0.12.15"), "0.12.15");
|
|
|
|
|
}
|
|
|
|
|
}
|