summaryrefslogtreecommitdiffstats
path: root/src/pkgver
diff options
context:
space:
mode:
authoraur-build <aur-build@localhost>2026-11-17 21:19:35 +0000
committeraur-build <aur-build@localhost>2026-11-17 21:19:35 +0000
commitf586d11f6a1711145ba4804787217a1bab58751d (patch)
tree3a8cd7d4a3d4097e315907c63e687bd243e8e686 /src/pkgver
parentfd3ecf91686b11feea078531baeddb60e6941116 (diff)
downloadaur-build-f586d11f6a1711145ba4804787217a1bab58751d.tar.gz
aur-build-f586d11f6a1711145ba4804787217a1bab58751d.zip
feat: AUR mirror watcher, recipe parsing, candidate creation
The detection path (§5.1, §5.1a, §5.3, §7.1): * git helpers, all subprocess git in one auditable place. Mirrors are cloned with --mirror and polled with git ls-remote, fetching only when the tip actually moved; --no-prune keeps history we may need forever. * .SRCINFO parsing (authoritative) with a PKGBUILD fallback, and source=() parsing that keeps VCS kind, #commit/#tag/#branch refs and the filename:: form. * recipe_hash over the whole snapshot tree, so a shipped patch is part of the recipe and cannot change silently. * source digest resolution: declared checksums are trusted-as-declared (makepkg enforces them, no bandwidth), local files are hashed from the mirror, and SKIP sources are downloaded and stream-hashed into the content-addressed source cache. Detection always re-fetches SKIP sources — answering from our own cache would defeat drift detection. * candidate creation with base = current_accepted_release, collapse in place while unviewed, supersede only once a human has looked, and a previously rejected identity is not re-raised. * non-publishable change handling (I11): unchanged version string means no review, but never silence — recipe drift and pin drift become notices, and a changed digest on a remote source with an unchanged version becomes a high-severity integrity_alert. Also vercmp + dep-string parsing with the ALPM test vectors, and the approval record with optimistic concurrency (§7.1a) that the CLI and web layers will both call. 16 detection tests against real file:// git fixtures, incl. I2 across three unattended detections and I11 for all three drift kinds. Part of P0 (DESIGN.md §17).
Diffstat (limited to 'src/pkgver')
-rw-r--r--src/pkgver/mod.rs59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/pkgver/mod.rs b/src/pkgver/mod.rs
index a940dc0..75be308 100644
--- a/src/pkgver/mod.rs
+++ b/src/pkgver/mod.rs
@@ -271,3 +271,62 @@ pub fn parse_deps(list: &[String]) -> Vec<Dep> {
pub fn dep_names(list: &[String]) -> Vec<String> {
parse_deps(list).into_iter().map(|d| d.name).collect()
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ fn ord(a: &str, b: &str) -> Ordering {
+ vercmp(a, b)
+ }
+
+ #[test]
+ fn alpm_version_ordering() {
+ // The classic ALPM test vectors.
+ assert_eq!(ord("1.0-1", "1.0-1"), Ordering::Equal);
+ assert_eq!(ord("1.0-1", "1.0-2"), Ordering::Less);
+ assert_eq!(ord("1.1-1", "1.0-1"), Ordering::Greater);
+ assert_eq!(ord("1.10-1", "1.9-1"), Ordering::Greater, "numeric chunks compare numerically");
+ assert_eq!(ord("1.0.a-1", "1.0.1-1"), Ordering::Greater, "alpha sorts after numeric");
+ assert_eq!(ord("1.5-1", "1.5.0-1"), Ordering::Less, "a trailing numeric chunk is newer");
+ assert_eq!(ord("1:1.0-1", "2.0-1"), Ordering::Greater, "epoch dominates");
+ assert_eq!(ord("1.0-1", "1.0_2-1"), Ordering::Less, "non-alnum separators are ignored");
+ assert_eq!(ord("1.0.0-1", "1.0-1"), Ordering::Greater, "a trailing numeric chunk is newer");
+ assert_eq!(ord("01.0-1", "1.0-1"), Ordering::Equal, "leading zeros are not significant");
+ }
+
+ #[test]
+ fn full_version_formatting() {
+ assert_eq!(full_version("0", "1.0", "1"), "1.0-1");
+ assert_eq!(full_version("", "1.0", "1"), "1.0-1");
+ assert_eq!(full_version("2", "1.0", "3"), "2:1.0-3");
+ assert_eq!(split_full_version("2:1.0-3").0, "2");
+ assert_eq!(split_full_version("1.0-3"), ("0".into(), "1.0".into(), "3".into()));
+ }
+
+ #[test]
+ fn pkgrel_reset_is_a_new_version() {
+ // §3: a pkgrel reset is a major signal.
+ assert_eq!(ord("1.0-7", "1.0-1"), Ordering::Greater);
+ assert!(is_downgrade("1.0-7", "1.0-1"));
+ }
+
+ #[test]
+ fn dep_strings_parse() {
+ assert_eq!(Dep::parse("foo").unwrap(), Dep { name: "foo".into(), op: DepOp::Any, version: None });
+ assert_eq!(Dep::parse("foo>=1.2").unwrap().op, DepOp::Ge);
+ assert_eq!(Dep::parse("foo<=1.2").unwrap().op, DepOp::Le);
+ assert_eq!(Dep::parse("foo=1.2-3").unwrap().version.as_deref(), Some("1.2-3"));
+ assert_eq!(Dep::parse("python-numpy").unwrap().name, "python-numpy");
+ assert_eq!(Dep::parse("cmake: for building").unwrap().name, "cmake");
+ assert!(Dep::parse("").is_none());
+ }
+
+ #[test]
+ fn version_constraints_are_checked() {
+ let d = Dep::parse("python>=3.11").unwrap();
+ assert!(d.satisfied_by("3.12-1"));
+ assert!(!d.satisfied_by("3.10-1"));
+ assert!(Dep::parse("foo").unwrap().satisfied_by("anything"));
+ }
+}