diff options
| author | aur-build <aur-build@localhost> | 2026-11-18 17:25:41 +0000 |
|---|---|---|
| committer | aur-build <aur-build@localhost> | 2026-11-18 17:25:41 +0000 |
| commit | f3e4c1496d2ddcdae535132427fdb499181f1695 (patch) | |
| tree | ca1c9cb5e66caa7b9542aebb38811725b98c6f46 /src/urlutil.rs | |
| parent | 8bb76cb266a2fef5d5fe43c0f9643101f59112aa (diff) | |
| download | aur-build-f3e4c1496d2ddcdae535132427fdb499181f1695.tar.gz aur-build-f3e4c1496d2ddcdae535132427fdb499181f1695.zip | |
review: one host rule, one body rule, one audit constructor
m-2. `hosts` existed twice, verbatim, in `review::diff` and `review::risk`. The
duplication that matters is the other one: "did the executable part of the
recipe change" also existed twice, with *different* semantics. The risk scorer
compared everything from the first function definition onward; the diff panel
compared only the lines that name a function, so a `build()` rewritten to
`curl … | sh` under the same function names told the risk scorer "code changed,
high" and told the reviewer nothing at all — the one reader who could have
caught it. Both questions now have one answer: `urlutil::hosts` (which also
strips the `git@` from ssh URLs, so a scheme change stops crying "new source
host" wolf) and `recipe::bodies_changed`, in the module that owns the recipe.
m-4. The three review decisions each hand-built an `AuditEntry` literal, and
their `detail` shapes drifted: approve recorded the identity hash, reject
recorded only the note, withdraw only the reason — so for two of the three the
log cannot answer which candidate bytes the decision was about. `AuditEntry` is
built by `::human` / `::system` now, and reject records the identity hash it
rejected.
m-3, the four-times-copied 21-column candidate `SELECT`, was already gone: the
`CANDIDATE_COLS` constant came with moving the candidate SQL into `db/` in an
earlier commit.
Tests: the body rule is pinned at the unit level with the exact drift case
(same function names, different body), `tests/production_surface.rs` fails if
either module grows a private copy again or if an audit row is hand-built, and
the reject test reads its own audit row back and requires the identity in it.
Diffstat (limited to 'src/urlutil.rs')
| -rw-r--r-- | src/urlutil.rs | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/urlutil.rs b/src/urlutil.rs new file mode 100644 index 0000000..75b52b9 --- /dev/null +++ b/src/urlutil.rs @@ -0,0 +1,73 @@ +//! Source-URL questions that more than one module asks (§6 m-2). +//! +//! `review::diff` and `review::risk` each carried a verbatim copy of `hosts`, +//! which is the kind of duplication that stays harmless until one copy is fixed +//! and the other is not: the diff panel would tell a reviewer a host appeared +//! while the risk scorer stayed quiet about the same host. + +use std::collections::BTreeSet; + +/// The host of one `source=()` entry, or `None` when it names no host — a local +/// file, a relative path, or a `file://` URL. +/// +/// Handles the two prefixes a PKGBUILD puts in front of a URL: a `custom::` +/// filename prefix, and the `git+`/`svn+`/`npm+` VCS scheme prefix. +pub fn host_of(source: &str) -> Option<String> { + let s = source.rsplit("::").next().unwrap_or(source); + let s = s.rsplit('+').next().unwrap_or(s); + let rest = s.split("://").nth(1)?; + let host = rest.split('/').next()?; + // `git+ssh://git@github.com/...` names the same place as + // `https://github.com/...`; leaving the user in would make a scheme change + // look like a new source host and cry wolf at a reviewer. + let host = host.rsplit('@').next().unwrap_or(host); + (!host.is_empty()).then(|| host.to_string()) +} + +/// The distinct hosts a `source=()` array names, sorted. A host appearing here +/// that was not in the accepted release's list is a new place the build fetches +/// code from (§5.3, §6). +pub fn hosts(sources: &[String]) -> BTreeSet<String> { + sources.iter().map(|s| s.as_str()).filter_map(host_of).collect() +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn a_plain_url_is_its_host() { + assert_eq!(host_of("https://example.invalid/a.tar.gz").as_deref(), Some("example.invalid")); + } + + #[test] + fn scheme_and_filename_prefixes_are_stripped() { + assert_eq!(host_of("git+https://github.com/a/b.git").as_deref(), Some("github.com")); + assert_eq!( + host_of("myname::https://cdn.example.org/x.tar").as_deref(), + Some("cdn.example.org") + ); + assert_eq!( + host_of("myname::git+ssh://git@gitlab.example.org/a/b.git").as_deref(), + Some("gitlab.example.org"), + "the ssh user is not part of the host" + ); + } + + #[test] + fn local_files_have_no_host() { + assert_eq!(host_of("fix.patch"), None); + assert_eq!(host_of("./relative/thing.conf"), None); + } + + #[test] + fn hosts_are_deduplicated_and_sorted() { + let h = hosts(&[ + "https://b.example/x.tar".to_string(), + "https://a.example/y.tar".to_string(), + "git+https://b.example/z.git".to_string(), + "local.patch".to_string(), + ]); + assert_eq!(h.into_iter().collect::<Vec<_>>(), vec!["a.example", "b.example"]); + } +} |
